|
|
@@ -4,6 +4,7 @@ namespace Lc\ShopBundle\Price\Services; |
|
|
|
|
|
|
|
use Lc\ShopBundle\Context\OrderShopInterface; |
|
|
|
use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface; |
|
|
|
use Lc\ShopBundle\Model\ReductionCart; |
|
|
|
|
|
|
|
class OrderShopPriceUtils implements OrderShopPriceUtilsInterface |
|
|
|
{ |
|
|
@@ -69,7 +70,10 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface |
|
|
|
return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function getTaxRateAverage(OrderShopInterface $order):float |
|
|
|
{ |
|
|
|
return $this->getTotalOrderProductsWithTax() / $this->getTotalOrderProducts(); |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) |
|
|
|
{ |
|
|
@@ -81,5 +85,40 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function applyOrderProductsReductionCart(OrderShopInterface $order, $withTax = true) |
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($order->getOrderReductionCarts() as $orderReductionCart) { |
|
|
|
if($orderReductionCart->getAppliedTo() == ReductionCart::APPLIED_TO_ORDER_PRODUCTS) { |
|
|
|
if ($orderReductionCart->getUnit() == 'percent') { |
|
|
|
|
|
|
|
$priceWithTax = $this->applyReductionPercent( |
|
|
|
$this->getTotalOrderProductsWithTax($order), |
|
|
|
$orderReductionCart->getValue |
|
|
|
); |
|
|
|
} else if ($orderReductionCart->getUnit() == 'amount') { |
|
|
|
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') { |
|
|
|
$priceWithTax = $this->applyTax( |
|
|
|
$this->applyReductionAmount( |
|
|
|
$this->getTotalOrderProducts($order), |
|
|
|
$orderReductionCart->getValue() |
|
|
|
), |
|
|
|
$order->getTaxRateAverage() |
|
|
|
); |
|
|
|
} else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') { |
|
|
|
$priceWithTax = |
|
|
|
$this->applyReductionAmount( |
|
|
|
$this->getTotalOrderProductsWithTax($order), |
|
|
|
$orderReductionCart->getValue() |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|