/** * 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'); } }