From 8e308d21e99dc44a247213c74b69400400125d4c Mon Sep 17 00:00:00 2001 From: gmorel Date: Thu, 19 Sep 2013 23:25:01 +0200 Subject: [PATCH] Working : Coupon : fix update effect (becomes type), update max usage --- .../Thelia/Config/Resources/routing/admin.xml | 19 ++++++++++++------- .../Controller/Admin/CouponController.php | 7 ++++--- .../Coupon/CouponCreateOrUpdateEvent.php | 12 ++++++------ core/lib/Thelia/Form/CouponCreationForm.php | 2 +- core/lib/Thelia/Model/Coupon.php | 6 +++--- .../Thelia/Tests/Coupon/RuleOrganizerTest.php | 3 ++- templates/admin/default/assets/js/coupon.js | 17 ++++++++++++----- templates/admin/default/coupon/form.html | 18 ++++++++++-------- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index af7c950af..15e450c01 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -160,26 +160,31 @@ - + Thelia\Controller\Admin\CouponController::browseAction - + Thelia\Controller\Admin\CouponController::createAction - + Thelia\Controller\Admin\CouponController::updateAction + \d+ - + Thelia\Controller\Admin\CouponController::readAction + \d+ - + Thelia\Controller\Admin\CouponController::getRuleInputAction + .* - + Thelia\Controller\Admin\CouponController::updateRulesAction + \d+ - + Thelia\Controller\Admin\CouponController::consumeAction + .* diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f50c58307..f7804de8e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -201,7 +201,7 @@ class CouponController extends BaseAdminController $lang = $this->getSession()->getLang(); $eventToDispatch = TheliaEvents::COUPON_UPDATE; - // Create + // Update if ($this->getRequest()->isMethod('POST')) { $this->validateCreateOrUpdateForm( $i18n, @@ -210,7 +210,7 @@ class CouponController extends BaseAdminController 'updated', 'update' ); - } else { // Update + } else { // Display // Prepare the data that will hydrate the form /** @var ConstraintFactory $constraintFactory */ @@ -495,11 +495,12 @@ class CouponController extends BaseAdminController // Get the form field values $data = $form->getData(); + $couponEvent = new CouponCreateOrUpdateEvent( $data['code'], $data['title'], $data['amount'], - $data['effect'], + $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 2e004b818..e8f54fffb 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -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 $effect Coupon effect + * @param string $type Coupon type * @param string $shortDescription Coupon short description * @param string $description Coupon description * @param boolean $isEnabled Enable/Disable @@ -106,7 +106,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $code, $title, $amount, - $effect, + $type, $shortDescription, $description, $isEnabled, @@ -130,7 +130,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent $this->rules = $rules; $this->shortDescription = $shortDescription; $this->title = $title; - $this->effect = $effect; + $this->type = $type; $this->locale = $locale; } @@ -264,13 +264,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent } /** - * Get Coupon effect + * Get Coupon type (effect) * * @return string */ - public function getEffect() + public function getType() { - return $this->effect; + return $this->type; } /** diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 1625ab685..f3ee0df63 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -87,7 +87,7 @@ class CouponCreationForm extends BaseForm ) ) ->add( - 'effect', + 'type', 'text', array( 'constraints' => array( diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 032de412a..e40fd9078 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -54,7 +54,7 @@ class Coupon extends BaseCoupon * @param string $code Coupon Code * @param string $title Coupon title * @param float $amount Amount removed from the Total Checkout - * @param string $effect Coupon effect + * @param string $type Coupon type * @param bool $isRemovingPostage Is removing Postage * @param string $shortDescription Coupon short description * @param string $description Coupon description @@ -67,13 +67,13 @@ class Coupon extends BaseCoupon * * @throws \Exception */ - function createOrUpdate($code, $title, $amount, $effect, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null) + function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null) { $this->setCode($code) ->setTitle($title) ->setShortDescription($shortDescription) ->setDescription($description) - ->setType($effect) + ->setType($type) ->setAmount($amount) ->setIsRemovingPostage($isRemovingPostage) ->setIsEnabled($isEnabled) diff --git a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php index 3300cb19b..d13184a8c 100644 --- a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php +++ b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php @@ -23,6 +23,7 @@ namespace Thelia\Coupon; +use Thelia\Coupon\RuleOrganizer; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 @@ -47,7 +48,7 @@ class RuleOrganizerTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->object = new RuleOrganizer; + $this->object = new RuleOrganizer(); } /** diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 41e0c1430..dae26d4b4 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -138,17 +138,24 @@ $(function($){ // Set max usage to unlimited or not couponManager.onUsageUnlimitedChange = function() { - if (!$('#max-usage').parent().hasClass('has-error')) { - $('#max-usage').hide().attr('value', '-1'); + var isUnlimited = $('#is-unlimited'); + if ($('#max-usage').val() == -1) { + isUnlimited.prop('checked', true); + $('#max-usage').hide(); $('#max-usage-label').hide(); + } else { + $isUnlimited.prop('checked', false); + $('#max-usage').show(); + $('#max-usage-label').show(); } - $('#is-unlimited').change(function(){ + + isUnlimited.change(function(){ var $this = $(this); if ($this.is(':checked')) { - $('#max-usage').hide().attr('value', '-1'); + $('#max-usage').hide().val('-1'); $('#max-usage-label').hide(); } else { - $('#max-usage').show().val('').attr('value', ''); + $('#max-usage').show().val(''); $('#max-usage-label').show(); } }); diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index a4ec8b14a..68c74bee2 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -88,11 +88,11 @@
- + {if $error}{$message}{/if}
{/form_field} @@ -101,17 +101,19 @@
- {form_field form=$form field='effect'} + {form_field form=$form field='type'}
- - + {foreach from=$availableCoupons item=availableCoupon} - + {/foreach} {if $error}{$message}{/if} - {$availableCoupons.0.toolTip} + {$availableCoupons.0.toolTip}
{/form_field}