setSite($site); } else { RCrmActions::eventLog( 'RetailCrmCart::handlerCart', 'RetailcrmConfigProvider::getSitesList', 'Error set site' ); return null; } } else { $site = RetailcrmConfigProvider::getSitesAvailable(); } $crmBasket = RCrmActions::apiMethod($api, 'cartGet', __METHOD__, $arBasket['USER_ID'], $site); if (empty($arBasket['BASKET'])) { if (!empty($crmBasket['cart']['items'])) { return RCrmActions::apiMethod( $api, 'cartClear', __METHOD__, [ 'clearedAt' => date(self::$dateFormat), 'customer' => [ 'externalId' => $arBasket['USER_ID'] ] ], $site ); } return null; } $date = 'createdAt'; $items = []; foreach ($arBasket['BASKET'] as $itemBitrix) { $item['quantity'] = $itemBitrix['QUANTITY']; $item['price'] = $itemBitrix['PRICE']; $item['createdAt'] = $itemBitrix['DATE_INSERT']->format(self::$dateFormat); $item['updateAt'] = $itemBitrix['DATE_UPDATE']->format(self::$dateFormat); $item['offer']['externalId'] = $itemBitrix['PRODUCT_ID']; $items[] = $item; } if (!empty($crmBasket['cart']['items'])) { $date = 'updatedAt'; } return RCrmActions::apiMethod( $api, 'cartSet', __METHOD__, [ 'customer' => [ 'externalId' => $arBasket['USER_ID'], 'site' => $site, ], $date => date(self::$dateFormat), 'droppedAt' => date(self::$dateFormat), 'items' => $items, ], $site ); } /** * @throws \Bitrix\Main\SystemException * * @return array|null */ public static function getBasketArray($event): ?array { if ($event instanceof Basket) { $obBasket = $event; } elseif ($event instanceof Event) { $obBasket = $event->getParameter('ENTITY'); } else { RCrmActions::eventLog('RetailCrmEvent::onChangeBasket', 'getBasketArray', 'event error'); return null; } $arBasket = [ 'LID' => $obBasket->getSiteId(), ]; $items = $obBasket->getBasket(); foreach ($items as $item) { $arBasket['BASKET'][] = $item->getFields(); } return $arBasket; } }