diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index b3086c266..5d58745f1 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -26,6 +26,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Condition\ConditionFactory; use Thelia\Condition\ConditionManagerInterface; +use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; @@ -68,7 +69,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface */ public function update(CouponCreateOrUpdateEvent $event) { - $coupon = $event->getCoupon(); + $coupon = $event->getCouponModel(); $this->createOrUpdate($coupon, $event); } @@ -76,13 +77,13 @@ class Coupon extends BaseAction implements EventSubscriberInterface /** * Occurring when a Coupon condition is about to be updated * - * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule + * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon condition */ public function updateCondition(CouponCreateOrUpdateEvent $event) { - $coupon = $event->getCoupon(); + $modelCoupon = $event->getCouponModel(); - $this->createOrUpdateCondition($coupon, $event); + $this->createOrUpdateCondition($modelCoupon, $event); } /** @@ -153,7 +154,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->getCode(), $event->getTitle(), $event->getAmount(), - $event->getType(), + $event->getServiceId(), $event->isRemovingPostage(), $event->getShortDescription(), $event->getDescription(), @@ -166,7 +167,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->getLocale() ); - $event->setCoupon($coupon); + $event->setCouponModel($coupon); } /** @@ -188,7 +189,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->getLocale() ); - $event->setCoupon($coupon); + $event->setCouponModel($coupon); } /** diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 0bf2a4a39..029af5a1b 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -27,7 +27,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Router; use Thelia\Condition\ConditionFactory; use Thelia\Condition\ConditionManagerInterface; -use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; @@ -336,23 +335,36 @@ class CouponController extends BaseAdminController // $conditionFactory->serializeCouponConditionCollection($conditions) // ); - $conditionEvent = new ConditionCreateOrUpdateEvent( - $conditions + $couponEvent = new CouponCreateOrUpdateEvent( + $coupon->getCode(), + $coupon->getTitle(), + $coupon->getAmount(), + $coupon->getType(), + $coupon->getShortDescription(), + $coupon->getDescription(), + $coupon->getIsEnabled(), + $coupon->getExpirationDate(), + $coupon->getIsAvailableOnSpecialOffers(), + $coupon->getIsCumulative(), + $coupon->getIsRemovingPostage(), + $coupon->getMaxUsage(), + $coupon->getLocale() ); - $conditionEvent->setCouponModel($coupon); + $couponEvent->setCouponModel($coupon); + $couponEvent->setConditions($conditions); $eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE; // Dispatch Event to the Action $this->dispatch( $eventToDispatch, - $conditionEvent + $couponEvent ); $this->adminLogAppend( sprintf( 'Coupon %s (ID %s) conditions updated', - $conditionEvent->getCouponModel()->getTitle(), - $conditionEvent->getCouponModel()->getServiceId() + $couponEvent->getCouponModel()->getTitle(), + $couponEvent->getCouponModel()->getType() ) ); @@ -489,14 +501,14 @@ class CouponController extends BaseAdminController sprintf( 'Coupon %s (ID ) ' . $log, $couponEvent->getTitle(), - $couponEvent->getCoupon()->getId() + $couponEvent->getCouponModel()->getId() ) ); $this->redirect( str_replace( '{id}', - $couponEvent->getCoupon()->getId(), + $couponEvent->getCouponModel()->getId(), $creationForm->getSuccessUrl() ) ); diff --git a/core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php deleted file mode 100644 index 58fdb10fe..000000000 --- a/core/lib/Thelia/Core/Event/Condition/ConditionCreateOrUpdateEvent.php +++ /dev/null @@ -1,106 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Core\Event\Condition; - -use Thelia\Core\Event\ActionEvent; -use Thelia\Coupon\ConditionCollection; -use Thelia\Coupon\Type\CouponInterface; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/29/13 - * Time: 3:45 PM - * - * Occurring when a Condition is created or updated - * - * @package Coupon - * @author Guillaume MOREL - * - */ -class ConditionCreateOrUpdateEvent extends ActionEvent -{ - /** @var ConditionCollection Array of ConditionManagerInterface */ - protected $conditions = null; - - /** @var CouponInterface Coupon model associated with this conditions */ - protected $couponModel = null; - - /** - * Constructor - * - * @param ConditionCollection $conditions Array of ConditionManagerInterface - */ - public function __construct(ConditionCollection $conditions) - { - $this->conditions = $conditions; - } - - /** - * Get Conditions - * - * @return null|ConditionCollection Array of ConditionManagerInterface - */ - public function getConditions() - { - return $this->conditions; - } - - /** - * Set Conditions - * - * @param ConditionCollection $conditions Array of ConditionManagerInterface - * - * @return $this - */ - public function setConditions(ConditionCollection $conditions) - { - $this->conditions = $conditions; - - return $this; - } - - /** - * Set Coupon Model associated to this condition - * - * @param CouponInterface $couponModel Coupon Model - * - * @return $this - */ - public function setCouponModel($couponModel) - { - $this->couponModel = $couponModel; - - return $this; - } - - /** - * Get Coupon Model associated to this condition - * - * @return null|CouponInterface - */ - public function getCouponModel() - { - return $this->couponModel; - } -} diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 3dfca3d4a..f890fd8cd 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -31,7 +31,7 @@ use Thelia\Model\Coupon; * Date: 8/29/13 * Time: 3:45 PM * - * Occurring when a Coupon is created + * Occurring when a Coupon is created or updated * * @package Coupon * @author Guillaume MOREL @@ -76,10 +76,10 @@ class CouponCreateOrUpdateEvent extends ActionEvent protected $isAvailableOnSpecialOffers = false; /** @var Coupon Coupon model */ - protected $coupon = null; + protected $couponModel = null; - /** @var string Coupon type */ - protected $type; + /** @var string Coupon Service id */ + protected $serviceId; /** @var string Language code ISO (ex: fr_FR) */ protected $locale = null; @@ -90,7 +90,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent * @param string $code Coupon Code * @param string $title Coupon title * @param float $amount Amount removed from the Total Checkout - * @param string $type Coupon type + * @param string $serviceId Coupon Service id * @param string $shortDescription Coupon short description * @param string $description Coupon description * @param bool $isEnabled Enable/Disable @@ -102,7 +102,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent * @param string $locale Coupon Language code ISO (ex: fr_FR) */ public function __construct( - $code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale + $code, $title, $amount, $serviceId, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale ) { $this->amount = $amount; @@ -116,7 +116,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $this->maxUsage = $maxUsage; $this->shortDescription = $shortDescription; $this->title = $title; - $this->type = $type; + $this->serviceId = $serviceId; $this->locale = $locale; } @@ -234,13 +234,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent } /** - * Get Coupon type (effect) + * Get Coupon Service id (Type) * * @return string */ - public function getType() + public function getServiceId() { - return $this->type; + return $this->serviceId; } /** @@ -256,13 +256,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent /** * Set Coupon Model * - * @param \Thelia\Model\Coupon $coupon Coupon Model + * @param Coupon $couponModel Coupon Model * * @return $this */ - public function setCoupon($coupon) + public function setCouponModel(Coupon $couponModel) { - $this->coupon = $coupon; + $this->couponModel = $couponModel; return $this; } @@ -272,13 +272,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent * * @return \Thelia\Model\Coupon */ - public function getCoupon() + public function getCouponModel() { - return $this->coupon; + return $this->couponModel; } /** - * Get Rules + * Get Conditions * * @return null|ConditionCollection Array of ConditionManagerInterface */ @@ -288,15 +288,15 @@ class CouponCreateOrUpdateEvent extends ActionEvent } /** - * set Rules + * Set Conditions * - * @param ConditionCollection $rules Array of ConditionManagerInterface + * @param ConditionCollection $conditions Array of ConditionManagerInterface * * @return $this */ - public function setConditions(ConditionCollection $rules) + public function setConditions(ConditionCollection $conditions) { - $this->conditions = $rules; + $this->conditions = $conditions; return $this; } diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index de36414bd..2c412765a 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -89,7 +89,7 @@ $(function($){ // Save conditions on click $.couponManager.onClickSaveCondition = function() { - $('#constraint-save-btn').on('click', function () { + $('#condition-save-btn').on('click', function () { if($('#category-condition').val() == 'thelia.condition.match_for_everyone') { // // @todo translate message + put it in modal var r = confirm("Do you really want to set this coupon available to everyone ?"); @@ -106,7 +106,7 @@ $(function($){ // Remove condition on click $.couponManager.onClickDeleteCondition = function() { - $('.constraint-delete-btn').on('click', function (e) { + $('.condition-delete-btn').on('click', function (e) { e.preventDefault(); var $this = $(this); $.couponManager.removeConditionAjax($this.attr('data-int')); diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 98ea53fcb..5e132b5cc 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -194,13 +194,13 @@
- - - + {**} + {**} + {**}