Skip to content

Commit

Permalink
ref #88832 Update cart date format (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Mar 29, 2023
1 parent 5a899f6 commit 3110960
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.5.1
* Обновление формата даты в корзинах

## v3.5.0
* Реализована поддержка новой логики работы с брошенными корзинами.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.0
3.5.1
14 changes: 10 additions & 4 deletions retailcrm/lib/RetailcrmCartUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class RetailcrmCartUploader
*/
static $now;

/**
* @var string
*/
static $crmCartDateFormat;

/**
* Cast provided sync delay to integer
*
Expand All @@ -101,6 +106,7 @@ public static function init()
static::$allowedUpdateInterval = 86400;
static::$now = new DateTimeImmutable();
static::$context = Context::getContext();
static::$crmCartDateFormat = 'Y-m-d H:i:sP';
}

/**
Expand Down Expand Up @@ -148,7 +154,7 @@ public static function run()
if ($isExistExternalId) {
static::$api->cartClear(
[
'clearedAt' => date('Y-m-d H:i:s'),
'clearedAt' => date(static::$crmCartDateFormat),
'customer' => ['externalId' => $cart->id_customer],
],
static::$site
Expand Down Expand Up @@ -256,15 +262,15 @@ private static function buildCrmCart($cart, string $cartExternalId, bool $isExis
$crmCart = [
'customer' => ['externalId' => $cart->id_customer],
'clearAt' => null,
'createdAt' => $cart->date_add,
'createdAt' => DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cart->date_add)->format(static::$crmCartDateFormat),
];

if (!$isExistExternalId) {
$crmCart['externalId'] = $cartExternalId . uniqid('_', true);
}

if (!empty($cart->date_upd)) {
$crmCart['updatedAt'] = $cart->date_upd;
$crmCart['updatedAt'] = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cart->date_upd)->format(static::$crmCartDateFormat);
}

$products = $cart->getProducts();
Expand All @@ -280,7 +286,7 @@ private static function buildCrmCart($cart, string $cartExternalId, bool $isExis
: $product['id_product'],
],
'quantity' => $product['cart_quantity'],
'createdAt' => $product['date_add'],
'createdAt' => DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $product['date_add'])->format(static::$crmCartDateFormat),
'price' => !empty($product['rate'])
? round($product['price'], 2) + (round($product['price'], 2) * $product['rate'] / 100)
: round($product['price'], 2),
Expand Down
2 changes: 1 addition & 1 deletion retailcrm/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

class RetailCRM extends Module
{
const VERSION = '3.5.0';
const VERSION = '3.5.1';

const API_URL = 'RETAILCRM_ADDRESS';
const API_KEY = 'RETAILCRM_API_TOKEN';
Expand Down

0 comments on commit 3110960

Please sign in to comment.