/** * @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; }
/** * {@inheritdoc} */ public function initResource() { $resource = $this->factory->create(); $this->eventDispatcher->dispatchOnPostInitResource($resource); return $resource; }