change price if needed when customer log in or log out
This commit is contained in:
@@ -51,7 +51,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
$customer = $cart->getCustomer();
|
$customer = $cart->getCustomer();
|
||||||
$discount = 0;
|
$discount = 0;
|
||||||
|
|
||||||
if(null !== $customer && $customer->getDiscount() > 0) {
|
if (null !== $customer && $customer->getDiscount() > 0) {
|
||||||
$discount = $customer->getDiscount();
|
$discount = $customer->getDiscount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
$customer = $cart->getCustomer();
|
$customer = $cart->getCustomer();
|
||||||
$discount = 0;
|
$discount = 0;
|
||||||
|
|
||||||
if(null !== $customer && $customer->getDiscount() > 0) {
|
if (null !== $customer && $customer->getDiscount() > 0) {
|
||||||
$discount = $customer->getDiscount();
|
$discount = $customer->getDiscount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ trait CartTrait
|
|||||||
*/
|
*/
|
||||||
protected function duplicateCart(EventDispatcherInterface $dispatcher, CartModel $cart, Session $session, Customer $customer = null)
|
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());
|
$session->setCart($newCart->getId());
|
||||||
|
|
||||||
$cartEvent = new CartEvent($newCart);
|
$cartEvent = new CartEvent($newCart);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use Thelia\Core\Security\Resource\AdminResources;
|
|||||||
use Thelia\Form\Cache\AssetsFlushForm;
|
use Thelia\Form\Cache\AssetsFlushForm;
|
||||||
use Thelia\Form\Cache\CacheFlushForm;
|
use Thelia\Form\Cache\CacheFlushForm;
|
||||||
use Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm;
|
use Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm;
|
||||||
use Thelia\Form\Exception\FormValidationException;
|
|
||||||
use Thelia\Log\Tlog;
|
use Thelia\Log\Tlog;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
|
|
||||||
|
|||||||
@@ -173,8 +173,7 @@ class Module extends BaseI18nLoop implements PropelSearchLoopInterface
|
|||||||
new \ReflectionClass($module->getFullNamespace());
|
new \ReflectionClass($module->getFullNamespace());
|
||||||
|
|
||||||
$exists = true;
|
$exists = true;
|
||||||
}
|
} catch (\ReflectionException $ex) {
|
||||||
catch(\ReflectionException $ex) {
|
|
||||||
$exists = false;
|
$exists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
|
|||||||
$taxedPromoPrice = null;
|
$taxedPromoPrice = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$loopResultRow
|
$loopResultRow
|
||||||
->set("ID" , $PSEValue->getId())
|
->set("ID" , $PSEValue->getId())
|
||||||
->set("QUANTITY" , $PSEValue->getQuantity())
|
->set("QUANTITY" , $PSEValue->getQuantity())
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Cart extends BaseCart
|
|||||||
* @param Customer $customer
|
* @param Customer $customer
|
||||||
* @return Cart
|
* @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();
|
$cartItems = $this->getCartItems();
|
||||||
|
|
||||||
@@ -26,11 +26,21 @@ class Cart extends BaseCart
|
|||||||
$cart->setAddressDeliveryId($this->getAddressDeliveryId());
|
$cart->setAddressDeliveryId($this->getAddressDeliveryId());
|
||||||
$cart->setAddressInvoiceId($this->getAddressInvoiceId());
|
$cart->setAddressInvoiceId($this->getAddressInvoiceId());
|
||||||
$cart->setToken($token);
|
$cart->setToken($token);
|
||||||
// TODO : set current Currency
|
$discount = 0;
|
||||||
$cart->setCurrencyId($this->getCurrencyId());
|
|
||||||
|
if (null === $currency) {
|
||||||
|
$currencyQuery = CurrencyQuery::create();
|
||||||
|
$currency = $currencyQuery->findPk($this->getCurrencyId()) ?: $currencyQuery->findOneByByDefault(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart->setCurrency($currency);
|
||||||
|
|
||||||
if ($customer) {
|
if ($customer) {
|
||||||
$cart->setCustomer($customer);
|
$cart->setCustomer($customer);
|
||||||
|
|
||||||
|
if ($customer->getDiscount() > 0) {
|
||||||
|
$discount = $customer->getDiscount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cart->save();
|
$cart->save();
|
||||||
@@ -50,25 +60,18 @@ class Cart extends BaseCart
|
|||||||
$item->setProductId($cartItem->getProductId());
|
$item->setProductId($cartItem->getProductId());
|
||||||
$item->setQuantity($cartItem->getQuantity());
|
$item->setQuantity($cartItem->getQuantity());
|
||||||
$item->setProductSaleElements($productSaleElements);
|
$item->setProductSaleElements($productSaleElements);
|
||||||
if ($currentDateTime <= $cartItem->getPriceEndOfLife()) {
|
$prices = $productSaleElements->getPricesByCurrency($currency, $discount);
|
||||||
$item->setPrice($cartItem->getPrice())
|
$item
|
||||||
->setPromoPrice($cartItem->getPromoPrice())
|
->setPrice($prices->getPrice())
|
||||||
->setPromo($productSaleElements->getPromo())
|
->setPromoPrice($prices->getPromoPrice())
|
||||||
// TODO : new price EOF or duplicate current priceEOF from $cartItem ?
|
->setPromo($productSaleElements->getPromo());
|
||||||
->setPriceEndOfLife($cartItem->getPriceEndOfLife());
|
|
||||||
} else {
|
|
||||||
$productPrices = ProductPriceQuery::create()->filterByProductSaleElements($productSaleElements)->findOne();
|
|
||||||
|
|
||||||
$item->setPrice($productPrices->getPrice())
|
|
||||||
->setPromoPrice($productPrices->getPromoPrice())
|
|
||||||
->setPromo($productSaleElements->getPromo())
|
|
||||||
->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60*60*24*30));
|
|
||||||
}
|
|
||||||
$item->save();
|
$item->save();
|
||||||
$dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem));
|
$dispatcher->dispatch(TheliaEvents::CART_ITEM_DUPLICATE, new CartItemDuplicationItem($item, $cartItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$this->delete();
|
||||||
|
|
||||||
return $cart;
|
return $cart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,7 +165,8 @@ class Module extends BaseModule
|
|||||||
/**
|
/**
|
||||||
* @return true if this module is a delivery module
|
* @return true if this module is a delivery module
|
||||||
*/
|
*/
|
||||||
public function isDeliveryModule() {
|
public function isDeliveryModule()
|
||||||
|
{
|
||||||
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
|
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
|
||||||
|
|
||||||
return $moduleReflection->implementsInterface("Thelia\Module\DeliveryModuleInterface");
|
return $moduleReflection->implementsInterface("Thelia\Module\DeliveryModuleInterface");
|
||||||
@@ -174,17 +175,18 @@ class Module extends BaseModule
|
|||||||
/**
|
/**
|
||||||
* @return true if this module is a payment module
|
* @return true if this module is a payment module
|
||||||
*/
|
*/
|
||||||
public function isPayementModule() {
|
public function isPayementModule()
|
||||||
|
{
|
||||||
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
|
$moduleReflection = new \ReflectionClass($this->getFullNamespace());
|
||||||
|
|
||||||
return $moduleReflection->implementsInterface("Thelia\Module\PaymentModuleInterface");
|
return $moduleReflection->implementsInterface("Thelia\Module\PaymentModuleInterface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BaseModule a new module instance.
|
* @return BaseModule a new module instance.
|
||||||
*/
|
*/
|
||||||
public function createInstance() {
|
public function createInstance()
|
||||||
|
{
|
||||||
$moduleClass = new \ReflectionClass($this->getFullNamespace());
|
$moduleClass = new \ReflectionClass($this->getFullNamespace());
|
||||||
|
|
||||||
return $moduleClass->newInstance();
|
return $moduleClass->newInstance();
|
||||||
|
|||||||
Reference in New Issue
Block a user