public function addFromRequest()
 {
     $p = $this->getDi()->productTable->load($this->getInt('item_id'));
     $plan_id = $this->getInt('billing_plan_id');
     if ($plan_id) {
         $p->setBillingPlan($plan_id);
     }
     $this->cart->addItem($p, $this->getInt('qty', 1));
     $this->cart->calculate();
 }
示例#2
0
 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'));
 }