Browse Source

Processus de commande

feature/export_comptable
Fab 4 years ago
parent
commit
6b50dbada2
4 changed files with 46 additions and 32 deletions
  1. +5
    -0
      ShopBundle/Model/ReductionCart.php
  2. +1
    -0
      ShopBundle/Model/ReductionCartPropertyTrait.php
  3. +40
    -1
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  4. +0
    -31
      ShopBundle/Services/Price/PriceUtilsTrait.php

+ 5
- 0
ShopBundle/Model/ReductionCart.php View File

*/ */
abstract class ReductionCart extends AbstractEntity implements ReductionPropertyInterface, ReductionInterface, ReductionCartPropertyInterface, FilterMerchantInterface, OrderAmountMinInterface, StatusInterface abstract class ReductionCart extends AbstractEntity implements ReductionPropertyInterface, ReductionInterface, ReductionCartPropertyInterface, FilterMerchantInterface, OrderAmountMinInterface, StatusInterface
{ {

const APPLIED_TO_DELIVERY = 'delivery';
const APPLIED_TO_ORDER_PRODUCTS = 'order-products';


use StatusTrait; use StatusTrait;
use OrderAmountMin; use OrderAmountMin;
use ReductionTrait; use ReductionTrait;

+ 1
- 0
ShopBundle/Model/ReductionCartPropertyTrait.php View File



trait ReductionCartPropertyTrait trait ReductionCartPropertyTrait
{ {

/** /**
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
*/ */

+ 40
- 1
ShopBundle/Services/Price/OrderShopPriceUtils.php View File



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()
);

}
}
}
}

}

} }



+ 0
- 31
ShopBundle/Services/Price/PriceUtilsTrait.php View File

} }




public function applyReductionCart(OrderShopInterface $order, $withTax = true)
{

foreach ($order->getOrderReductionCarts() as $orderReductionCart) {
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->getTaxRateInherited()->getValue()
);
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-inlcluded') {
$priceWithTax =
$this->applyReductionAmount(
$this->getTotalOrderProductsWithTax($order),
$orderReductionCart->getValue()
);
}
}
}
}

}




} }

Loading…
Cancel
Save