_getDataObj()->setPrimaryKey($this->_getDataObj()->getCartId()); parent::__construct($options); } public function exec() { if ($this->getConfig('type') == self::TYPE_PREVIEW) { $this->setPreviewMode(); $this->_getLog()->addIgnoredControllers(['App_ECommerce_Cart_View' => ['list']]); } else { if (!($this->_doc instanceof App_Doc_Admin)) { $this->_getDataObj()->removeServiceProducts(); } } return parent::exec(); } protected function _addListItem() { $this->_initListRedirection(); $item = $this->_getListItem(); if (false === $this->getPreviewMode()) { $this->_doc->addScript('js/app/ECommerce/cart.js'); $this->_doc->addScript('js/jquery-autoNumeric.js'); $params = [ 'qtyList' => $this->_getQtyList(), ]; $this->_doc->addInitFunction('App_Cart_Cart.init', [$params]); $this->_doc->addGtmValues(Qs_Gtm::adGetShoppingCart($item['list'])); if ($this->_doc->isGtmEnabled()) { $cartItems = Qs_Gtm::eeGetProducts($this->_getDataObj()->getList(true), Qs_Gtm::DATASET_CART, [], true); $options = ['cartItems' => $cartItems]; $this->_doc->addInitObject('lib.Gtm', [$options]); } } $this->_addLinksItem(); $this->_addItem($item); return $this; } protected function _getListOptions() { $options = parent::_getListOptions(); $options['previewMode'] = $this->getPreviewMode(); return $options; } protected function _getQtyList() { $items = (array) $this->_getListItem(); $qtyList = []; foreach ($items['list'] as $item) { $qtyList[$item['id']] = $item['quantity']; } return $qtyList; } /** * Get list item. Add cart summary info. * * @internal param null $list * @return array|null */ protected function _getListItem() { $list = parent::_getListItem(); $list['shoppingCartSummary'] = $this->_getDataObj()->getTotal(); $list['previewMode'] = $this->getPreviewMode(); $this->_getDataObj()->validateCartItems(); $list['cartErrors'] = $this->_getDataObj()->getErrors(); return $list; } /** * Update cart item * Display 404 page when request is not ajax */ protected function _doUpdateItem() { return $this->_doc->display404(); } /** * Ajax. Update cart item */ protected function _doUpdateItemAjax() { $result = false; $itemId = Qs_Request::getRequestValue('itemId'); $qty = Qs_Request::getRequestValue('qty'); if (!empty($itemId)) { if (!$qty) { $qty = 1; } $result = $this->_getDataObj()->updateItemQty($itemId, $qty); } $response = []; $response['success'] = $result; if ($result) { $row = $this->_getDataObj()->getRowData($itemId); $currency = static::CURRENCY_SYMBOL; $response['rowPrice'] = $currency . number_format($row['price'], 2); $response['rowTotal'] = $currency . number_format($row['rowTotal'], 2); if (!empty($row['promoDescription'])) { $response['rowTotal'] .= ' (' . htmlspecialchars($row['promoDescription']) . ')'; } $response['subTotal'] = $currency . number_format(Zend_Locale_Math::round($this->_getDataObj()->getTotal(), 2), 2); $response['quantity'] = $this->_getDataObj()->getItemsCount(); $this->_log(); } $this->_displayJson($response); } /** * Clear default links * * @return array */ protected function _getDefaultLinks() { return []; } /** * Get cart list HTML for JSONP requests */ protected function _doGetListHtml() { $this->_doGetListHtmlAjax(); } /** * Ajax. Get cart list HTML */ protected function _doGetListHtmlAjax() { $item = $this->_getListItem(); Qs_Smarty_File::setTemplate('ECommerce/Cart/small-list.tpl'); $data = [ 'item' => [ 'list' => $item['list'], 'subTotal' => $item['shoppingCartSummary'], 'config' => $item['config'], ], ]; $list = Qs_Smarty_File::render($data); $response = ['success' => true, 'html' => $list]; $callback = Qs_Array::get($_GET, 'callback'); $this->_displayJson($response, $callback); } /** * Set transaction id * * @param $id * @return bool|Exception */ public function setTransactionId($id) { if (($e = $this->_getDataObj()->updateTransactionId($id)) instanceof Exception) { return $e; } return true; } /** * Clean transactionId field * * @param int $id * @return bool|Exception */ public function cancelTransaction($id) { if (($e = $this->_getDataObj()->cancelTransaction($id)) instanceof Exception) { return $e; } return true; } public function getItemsCount() { return $this->_getDataObj()->getItemsCount(); } /** * Get GTM Products for JSONP requests */ protected function _doGetGtmProducts() { $this->_doGetGtmProductsAjax(); } /** * Ajax. Get GTM Products */ protected function _doGetGtmProductsAjax() { $products = App_ECommerce_Cart_Obj::getInstance()->getList(); $products = Qs_Gtm::eeGetProducts($products, Qs_Gtm::DATASET_CHECKOUT); $response = [ 'success' => true, 'products' => $products, ]; $callback = Qs_Array::get($_GET, 'callback'); $this->_displayJson($response, $callback); } }