|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Lc\ShopBundle\Context\OrderShopInterface; |
|
|
use Lc\ShopBundle\Context\OrderShopInterface; |
|
|
use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface; |
|
|
use Lc\ShopBundle\Context\OrderShopPriceUtilsInterface; |
|
|
|
|
|
use Lc\ShopBundle\Model\ReductionCart; |
|
|
|
|
|
|
|
|
class OrderShopPriceUtils implements OrderShopPriceUtilsInterface |
|
|
class OrderShopPriceUtils implements OrderShopPriceUtilsInterface |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop); |
|
|
return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function getTaxRateAverage(OrderShopInterface $order):float |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->getTotalOrderProductsWithTax() / $this->getTotalOrderProducts(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) |
|
|
public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|