use customer permanent discount
This commit is contained in:
@@ -48,6 +48,12 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
$append = $event->getAppend();
|
||||
$quantity = $event->getQuantity();
|
||||
$currency = $cart->getCurrency();
|
||||
$customer = $cart->getCustomer();
|
||||
$discount = 0;
|
||||
|
||||
if(null !== $customer && $customer->getDiscount() > 0) {
|
||||
$discount = $customer->getDiscount();
|
||||
}
|
||||
|
||||
$productSaleElementsId = $event->getProductSaleElementsId();
|
||||
$productId = $event->getProduct();
|
||||
@@ -60,7 +66,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
->findPk($productSaleElementsId);
|
||||
|
||||
if (null !== $productSaleElements) {
|
||||
$productPrices = $productSaleElements->getPricesByCurrency($currency);
|
||||
$productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);
|
||||
$event->setCartItem(
|
||||
$this->doAddItem($event->getDispatcher(), $cart, $productId, $productSaleElements, $quantity, $productPrices)
|
||||
);
|
||||
@@ -151,11 +157,18 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
public function updateCartPrices(\Thelia\Model\Cart $cart, Currency $currency)
|
||||
{
|
||||
|
||||
$customer = $cart->getCustomer();
|
||||
$discount = 0;
|
||||
|
||||
if(null !== $customer && $customer->getDiscount() > 0) {
|
||||
$discount = $customer->getDiscount();
|
||||
}
|
||||
|
||||
// cart item
|
||||
foreach ($cart->getCartItems() as $cartItem) {
|
||||
$productSaleElements = $cartItem->getProductSaleElements();
|
||||
|
||||
$productPrice = $productSaleElements->getPricesByCurrency($currency);
|
||||
$productPrice = $productSaleElements->getPricesByCurrency($currency, $discount);
|
||||
|
||||
$cartItem
|
||||
->setPrice($productPrice->getPrice())
|
||||
|
||||
@@ -457,12 +457,19 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
||||
}
|
||||
|
||||
$taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
|
||||
/** @var \Thelia\Core\Security\SecurityContext $securityContext */
|
||||
$securityContext = $this->container->get('thelia.securityContext');
|
||||
|
||||
foreach ($loopResult->getResultDataCollection() as $product) {
|
||||
|
||||
$loopResultRow = new LoopResultRow($product);
|
||||
|
||||
$price = $product->getVirtualColumn('price');
|
||||
|
||||
if ($securityContext->hasCustomerUser() && $securityContext->getCustomerUser()->getDiscount() > 0) {
|
||||
$price = $price * (1-($securityContext->getCustomerUser()->getDiscount()/100));
|
||||
}
|
||||
|
||||
try {
|
||||
$taxedPrice = $product->getTaxedPrice(
|
||||
$taxCountry,
|
||||
@@ -472,6 +479,10 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
||||
$taxedPrice = null;
|
||||
}
|
||||
$promoPrice = $product->getVirtualColumn('promo_price');
|
||||
|
||||
if ($securityContext->hasCustomerUser() && $securityContext->getCustomerUser()->getDiscount() > 0) {
|
||||
$promoPrice = $promoPrice * (1-($securityContext->getCustomerUser()->getDiscount()/100));
|
||||
}
|
||||
try {
|
||||
$taxedPromoPrice = $product->getTaxedPromoPrice(
|
||||
$taxCountry,
|
||||
@@ -938,6 +949,8 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
||||
$loopResult = new LoopResult($results);
|
||||
|
||||
$taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
|
||||
/** @var \Thelia\Core\Security\SecurityContext $securityContext */
|
||||
$securityContext = $this->container->get('thelia.securityContext');
|
||||
|
||||
foreach ($loopResult->getResultDataCollection() as $product) {
|
||||
|
||||
@@ -945,10 +958,14 @@ class Product extends BaseI18nLoop implements PropelSearchLoopInterface, SearchL
|
||||
|
||||
$price = $product->getRealLowestPrice();
|
||||
|
||||
if ($securityContext->hasCustomerUser() && $securityContext->getCustomerUser()->getDiscount() > 0) {
|
||||
$price = $price * (1-($securityContext->getCustomerUser()->getDiscount()/100));
|
||||
}
|
||||
|
||||
try {
|
||||
$taxedPrice = $product->getTaxedPrice(
|
||||
$taxCountry,
|
||||
$product->getRealLowestPrice()
|
||||
$price
|
||||
);
|
||||
} catch (TaxEngineException $e) {
|
||||
$taxedPrice = null;
|
||||
|
||||
@@ -135,27 +135,40 @@ class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
|
||||
public function parseResults(LoopResult $loopResult)
|
||||
{
|
||||
$taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
|
||||
/** @var \Thelia\Core\Security\SecurityContext $securityContext */
|
||||
$securityContext = $this->container->get('thelia.securityContext');
|
||||
$discount = 0;
|
||||
|
||||
if ($securityContext->hasCustomerUser() && $securityContext->getCustomerUser()->getDiscount() > 0) {
|
||||
$discount = $securityContext->getCustomerUser()->getDiscount();
|
||||
}
|
||||
|
||||
foreach ($loopResult->getResultDataCollection() as $PSEValue) {
|
||||
$loopResultRow = new LoopResultRow($PSEValue);
|
||||
|
||||
$price = $PSEValue->getPrice();
|
||||
$price = $PSEValue->getPrice('price_PRICE', $discount);
|
||||
try {
|
||||
$taxedPrice = $PSEValue->getTaxedPrice(
|
||||
$taxCountry
|
||||
$taxCountry,
|
||||
'price_PRICE',
|
||||
$discount
|
||||
);
|
||||
} catch (TaxEngineException $e) {
|
||||
$taxedPrice = null;
|
||||
}
|
||||
$promoPrice = $PSEValue->getPromoPrice();
|
||||
|
||||
$promoPrice = $PSEValue->getPromoPrice('price_PROMO_PRICE', $discount);
|
||||
try {
|
||||
$taxedPromoPrice = $PSEValue->getTaxedPromoPrice(
|
||||
$taxCountry
|
||||
$taxCountry,
|
||||
'price_PROMO_PRICE',
|
||||
$discount
|
||||
);
|
||||
} catch (TaxEngineException $e) {
|
||||
$taxedPromoPrice = null;
|
||||
}
|
||||
|
||||
|
||||
$loopResultRow
|
||||
->set("ID" , $PSEValue->getId())
|
||||
->set("QUANTITY" , $PSEValue->getQuantity())
|
||||
|
||||
@@ -8,10 +8,14 @@ use Thelia\TaxEngine\Calculator;
|
||||
|
||||
class ProductSaleElements extends BaseProductSaleElements
|
||||
{
|
||||
public function getPrice($virtualColumnName = 'price_PRICE')
|
||||
public function getPrice($virtualColumnName = 'price_PRICE', $discount = 0)
|
||||
{
|
||||
try {
|
||||
$amount = $this->getVirtualColumn($virtualColumnName);
|
||||
|
||||
if ($discount > 0) {
|
||||
$amount = $amount * (1-($discount/100));
|
||||
}
|
||||
} catch (PropelException $e) {
|
||||
throw new PropelException("Virtual column `$virtualColumnName` does not exist in ProductSaleElements::getPrice");
|
||||
}
|
||||
@@ -19,10 +23,14 @@ class ProductSaleElements extends BaseProductSaleElements
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function getPromoPrice($virtualColumnName = 'price_PROMO_PRICE')
|
||||
public function getPromoPrice($virtualColumnName = 'price_PROMO_PRICE', $discount = 0)
|
||||
{
|
||||
try {
|
||||
$amount = $this->getVirtualColumn($virtualColumnName);
|
||||
|
||||
if ($discount > 0) {
|
||||
$amount = $amount * (1-($discount/100));
|
||||
}
|
||||
} catch (PropelException $e) {
|
||||
throw new PropelException("Virtual column `$virtualColumnName` does not exist in ProductSaleElements::getPromoPrice");
|
||||
}
|
||||
@@ -30,18 +38,18 @@ class ProductSaleElements extends BaseProductSaleElements
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function getTaxedPrice(Country $country)
|
||||
public function getTaxedPrice(Country $country , $virtualColumnName = 'price_PRICE', $discount = 0)
|
||||
{
|
||||
$taxCalculator = new Calculator();
|
||||
|
||||
return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()), 2);
|
||||
return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice($virtualColumnName, $discount)), 2);
|
||||
}
|
||||
|
||||
public function getTaxedPromoPrice(Country $country)
|
||||
public function getTaxedPromoPrice(Country $country, $virtualColumnName = 'price_PROMO_PRICE', $discount = 0)
|
||||
{
|
||||
$taxCalculator = new Calculator();
|
||||
|
||||
return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()), 2);
|
||||
return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice($virtualColumnName, $discount)), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +64,7 @@ class ProductSaleElements extends BaseProductSaleElements
|
||||
* @return ProductPriceTools
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function getPricesByCurrency($currency)
|
||||
public function getPricesByCurrency(Currency $currency, $discount = 0)
|
||||
{
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
|
||||
@@ -85,6 +93,11 @@ class ProductSaleElements extends BaseProductSaleElements
|
||||
$promoPrice = $productPrice->getPromoPrice();
|
||||
}
|
||||
|
||||
if ($discount > 0) {
|
||||
$price = $price * (1-($discount/100));
|
||||
$promoPrice = $promoPrice * (1-($discount/100));
|
||||
}
|
||||
|
||||
$productPriceTools = new ProductPriceTools($price, $promoPrice);
|
||||
|
||||
return $productPriceTools;
|
||||
|
||||
Reference in New Issue
Block a user