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