cart integration

This commit is contained in:
Etienne Roudeix
2013-09-16 13:15:35 +02:00
parent 2857d0621c
commit e0a48df23e
7 changed files with 304 additions and 106 deletions

View File

@@ -8,6 +8,7 @@ use Thelia\Model\Base\Cart as BaseCart;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Model\ProductPriceQuery;
use Thelia\Model\CartItemQuery;
use Thelia\TaxEngine\Calculator;
class Cart extends BaseCart
{
@@ -72,9 +73,25 @@ class Cart extends BaseCart
;
}
public function getTaxedAmount()
public function getTaxedAmount(Country $country)
{
$taxCalculator = new Calculator();
$total = 0;
foreach($this->getCartItems() as $cartItem) {
$subtotal = $cartItem->getRealPrice();
$subtotal -= $cartItem->getDiscount();
/* we round it for the unit price, before the quantity factor */
$subtotal = round($taxCalculator->load($cartItem->getProduct(), $country)->getTaxedPrice($subtotal), 2);
$subtotal *= $cartItem->getQuantity();
$total += $subtotal;
}
$total -= $this->getDiscount();
return $total;
}
public function getTotalAmount()
@@ -82,7 +99,11 @@ class Cart extends BaseCart
$total = 0;
foreach($this->getCartItems() as $cartItem) {
$total += $cartItem->getPrice()-$cartItem->getDiscount();
$subtotal = $cartItem->getRealPrice();
$subtotal -= $cartItem->getDiscount();
$subtotal *= $cartItem->getQuantity();
$total += $subtotal;
}
$total -= $this->getDiscount();

View File

@@ -65,6 +65,11 @@ class CartItem extends BaseCartItem
return $this;
}
public function getRealPrice()
{
return $this->getPromo() == 1 ? $this->getPromoPrice() : $this->getPrice();
}
public function getTaxedPrice(Country $country)
{
$taxCalculator = new Calculator();