Skip to content

Commit

Permalink
Tax management
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-hubert committed Apr 9, 2018
1 parent a0d831d commit 718832f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
27 changes: 27 additions & 0 deletions Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ class Order
*/
private $totalWoTax;

/**
* @var float
*
* @ORM\Column(name="total", type="decimal", precision=10, scale=2)
*/
private $total;

/**
* @var string
*
Expand Down Expand Up @@ -370,4 +377,24 @@ public function setDiscount($discount)

return $this;
}

/**
* @return float
*/
public function getTotal()
{
return $this->total;
}

/**
* @param float $total
* @return Order
*/
public function setTotal($total = null)
{
$this->total = $total;

return $this;
}

}
2 changes: 1 addition & 1 deletion EventListener/AnalyticsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function onOrderPostPersist(OrderEvent $event)

$data = [
'ti' => $order->getId(),
'tr' => $order->getTotalWoTax(),
'tr' => $order->getTotal(),
'tt' => 0,
'cu' => $order->getCurrency(),
];
Expand Down
15 changes: 12 additions & 3 deletions Helper/Cart/CartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ public function getCurrentCart(Customer $customer = null)
* @throws CartAccessDeniedException
* @throws CartNotFoundException
*/
public function getTotal($withProductDiscount = true, $withCartDiscount = true, $cartId = null, $withShipment = true)
{
public function getTotal(
$withProductDiscount = true,
$withCartDiscount = true,
$cartId = null,
$withShipment = true,
$withTaxes = 0
) {
$total = 0;

if ($cartId === null) {
Expand Down Expand Up @@ -186,6 +191,10 @@ public function getTotal($withProductDiscount = true, $withCartDiscount = true,
$total += $shipment->getPrice();
}

if (!empty($withTaxes)) {
$total += ($total * $withTaxes / 100);
}

return $total;
}

Expand Down Expand Up @@ -468,7 +477,7 @@ public function memorize(Cart $cart, $newName = null, $deleteAfterMemorize = tru
*/
public function switchCart(Cart $cart, Customer $customer = null, $keepSavedCart = true)
{
if($customer === null) {
if ($customer === null) {
$customer = $this->customer;
}

Expand Down
5 changes: 3 additions & 2 deletions Helper/Order/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public function newOrder(Cart $cart, Customer $customer)
}

$order->setDiscount($this->cartManager->getCartDiscount());
$order->setBareTotalWoTax($this->cartManager->getTotal(true, false));
$order->setTotalWoTax($this->cartManager->getTotal(true, true));
$order->setBareTotalWoTax($this->cartManager->getTotal(true, false, null, true, 0));
$order->setTotalWoTax($this->cartManager->getTotal(true, true, null, true, 0));
$order->setTotal($this->cartManager->getTotal(true, true, null, true, $customer->getVatRate()));

return $order
->setCart($cart)
Expand Down

0 comments on commit 718832f

Please sign in to comment.