show coupon codes in back office
This commit is contained in:
@@ -37,6 +37,7 @@ use Thelia\Condition\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Model\OrderCoupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -129,6 +130,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
->getCart()
|
||||
->setDiscount($totalDiscount)
|
||||
->save();
|
||||
$request
|
||||
->getSession()
|
||||
->getOrder()
|
||||
->setDiscount($totalDiscount)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +228,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* @param \Thelia\Core\Event\Order\OrderEvent $event
|
||||
*/
|
||||
public function decreaseCouponQuantity(OrderEvent $event)
|
||||
public function afterOrder(OrderEvent $event)
|
||||
{
|
||||
$request = $this->container->get('request');
|
||||
|
||||
@@ -233,10 +239,31 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
if (is_array($consumedCoupons)) {
|
||||
foreach($consumedCoupons as $couponCode) {
|
||||
// Decrement coupon quantity
|
||||
$couponQuery = CouponQuery::create();
|
||||
$couponModel = $couponQuery->findOneByCode($couponCode);
|
||||
$couponModel->setLocale($request->getSession()->getLang()->getLocale());
|
||||
|
||||
/* decrease coupon quantity */
|
||||
$couponManager->decrementQuantity($couponModel);
|
||||
|
||||
/* memorize coupon */
|
||||
$orderCoupon = new OrderCoupon();
|
||||
$orderCoupon->setOrder($event->getOrder())
|
||||
->setCode($couponModel->getCode())
|
||||
->setType($couponModel->getType())
|
||||
->setAmount($couponModel->getAmount())
|
||||
|
||||
->setTitle($couponModel->getTitle())
|
||||
->setShortDescription($couponModel->getShortDescription())
|
||||
->setDescription($couponModel->getDescription())
|
||||
|
||||
->setExpirationDate($couponModel->getExpirationDate())
|
||||
->setIsCumulative($couponModel->getIsCumulative())
|
||||
->setIsRemovingPostage($couponModel->getIsRemovingPostage())
|
||||
->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())
|
||||
->setSerializedConditions($couponModel->getSerializedConditions())
|
||||
;
|
||||
$orderCoupon->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +296,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
|
||||
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 256),
|
||||
TheliaEvents::ORDER_BEFORE_PAYMENT => array("decreaseCouponQuantity", 128),
|
||||
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ use Thelia\Core\Event\Cart\CartEvent;
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Exception\TheliaProcessException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
@@ -189,8 +190,6 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId()
|
||||
);
|
||||
|
||||
/* refresh discount @todo */
|
||||
|
||||
/* memorize discount */
|
||||
$placedOrder->setDiscount(
|
||||
$cart->getDiscount()
|
||||
@@ -280,8 +279,6 @@ class Order extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/* memorize coupons @todo */
|
||||
|
||||
$con->commit();
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
|
||||
|
||||
Reference in New Issue
Block a user