public function visitOrder(OrderInterface $order) { $productTotal = $order->getProductTotal(); $modifiers = $order->getModifiers(); $targetCurrency = $order->getCurrency(); /** @var OrderSummaryInterface $summary */ $summary = $this->factory->create(); $summary->setGrossAmount($productTotal->getGrossPrice()); $summary->setNetAmount($productTotal->getNetPrice()); $summary->setTaxAmount($productTotal->getTaxAmount()); $modifiers->map(function (OrderModifierInterface $modifier) use($summary, $targetCurrency) { $baseCurrency = $modifier->getCurrency(); $grossAmount = $this->helper->convert($modifier->getGrossAmount(), $baseCurrency, $targetCurrency); $netAmount = $this->helper->convert($modifier->getNetAmount(), $baseCurrency, $targetCurrency); $taxAmount = $this->helper->convert($modifier->getTaxAmount(), $baseCurrency, $targetCurrency); if ($modifier->isSubtraction()) { $summary->setGrossAmount($summary->getGrossAmount() - $grossAmount); $summary->setNetAmount($summary->getNetAmount() - $netAmount); $summary->setTaxAmount($summary->getTaxAmount() - $taxAmount); } else { $summary->setGrossAmount($summary->getGrossAmount() + $grossAmount); $summary->setNetAmount($summary->getNetAmount() + $netAmount); $summary->setTaxAmount($summary->getTaxAmount() + $taxAmount); } }); $order->setSummary($summary); }
public function initResource() : EntityInterface { $entity = $this->factory->create(); $this->dispatchEvent(self::POST_ENTITY_INIT_EVENT, $entity); return $entity; }