{ | { | ||||
if(!$orderProduct->getOrderProductReductionCatalog()) { | if(!$orderProduct->getOrderProductReductionCatalog()) { | ||||
if (is_null($productFamily)) { | if (is_null($productFamily)) { | ||||
$productFamily = $this->productFamilyStore->setSection($section)->getOneBySlug( | |||||
$orderProduct->getProduct()->getProductFamily()->getSlug() | |||||
); | |||||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||||
} | } | ||||
$reductionCatalog = $productFamily->getReductionCatalog(); | $reductionCatalog = $productFamily->getReductionCatalog(); |
} | } | ||||
public function getTotalWithReduction(OrderProductInterface $orderProduct) | |||||
public function getTotalWithReduction(OrderProductInterface $orderProduct, bool $round = true) | |||||
{ | { | ||||
return $this->applyReductionCatalog( | return $this->applyReductionCatalog( | ||||
$orderProduct, | $orderProduct, | ||||
$this->getTotal($orderProduct), | $this->getTotal($orderProduct), | ||||
$this->getTotalWithTax($orderProduct), | |||||
$this->getTotalWithTax($orderProduct, $round), | |||||
$orderProduct->getQuantityOrder(), | $orderProduct->getQuantityOrder(), | ||||
null, | null, | ||||
false | |||||
false, | |||||
$round | |||||
); | ); | ||||
} | } | ||||
public function getTotalWithTax(OrderProductInterface $orderProduct) | |||||
public function getTotalWithTax(OrderProductInterface $orderProduct, $round = true) | |||||
{ | { | ||||
return $this->applyTax( | return $this->applyTax( | ||||
$this->getTotal($orderProduct), | $this->getTotal($orderProduct), | ||||
$orderProduct->getTaxRate()->getValue() | |||||
$orderProduct->getTaxRate()->getValue(), | |||||
$round | |||||
); | ); | ||||
} | } | ||||
return $this->applyReductionCatalog( | return $this->applyReductionCatalog( | ||||
$orderProduct, | $orderProduct, | ||||
$this->getTotal($orderProduct), | $this->getTotal($orderProduct), | ||||
$this->getTotalWithTax($orderProduct), | |||||
$this->getTotalWithTax($orderProduct, $round), | |||||
$orderProduct->getQuantityOrder(), | $orderProduct->getQuantityOrder(), | ||||
null, | null, | ||||
true, | true, |
$total = 0; | $total = 0; | ||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | foreach ($orderShop->getOrderProducts() as $orderProduct) { | ||||
$total += $this->orderProductPriceResolver->getTotalWithReduction($orderProduct); | |||||
$total += $this->orderProductPriceResolver->getTotalWithReduction($orderProduct, false); | |||||
} | } | ||||
return $this->round($total); | return $this->round($total); | ||||
} | } | ||||
{ | { | ||||
$total = 0; | $total = 0; | ||||
foreach ($orderProducts as $orderProduct) { | foreach ($orderProducts as $orderProduct) { | ||||
$total += $this->orderProductPriceResolver->getTotalWithTaxAndReduction($orderProduct); | |||||
$total += $this->orderProductPriceResolver->getTotalWithTaxAndReduction($orderProduct, false); | |||||
} | } | ||||
return $this->round($total); | return $this->round($total); |
trait PriceSolverTrait | trait PriceSolverTrait | ||||
{ | { | ||||
public function applyTax($price, $taxRateValue) | |||||
public function applyTax($price, $taxRateValue, $round = true) | |||||
{ | { | ||||
return $this->round($this->applyPercent($price, $taxRateValue)); | |||||
$price = $this->applyPercent($price, $taxRateValue); | |||||
if($round) { | |||||
return $this->round($price); | |||||
} | |||||
return $price; | |||||
} | } | ||||
public function applyReductionPercent($price, $percentage) | public function applyReductionPercent($price, $percentage) |