save if producSaleElements is in promo or not

This commit is contained in:
Manuel Raynaud
2013-09-16 10:49:42 +02:00
parent 365d90b4a8
commit da60359c15
2 changed files with 12 additions and 9 deletions

View File

@@ -65,7 +65,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
->filterByProductSaleElementsId($productSaleElementsId)
->findOne();
$this->doAddItem($cart, $productId, $productSaleElementsId, $quantity, $productPrice);
$this->doAddItem($cart, $productId, $productPrice->getProductSaleElements(), $quantity, $productPrice);
}
if ($append && $cartItem !== null) {
@@ -166,17 +166,18 @@ class Cart extends BaseAction implements EventSubscriberInterface
* @param float $quantity
* @param ProductPrice $productPrice
*/
protected function doAddItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice)
protected function doAddItem(\Thelia\Model\Cart $cart, $productId, \Thelia\Model\ProductSaleElements $productSaleElements, $quantity, ProductPrice $productPrice)
{
$cartItem = new CartItem();
$cartItem->setDisptacher($this->getDispatcher());
$cartItem
->setCart($cart)
->setProductId($productId)
->setProductSaleElementsId($productSaleElementsId)
->setProductSaleElementsId($productSaleElements->getId())
->setQuantity($quantity)
->setPrice($productPrice->getPrice())
->setPromoPrice($productPrice->getPromoPrice())
->setPromo($productSaleElements->getPromo())
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30))
->save();
}

View File

@@ -44,16 +44,18 @@ class Cart extends BaseCart
$item->setQuantity($cartItem->getQuantity());
$item->setProductSaleElements($productSaleElements);
if ($currentDateTime <= $cartItem->getPriceEndOfLife()) {
$item->setPrice($cartItem->getPrice());
$item->setPromoPrice($cartItem->getPromoPrice());
$item->setPrice($cartItem->getPrice())
->setPromoPrice($cartItem->getPromoPrice())
->setPromo($productSaleElements->getPromo())
// TODO : new price EOF or duplicate current priceEOF from $cartItem ?
$item->setPriceEndOfLife($cartItem->getPriceEndOfLife());
->setPriceEndOfLife($cartItem->getPriceEndOfLife());
} else {
$productPrices = ProductPriceQuery::create()->filterByProductSaleElements($productSaleElements)->findOne();
$item->setPrice($productPrices->getPrice());
$item->setPromoPrice($productPrices->getPromoPrice());
$item->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
$item->setPrice($productPrices->getPrice())
->setPromoPrice($productPrices->getPromoPrice())
->setPromo($productSaleElements->getPromo())
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
}
$item->save();
}