WIP : Implement coupon check on ordering tunnel
@todo CSS @todo List coupon used and detailed effects
This commit is contained in:
@@ -105,6 +105,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$coupon = $couponFactory->buildCouponFromCode($event->getCode());
|
$coupon = $couponFactory->buildCouponFromCode($event->getCode());
|
||||||
|
|
||||||
$isValid = $coupon->isMatching();
|
$isValid = $coupon->isMatching();
|
||||||
|
|
||||||
if ($isValid) {
|
if ($isValid) {
|
||||||
/** @var Request $request */
|
/** @var Request $request */
|
||||||
$request = $this->container->get('request');
|
$request = $this->container->get('request');
|
||||||
@@ -121,7 +122,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
|
|
||||||
$totalDiscount = $couponManager->getDiscount();
|
$totalDiscount = $couponManager->getDiscount();
|
||||||
|
|
||||||
|
// @todo decrement coupon quantity
|
||||||
|
|
||||||
// @todo modify Cart total discount
|
// @todo modify Cart total discount
|
||||||
|
$request->getSession()->getCart()->setDiscount($totalDiscount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$event->setIsValid($isValid);
|
$event->setIsValid($isValid);
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
</route>
|
</route>
|
||||||
|
|
||||||
<route id="order.coupon.process" path="/order/coupon" methods="post">
|
<route id="order.coupon.process" path="/order/coupon" methods="post">
|
||||||
<default key="_controller">Thelia\Controller\Front\CouponController::consume</default>
|
<default key="_controller">Thelia\Controller\Front\CouponController::consumeAction</default>
|
||||||
<default key="_view">order-invoice</default>
|
<default key="_view">order-invoice</default>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class CouponController extends BaseFrontController
|
|||||||
|
|
||||||
// Dispatch Event to the Action
|
// Dispatch Event to the Action
|
||||||
$this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $couponConsumeEvent);
|
$this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $couponConsumeEvent);
|
||||||
|
|
||||||
} catch (FormValidationException $e) {
|
} catch (FormValidationException $e) {
|
||||||
$message = sprintf('Please check your coupon code: %s', $e->getMessage());
|
$message = sprintf('Please check your coupon code: %s', $e->getMessage());
|
||||||
} catch (PropelException $e) {
|
} catch (PropelException $e) {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getCheckoutTotalPrice()
|
public function getCheckoutTotalPrice()
|
||||||
{
|
{
|
||||||
// TODO: Implement getCheckoutTotalPrice() method.
|
return $this->getRequest()->getSession()->getOrder()->getTotalAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +117,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getCheckoutPostagePrice()
|
public function getCheckoutPostagePrice()
|
||||||
{
|
{
|
||||||
// TODO: Implement getCheckoutPostagePrice() method.
|
return $this->getRequest()->getSession()->getOrder()->getPostage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +127,8 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getCartTotalPrice()
|
public function getCartTotalPrice()
|
||||||
{
|
{
|
||||||
// TODO: Implement getCartTotalPrice() method.
|
return $this->getRequest()->getSession()->getCart()->getTotalAmount();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +138,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getCheckoutCurrency()
|
public function getCheckoutCurrency()
|
||||||
{
|
{
|
||||||
$this->getRequest()->getSession()->getCurrency();
|
return $this->getRequest()->getSession()->getCurrency()->getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +149,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getNbArticlesInCart()
|
public function getNbArticlesInCart()
|
||||||
{
|
{
|
||||||
// TODO: Implement getNbArticlesInCart() method.
|
return count($this->getRequest()->getSession()->getCart()->getCartItems());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,16 +159,13 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getCurrentCoupons()
|
public function getCurrentCoupons()
|
||||||
{
|
{
|
||||||
// @todo implement
|
$couponCodes = $this->getRequest()->getSession()->getConsumedCoupons();
|
||||||
// $consumedCoupons = $this->getRequest()->getSession()->getConsumedCoupons();
|
|
||||||
// @todo convert coupon code to coupon Interface
|
|
||||||
|
|
||||||
|
|
||||||
|
if (null === $couponCodes) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
$couponFactory = $this->container->get('thelia.coupon.factory');
|
$couponFactory = $this->container->get('thelia.coupon.factory');
|
||||||
|
|
||||||
// @todo get from cart
|
|
||||||
$couponCodes = array('XMAS', 'SPRINGBREAK');
|
|
||||||
|
|
||||||
$coupons = array();
|
$coupons = array();
|
||||||
foreach ($couponCodes as $couponCode) {
|
foreach ($couponCodes as $couponCode) {
|
||||||
$coupons[] = $couponFactory->buildCouponFromCode($couponCode);
|
$coupons[] = $couponFactory->buildCouponFromCode($couponCode);
|
||||||
@@ -246,7 +244,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
*/
|
*/
|
||||||
public function getMainCurrency()
|
public function getMainCurrency()
|
||||||
{
|
{
|
||||||
// TODO: Implement getMainCurrency() method.
|
return $this->getRequest()->getSession()->getCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class CouponManager
|
|||||||
/** @var CouponInterface $coupon */
|
/** @var CouponInterface $coupon */
|
||||||
foreach ($coupons as $coupon) {
|
foreach ($coupons as $coupon) {
|
||||||
// @todo modify Cart with discount for each cart item
|
// @todo modify Cart with discount for each cart item
|
||||||
$discount += $coupon->getDiscount($this->adapter);
|
$discount += $coupon->exec($this->adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $discount;
|
return $discount;
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
*
|
*
|
||||||
* @return float Amount removed from the Total Checkout
|
* @return float Amount removed from the Total Checkout
|
||||||
*/
|
*/
|
||||||
public function getDiscount()
|
public function exec()
|
||||||
{
|
{
|
||||||
return $this->amount;
|
return $this->amount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ interface CouponInterface
|
|||||||
*
|
*
|
||||||
* @return float Amount removed from the Total Checkout
|
* @return float Amount removed from the Total Checkout
|
||||||
*/
|
*/
|
||||||
public function getDiscount();
|
public function exec();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the current Coupon is matching its conditions (Rules)
|
* Check if the current Coupon is matching its conditions (Rules)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getDiscount()
|
public function exec()
|
||||||
{
|
{
|
||||||
if ($this->percent >= 100) {
|
if ($this->percent >= 100) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
|
|||||||
Reference in New Issue
Block a user