Beispiel #1
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();
 }
Beispiel #2
0
 public function viewAction($id = '')
 {
     $item = \Ecommerce\Item::get((int) $id);
     if (!$item) {
         Tools::redirect('/ecommerce/', 'Такой товар не найден');
     }
     $active = $item->category_id;
     $catalog = $item->category;
     $bread = [];
     $bread[] = ['text' => 'Каталог', 'href' => '/ecommerce'];
     $catalogIds = array_values(array_filter(explode('/', $item->tree_path)));
     foreach ($catalogIds as $id) {
         $cat = Ecommerce\Category::get($id);
         if ($cat) {
             $bread[] = ['text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id];
         }
     }
     $bread[] = ['text' => $item->name()];
     $this->view->setTitle($item->name());
     $options = ['data' => compact('item', 'active', 'catalog', 'bread')];
     if (isset($_GET['quickview'])) {
         $options['page'] = 'blank';
     }
     $this->view->addMetaTag(['property' => 'og:title', 'content' => $item->name]);
     $this->view->addMetaTag(['property' => 'og:description', 'content' => $item->description]);
     if ($item->image) {
         $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]);
     }
     $this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . INJI_DOMAIN_NAME . '/view/' . $item->id]);
     $options['content'] = $item->view ? $item->view : 'view';
     $this->view->page($options);
 }