Exemple #1
0
 function findParse($objectId, $type)
 {
     if (empty($this->ids['objectIds'][$type])) {
         $this->ids['objectIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'object_id']);
         ksort($this->ids['objectIds'][$type]);
     }
     if (!empty($this->ids['objectIds'][$type][$objectId])) {
         return $this->ids['objectIds'][$type][$objectId];
     }
 }
Exemple #2
0
 public function updateCartItems($cart, $items)
 {
     $itemIds = [];
     $cItems = [];
     foreach ($items as $item) {
         $cItem = [];
         $id = \Migrations\Id::get([['parse_id', $item->Ид], ['type', 'Ecommerce\\Item']]);
         if (!$id) {
             continue;
         }
         $itemIds[] = $id->object_id;
         $siteItem = \Ecommerce\Item::get($id->object_id);
         if (!$siteItem) {
             $cItem['item_id'] = 0;
             $cItem['item_offer_price_id'] = 0;
             $cItem['count'] = (string) $item->Количество;
             $cItem['name'] = (string) $item->Наименование;
             $cItems[] = $cItem;
             continue;
         }
         $pricesByPrice = $siteItem->prices(['key' => 'price']);
         $prices = $siteItem->prices;
         $default = key($prices);
         $itemPrice = number_format((string) $item->ЦенаЗаЕдиницу, 2, '.', '');
         if (!empty($pricesByPrice[$itemPrice])) {
             $price = $pricesByPrice[$itemPrice];
         } else {
             $rolePrice = 0;
             foreach ($siteItem->prices as $priceId => $itemPrice) {
                 if (!$itemPrice->type->cipt_roles) {
                     $default = $priceId;
                     continue;
                 }
                 if ($itemPrice->type->cipt_roles && $cart->user->user_role_id && false !== strpos($itemPrice->type->cipt_roles, "|{$cart->user->user_role_id}|")) {
                     $rolePrice = $priceId;
                 }
             }
             $price = $siteItem->prices[$rolePrice ? $rolePrice : $default];
         }
         $cItem['item_id'] = $id->object_id;
         $cItem['item_offer_price_id'] = $price->id;
         $cItem['count'] = (string) $item->Количество;
         $cItem['final_price'] = (string) $item->ЦенаЗаЕдиницу;
         $cItem['name'] = (string) $item->Наименование;
         $cItems[] = $cItem;
     }
     foreach ($cart->cartItems as $cartItem) {
         $isset = false;
         foreach ($cItems as $key => $cItem) {
             if (!($cItem['item_id'] == $cartItem->item_id)) {
                 continue;
             }
             $isset = true;
             if ($cItem['final_price'] != $cartItem->final_price || $cItem['item_offer_price_id'] != $cartItem->item_offer_price_id || $cItem['count'] != $cartItem->count) {
                 $cartItem->item_offer_price_id = $cItem['item_offer_price_id'];
                 $cartItem->count = $cItem['count'];
                 $cartItem->final_price = $cItem['final_price'];
                 $cartItem->save();
             }
             unset($cItems[$key]);
         }
         if (!$isset && !empty($cItem['name']) && !in_array($cItem['name'], ['Доставка', 'Клубная карта', 'Пакет майка'])) {
             $cartItem->delete();
         }
     }
     if ($cItems) {
         foreach ($cItems as $cItem) {
             $cart->addItem($cItem['item_offer_price_id'], $cItem['count'], $cItem['final_price']);
         }
     }
     $cart->calc();
 }