_getDataObj()->setPrimaryKey($this->_getDataObj()->getCartId()); parent::__construct($options); } public function exec() { if ($this->getConfig('type') == self::TYPE_PREVIEW) { $this->setPreviewMode(); $this->_getLog()->addIgnoredControllers(array('App_ECommerce_Cart_View' => array('list'))); } return parent::exec(); } /** * Add list item to page * * @param null $list * @return Qs_ViewController */ protected function _addListItem($list = null) { if (false === $this->getPreviewMode()) { $this->_doc->addScript('js/app/ECommerce/cart.js'); $this->_doc->addScript('js/jquery-autoNumeric.js'); $params = array( 'qtyList' => $this->_getQtyList() ); $this->_doc->addInitFunction('App_Cart_Cart.init', array($params)); } return parent::_addListItem($list); } protected function _getListOptions() { $options = parent::_getListOptions(); $options['previewMode'] = $this->getPreviewMode(); return $options; } protected function _getQtyList() { $items = (array) $this->_getListItem(); $qtyList = array(); foreach ($items['list'] as $item) { $qtyList[$item['id']] = $item['quantity']; } return $qtyList; } /** * Get list item. Add cart summary info. * * @param null $list * @return array|null */ protected function _getListItem($list = null) { $list = parent::_getListItem($list); $list['shoppingCartSummary'] = $this->_getDataObj()->getTotal(); $list['previewMode'] = $this->getPreviewMode(); 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 = array(); $response['success'] = $result; if ($result) { $row = $this->_getDataObj()->getRowData($itemId); $currency = static::CURRENCY_SYMBOL; $response['rowPrice'] = $currency . number_format($row['price'], 2); if (!empty($row['promoDescription'])) { $response['rowPrice'] .= ' (' . htmlspecialchars($row['promoDescription']) . ')'; } $response['subTotal'] = $currency . number_format($this->_getDataObj()->getTotal(), 2); $response['quantity'] = $this->_getDataObj()->getItemsCount(); } $this->_displayJson($response); } /** * Clear default links * * @return array */ protected function _getDefaultLinks() { return array(); } /** * Get cart list HTML * Display 404 page when request is not ajax */ protected function _doGetListHtml() { return $this->_doc->display404(); } /** * Ajax. Get cart list HTML */ protected function _doGetListHtmlAjax() { $item = $this->_getListItem(); Qs_Smarty_File::setTemplate('ECommerce/Cart/small-list.tpl'); $data = array( 'item' => array( 'list' => $item['list'], 'subTotal' => $item['shoppingCartSummary'], 'config' => $item['config'], ) ); die(Qs_Smarty_File::render($data)); } /** * 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(); } }