示例#1
0
 /**
  * Action Add Product
  *
  * @return string
  */
 public function addProductAction()
 {
     $this->cart = $this->cartUtility->getCartFromSession($this->settings['cart'], $this->pluginSettings);
     $products = $this->cartUtility->getProductsFromRequest($this->pluginSettings, $this->request, $this->cart->getTaxClasses());
     $quantity = 0;
     foreach ($products as $product) {
         $quantity += $product->getQuantity();
         $this->cart->addProduct($product);
     }
     $this->updateService();
     $this->sessionHandler->writeToSession($this->cart, $this->settings['cart']['pid']);
     $productsChanged = [];
     foreach ($products as $product) {
         $productChanged = $this->cart->getProduct($product->getId());
         $productsChanged[$product->getId()] = $productChanged->toArray();
     }
     if (isset($_GET['type'])) {
         // ToDo: have different response status
         $response = ['status' => '200', 'added' => $quantity, 'count' => $this->cart->getCount(), 'net' => $this->cart->getNet(), 'gross' => $this->cart->getGross(), 'productsChanged' => $productsChanged];
         return json_encode($response);
     } else {
         $this->redirect('showCart');
     }
 }
示例#2
0
文件: CartTest.php 项目: extcode/cart
 protected function addFirstProductToCarts()
 {
     $product = new \Extcode\Cart\Domain\Model\Cart\Product('simple', 1, 0, 0, 1, 'First Product', 10.0, $this->normalTaxClass, 1, false);
     $this->grossCart->addProduct($product);
     $this->netCart->addProduct($product);
 }