/** * @param CartActionEvent $event */ public static function renderCartPreview(CartActionEvent $event) { $result = $event->getEventData(); /** @var View $view */ $view = \Yii::$app->getView(); $order = $event->getOrder(); $order->calculate(false, false); $result['itemModalPreview'] = $view->renderFile(ShopModule::getInstance()->getViewPath() . '/cart/partial/item-modal-preview.php', ['order' => $order]); /** Backward compatibility */ if (true === in_array($event->name, [CartController::EVENT_ACTION_ADD, CartController::EVENT_ACTION_REMOVE])) { $result['bcItemModalPreview'] = self::bcRenderCartPreview($order, $view, $event->getProducts()); } /** Backward compatibility [END] */ $event->setEventData($result); }
/** * @param CartActionEvent $event */ public static function handleClearCart(CartActionEvent $event) { $result = $event->getEventData(); /** @var Currency $currency */ $currency = static::$currency; $ya = []; $ya['currency'] = $currency->iso_code; $ya['products'] = array_reduce($event->getProducts(), function ($res, $item) use($currency) { $quantity = $item['quantity']; /** @var Product $item */ $item = $item['model']; $res[] = ['id' => $item->id, 'name' => $item->name, 'category' => self::getCategories($item), 'price' => CurrencyHelper::convertCurrencies($item->price, $item->currency, $currency), 'quantity' => $quantity]; return $res; }, []); $result['ecYandex'] = $ya; $event->setEventData($result); }