From 5773922314fb2a1fe4945140f8583f6c5c1c4cd0 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 19 Dec 2013 14:50:45 +0100 Subject: [PATCH] show coupon codes in back office --- core/lib/Thelia/Action/Coupon.php | 33 +++++++++++++++++-- core/lib/Thelia/Action/Order.php | 5 +-- .../Smarty/Plugins/DataAccessFunctions.php | 2 ++ local/config/schema.xml | 1 - templates/backOffice/default/order-edit.html | 6 +--- .../frontOffice/default/order-invoice.html | 11 ++++++- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 2042d3e66..4c76002ac 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -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), ); } } diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index b0c09ae1a..b32d883f6 100755 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -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)); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index a9ca6be6d..6a9348c64 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -211,6 +211,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin switch ($attribute) { case 'postage': return $order->getPostage(); + case 'discount': + return $order->getDiscount(); case 'delivery_address': return $order->chosenDeliveryAddress; case 'invoice_address': diff --git a/local/config/schema.xml b/local/config/schema.xml index 3e679e739..d8a2543a6 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1275,7 +1275,6 @@ - diff --git a/templates/backOffice/default/order-edit.html b/templates/backOffice/default/order-edit.html index 9eacf23fc..fc7903e1c 100755 --- a/templates/backOffice/default/order-edit.html +++ b/templates/backOffice/default/order-edit.html @@ -118,13 +118,9 @@ {intl l="Coupon code"} - {ifloop rel="couponcode"} -
    {loop type="order_coupon" name="couponcode" order=$ID} -
  • {$CODE}
  • + {$CODE}{if $LOOP_COUNT != $LOOP_TOTAL}, {/if} {/loop} -
- {/ifloop} {elseloop rel="couponcode"} Ø {/elseloop} diff --git a/templates/frontOffice/default/order-invoice.html b/templates/frontOffice/default/order-invoice.html index 149162110..befe89f81 100755 --- a/templates/frontOffice/default/order-invoice.html +++ b/templates/frontOffice/default/order-invoice.html @@ -122,8 +122,17 @@ + + +   + {intl l="Discount"} + +
+ {order attr="discount"} {currency attr="symbol"} +
+ + -   {intl l="Shipping Tax"}