_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 _doUpdateNumbersAjax() { $data = Qs_Request::getPost(); $productView = new App_ECommerce_Product_View(); $form = $productView->getAddToCartForm('full', $data['productId']); if ($form->validate()) { $obj = $this->_getDataObj()->setPrimaryKey($data['id']); $obj->updateNumbers($data['id'], $data); $this->_displayJson(array('success' => true)); } else { $productView = new App_ECommerce_Product_View(); $this->_displayJson(array('form' => $productView->renderCartForm($form))); } } protected function _doGetUpdateNumbersFormAjax() { $productView = new App_ECommerce_Product_View(); die($productView->renderCartForm()); } 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['shoppingCartSummaryReal'] = $this->_getDataObj()->getTotal(true); $list['shoppingCartSummaryDiff'] = $list['shoppingCartSummary'] - $list['shoppingCartSummaryReal']; $list['orderMinimumAmount'] = (int) App_Settings_Obj::get('orderMinimumAmount'); $list['previewMode'] = $this->getPreviewMode(); return $list; } /** * Update cart item * Display 404 page when request is not ajax */ protected function _doUpdateItem() { return $this->_doc->display404(); } protected function _doList() { /** @var Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/lib/form.js'); $doc->addScript('js/jquery.defaultHint.js'); return parent::_doList(); } /** * 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); $response['rowTotal'] = $currency . number_format($row['rowTotal'], 2); if (!empty($row['promoDescription'])) { $response['rowTotal'] .= ' (' . htmlspecialchars($row['promoDescription']) . ')'; } $total = $this->_getDataObj()->getTotal(); $realTotal = $this->_getDataObj()->getTotal(true); $response['subTotal'] = $currency . number_format(Zend_Locale_Math::round($total, 2), 2); $response['subTotalReal'] = number_format(Zend_Locale_Math::round($realTotal, 2), 2); $response['subTotalDiff'] = number_format(Zend_Locale_Math::round($total - $realTotal, 2), 2); $response['quantity'] = $this->_getDataObj()->getItemsCount(); $this->_log(); } $this->_displayJson($response); } /** * Clear default links * * @return array */ protected function _getDefaultLinks() { return array(); } /** * 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 = array( 'item' => array( 'list' => $item['list'], 'subTotal' => $item['shoppingCartSummary'], 'config' => $item['config'], ) ); $list = Qs_Smarty_File::render($data); $response = array('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(); } }