public function create() : PriceInterface { $price = new Price(); $price->setGrossAmount(0); $price->setNetAmount(0); $price->setTaxAmount(0); $price->setTaxRate(0); $price->setCurrency(''); return $price; }
protected function getShippingCostsCollection(ShippingMethodInterface $shippingMethod) { $collection = new ArrayCollection(); $cost = new ShippingMethodCost(); $cost->setRangeFrom(0); $cost->setRangeTo(100000); $price = new Price(); $price->setCurrency('EUR'); $price->setNetAmount(10); $price->setTaxAmount(2.3); $price->setTaxRate(23); $price->setGrossAmount(12.3); $cost->setCost($price); $cost->setShippingMethod($shippingMethod); $collection->add($cost); return $collection; }
/** * @param CartProductInterface $cartProduct * @param OrderInterface $order * * @return \WellCommerce\Bundle\OrderBundle\Entity\OrderProductInterface */ public function prepareOrderProduct(CartProductInterface $cartProduct, OrderInterface $order) { $orderProduct = $this->orderProductFactory->create(); $product = $cartProduct->getProduct(); $attribute = $cartProduct->getAttribute(); $sellPrice = $cartProduct->getSellPrice(); $baseCurrency = $sellPrice->getCurrency(); $targetCurrency = $order->getCurrency(); $grossAmount = $this->getCurrencyHelper()->convert($sellPrice->getFinalGrossAmount(), $baseCurrency, $targetCurrency); $netAmount = $this->getCurrencyHelper()->convert($sellPrice->getFinalNetAmount(), $baseCurrency, $targetCurrency); $taxAmount = $this->getCurrencyHelper()->convert($sellPrice->getFinalTaxAmount(), $baseCurrency, $targetCurrency); $sellPrice = new Price(); $sellPrice->setGrossAmount($grossAmount); $sellPrice->setNetAmount($netAmount); $sellPrice->setTaxAmount($taxAmount); $sellPrice->setTaxRate($sellPrice->getTaxRate()); $sellPrice->setCurrency($targetCurrency); $orderProduct->setSellPrice($sellPrice); $orderProduct->setBuyPrice($product->getBuyPrice()); $orderProduct->setQuantity($cartProduct->getQuantity()); $orderProduct->setWeight($cartProduct->getWeight()); $orderProduct->setProductAttribute($attribute); $orderProduct->setProduct($product); return $orderProduct; }
/** * Creates an instance of order product * * @param array $productValues * @param OrderInterface $order * * @return \WellCommerce\Bundle\OrderBundle\Entity\OrderProductInterface */ protected function createOrderProduct(array $productValues, OrderInterface $order) { $productId = (int) $productValues['product_id']; $product = $this->productRepository->find($productId); if (!$product instanceof ProductInterface) { throw new \InvalidArgumentException(sprintf('Cannot add product to order. ID "%s" does not exists.', $productId)); } $orderProduct = $this->factory->create(); $orderProduct->setBuyPrice($product->getBuyPrice()); $orderProduct->setOrder($order); $orderProduct->setProduct($product); $orderProduct->setProductAttribute(null); $orderProduct->setQuantity($productValues['quantity']); $orderProduct->setWeight($productValues['weight']); $sellPrice = new Price(); $grossAmount = $productValues['gross_amount']; $taxRate = $product->getSellPriceTax()->getValue(); $netAmount = TaxHelper::calculateNetPrice($grossAmount, $taxRate); $sellPrice->setTaxRate($taxRate); $sellPrice->setTaxAmount($grossAmount - $netAmount); $sellPrice->setNetAmount($netAmount); $sellPrice->setGrossAmount($grossAmount); $sellPrice->setCurrency($order->getCurrency()); $orderProduct->setSellPrice($sellPrice); return $orderProduct; }