/** * @return array * @throws BadRequestHttpException * @throws NotFoundHttpException */ public function actionAdd() { Yii::$app->response->format = Response::FORMAT_JSON; $products = Yii::$app->request->post('products', []); if (false === is_array($products) || true === empty($products)) { throw new BadRequestHttpException(); } $order = $this->loadOrder(true); if (null === $order->stage || true === $order->getImmutability(Order::IMMUTABLE_USER)) { throw new BadRequestHttpException(); } $result = ['products' => [], 'errors' => [], 'additional' => []]; $result = $this->addProductsToOrder($order, $products, $result); $order = $this->loadOrder(); $order->calculate(true); $userCurrency = CurrencyHelper::getUserCurrency(); $result['success'] = count($products) > 0 && count($result['products']) > 0; $result['itemsCount'] = $order->items_count; $result['totalPrice'] = $userCurrency->format(CurrencyHelper::convertToUserCurrency($order->total_price, CurrencyHelper::getMainCurrency())); $event = new CartActionEvent($order, $result['products']); Event::trigger($this, self::EVENT_ACTION_ADD, $event); $result['additional'] = $event->getEventData(); /** * Backward compatibility */ $result['itemModalPreview'] = isset($result['additional']['bcItemModalPreview']) ? $result['additional']['bcItemModalPreview'] : ''; $result['products'] = $this->productsModelsToArray($result['products']); return $result; }