public function viewBasketAction() { if ($this->getParam('do-return')) { return $this->_redirect('cart'); } $d = (array) $this->getParam('d', array()); $qty = (array) $this->getParam('qty', array()); foreach ($qty as $item_id => $newQty) { if ($item = $this->cart->getInvoice()->findItem('product', intval($item_id))) { if ($item->is_countable) { $item->qty = (int) $newQty; } } } foreach ($d as $item_id => $val) { if ($item = $this->cart->getInvoice()->findItem('product', intval($item_id))) { $this->cart->getInvoice()->deleteItem($item); } } if (($code = $this->getFiltered('coupon')) !== null) { $this->view->coupon_error = $this->cart->setCouponCode($code); } $this->cart->calculate(); if (!$this->view->coupon_error && $this->getParam('do-checkout')) { return $this->checkoutAction(); } $this->view->display('cart/basket.phtml'); }
public function addFromRequest() { //data = [{id:id,qty:qty,plan:plan,type:type},{}...] $data = json_decode($this->getParam('data')); try { if (!$data) { throw new Am_Exception_InternalError(___('Shopping Cart Module. No data input')); } foreach ($data as $item) { $item_id = intval($item->id); if (!$item_id) { throw new Am_Exception_InternalError(___('Shopping Cart Module. No product id input')); } $qty = !empty($item->qty) && ($q = intval($item->qty)) ? $q : 1; $p = $this->getDi()->productTable->load($item_id); if (!empty($item->plan) && ($bp = intval($item->plan))) { $p->setBillingPlan($bp); } $this->cart->addItem($p, $qty); } if ($this->getDi()->auth->getUserId()) { $this->cart->setUser($this->getDi()->user); } $this->cart->calculate(); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); $this->ajaxResponse(array('status' => 'error', 'message' => $e->getPublicError())); return; } $this->ajaxResponse(array('status' => 'ok')); }