/** * @test */ public function addFirstNetCartProductToGrossCartChangeNetOfCart() { $productPrice = 10.0; $netProduct = new \Extcode\Cart\Domain\Model\Cart\Product('simple', 1, 0, 0, 1, 'First Net Product', $productPrice, $this->normalTaxClass, 1, true); $this->grossCart->addProduct($netProduct); $this->assertSame($productPrice, $this->grossCart->getNet()); }
/** * 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'); } }
/** * Save Order * * @param array $pluginSettings TypoScript Plugin Settings * @param \Extcode\Cart\Domain\Model\Cart\Cart $cart * @param \Extcode\Cart\Domain\Model\Order\Item $orderItem * @param \Extcode\Cart\Domain\Model\Order\Address $billingAddress * @param \Extcode\Cart\Domain\Model\Order\Address $shippingAddress * * @return void */ public function saveOrderItem(array $pluginSettings, \Extcode\Cart\Domain\Model\Cart\Cart $cart, \Extcode\Cart\Domain\Model\Order\Item $orderItem, \Extcode\Cart\Domain\Model\Order\Address $billingAddress, \Extcode\Cart\Domain\Model\Order\Address $shippingAddress = null) { $this->storagePid = $pluginSettings['settings']['order']['pid']; $this->cart = $cart; $this->orderItem = $orderItem; if (!$this->objectManager) { $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); } $orderItem->setPid($this->storagePid); $orderItem->setFeUser((int) $GLOBALS['TSFE']->fe_user->user['uid']); $orderItem->setGross($this->cart->getGross()); $orderItem->setNet($this->cart->getNet()); $orderItem->setTotalGross($this->cart->getTotalGross()); $orderItem->setTotalNet($this->cart->getTotalNet()); $billingAddress->setPid($this->storagePid); $orderItem->setBillingAddress($billingAddress); if ($shippingAddress && !$shippingAddress->_isDirty()) { $shippingAddress->setPid($this->storagePid); $orderItem->setShippingAddress($shippingAddress); } if (!$orderItem->_isDirty()) { $this->orderItemRepository->add($orderItem); $this->addTaxClasses(); $this->addTaxes('TotalTax'); $this->addTaxes('Tax'); if ($this->cart->getProducts()) { $this->addProducts(); } if ($this->cart->getCoupons()) { $this->addCoupons(); } if ($this->cart->getPayment()) { $this->addPayment(); } if ($this->cart->getShipping()) { $this->addShipping(); } } $orderNumber = $this->getOrderNumber($pluginSettings); $orderItem->setOrderNumber($orderNumber); $orderItem->setOrderDate(new \DateTime()); $this->persistenceManager->persistAll(); $this->cart->setOrderId($orderItem->getUid()); $this->cart->setOrderNumber($orderItem->getOrderNumber()); }