change price if needed when customer log in or log out

This commit is contained in:
Manuel Raynaud
2014-04-29 11:35:10 +02:00
parent 406b06e09d
commit d0edbdfd5b
8 changed files with 162 additions and 159 deletions

View File

@@ -51,7 +51,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
$customer = $cart->getCustomer();
$discount = 0;
if(null !== $customer && $customer->getDiscount() > 0) {
if (null !== $customer && $customer->getDiscount() > 0) {
$discount = $customer->getDiscount();
}
@@ -160,7 +160,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
$customer = $cart->getCustomer();
$discount = 0;
if(null !== $customer && $customer->getDiscount() > 0) {
if (null !== $customer && $customer->getDiscount() > 0) {
$discount = $customer->getDiscount();
}

View File

@@ -112,7 +112,8 @@ trait CartTrait
*/
protected function duplicateCart(EventDispatcherInterface $dispatcher, CartModel $cart, Session $session, Customer $customer = null)
{
$newCart = $cart->duplicate($this->generateCookie($session), $customer, $dispatcher);
$currency = $session->getCurrency();
$newCart = $cart->duplicate($this->generateCookie($session), $customer, $currency, $dispatcher);
$session->setCart($newCart->getId());
$cartEvent = new CartEvent($newCart);

View File

@@ -19,7 +19,6 @@ use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Cache\AssetsFlushForm;
use Thelia\Form\Cache\CacheFlushForm;
use Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;

View File

@@ -173,8 +173,7 @@ class Module extends BaseI18nLoop implements PropelSearchLoopInterface
new \ReflectionClass($module->getFullNamespace());
$exists = true;
}
catch(\ReflectionException $ex) {
} catch (\ReflectionException $ex) {
$exists = false;
}

View File

@@ -168,7 +168,6 @@ class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
$taxedPromoPrice = null;
}
$loopResultRow
->set("ID" , $PSEValue->getId())
->set("QUANTITY" , $PSEValue->getQuantity())

View File

@@ -18,7 +18,7 @@ class Cart extends BaseCart
* @param Customer $customer
* @return Cart
*/
public function duplicate($token, Customer $customer = null, EventDispatcherInterface $dispatcher)
public function duplicate($token, Customer $customer = null, Currency $currency = null, EventDispatcherInterface $dispatcher)
{
$cartItems = $this->getCartItems();
@@ -26,11 +26,21 @@ class Cart extends BaseCart
$cart->setAddressDeliveryId($this->getAddressDeliveryId());
$cart->setAddressInvoiceId($this->getAddressInvoiceId());
$cart->setToken($token);
// TODO : set current Currency
$cart->setCurrencyId($this->getCurrencyId());
$discount = 0;
if (null === $currency) {
$currencyQuery = CurrencyQuery::create();
$currency = $currencyQuery->findPk($this->getCurrencyId()) ?: $currencyQuery->findOneByByDefault(1);
}
$cart->setCurrency($currency);
if ($customer) {
$cart->setCustomer($customer);
if ($customer->getDiscount() > 0) {
$discount = $customer->getDiscount();
}
}
$cart->save();
@@ -50,25 +60,18 @@ class Cart extends BaseCart
$item->setProductId($cartItem->getProductId());
$item->setQuantity($cartItem->getQuantity());
$item->setProductSaleElements($productSaleElements);
if ($currentDateTime <= $cartItem->getPriceEndOfLife()) {
$item->setPrice($cartItem->getPrice())
->setPromoPrice($cartItem->getPromoPrice())
->setPromo($productSaleElements->getPromo())
// TODO : new price EOF or duplicate current priceEOF from $cartItem ?
->setPriceEndOfLife($cartItem->getPriceEndOfLife());
} else {
$productPrices = ProductPriceQuery::create()->filterByProductSaleElements($productSaleElements)->findOne();
$prices = $productSaleElements->getPricesByCurrency($currency, $discount);
$item
->setPrice($prices->getPrice())
->setPromoPrice($prices->getPromoPrice())
->setPromo($productSaleElements->getPromo());
$item->setPrice($productPrices->getPrice())
->setPromoPrice($productPrices->getPromoPrice())
->setPromo($productSaleElements->getPromo())
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
}
$item->save();
$dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem));
}
}
$this->delete();
return $cart;
}

View File

@@ -165,7 +165,8 @@ class Module extends BaseModule
/**
* @return true if this module is a delivery module
*/
public function isDeliveryModule() {
public function isDeliveryModule()
{
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
return $moduleReflection->implementsInterface("Thelia\Module\DeliveryModuleInterface");
@@ -174,17 +175,18 @@ class Module extends BaseModule
/**
* @return true if this module is a payment module
*/
public function isPayementModule() {
public function isPayementModule()
{
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
return $moduleReflection->implementsInterface("Thelia\Module\PaymentModuleInterface");
}
/**
* @return BaseModule a new module instance.
*/
public function createInstance() {
public function createInstance()
{
$moduleClass = new \ReflectionClass($this->getFullNamespace());
return $moduleClass->newInstance();