From 5abe350b65e62a4327258dc19cf4a0164fc6389f Mon Sep 17 00:00:00 2001 From: gmorel Date: Fri, 27 Sep 2013 14:52:38 +0200 Subject: [PATCH] WIP : Coupon : Fix condition selection JS + Dependency Injection register --- .../Thelia/Controller/Admin/CouponController.php | 15 ++++++--------- core/lib/Thelia/Core/Bundle/TheliaBundle.php | 6 ++---- ...lePass.php => RegisterCouponConditionPass.php} | 10 ++++++---- core/lib/Thelia/Coupon/CouponManager.php | 2 +- core/lib/Thelia/Form/CouponCreationForm.php | 9 +++++---- templates/admin/default/assets/js/coupon.js | 12 ++++++------ templates/admin/default/coupon-update.html | 2 +- templates/admin/default/coupon/form.html | 2 -- 8 files changed, 27 insertions(+), 31 deletions(-) rename core/lib/Thelia/Core/DependencyInjection/Compiler/{RegisterRulePass.php => RegisterCouponConditionPass.php} (92%) diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 0ba2e961b..0bf2a4a39 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -208,10 +208,7 @@ class CouponController extends BaseAdminController $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedConditions() ); -var_dump($coupon->getIsEnabled());; -var_dump($coupon->getIsAvailableOnSpecialOffers());; -var_dump($coupon->getIsCumulative());; -var_dump($coupon->getIsRemovingPostage());; + $data = array( 'code' => $coupon->getCode(), 'title' => $coupon->getTitle(), @@ -219,11 +216,11 @@ var_dump($coupon->getIsRemovingPostage());; 'type' => $coupon->getType(), 'shortDescription' => $coupon->getShortDescription(), 'description' => $coupon->getDescription(), - 'isEnabled' => ($coupon->getIsEnabled() == 1), + 'isEnabled' => $coupon->getIsEnabled(), 'expirationDate' => $coupon->getExpirationDate('Y-m-d'), - 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1), - 'isCumulative' => ($coupon->getIsCumulative() == 1), - 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), + 'isAvailableOnSpecialOffers' => $coupon->getIsAvailableOnSpecialOffers(), + 'isCumulative' => $coupon->getIsCumulative(), + 'isRemovingPostage' => $coupon->getIsRemovingPostage(), 'maxUsage' => $coupon->getMaxUsage(), 'conditions' => $conditions, 'locale' => $coupon->getLocale(), @@ -264,7 +261,7 @@ var_dump($coupon->getIsRemovingPostage());; Router::ABSOLUTE_URL ); - $args['formAction'] = 'admin/coupon/update' . $couponId; + $args['formAction'] = 'admin/coupon/update/' . $couponId; return $this->render('coupon-update', $args); } diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index a9704b350..dcdcdd5d2 100755 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -30,7 +30,7 @@ use Thelia\Core\DependencyInjection\Compiler\RegisterCouponPass; use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass; use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass; use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass; -use Thelia\Core\DependencyInjection\Compiler\RegisterRulePass; +use Thelia\Core\DependencyInjection\Compiler\RegisterCouponConditionPass; /** * First Bundle use in Thelia @@ -63,8 +63,6 @@ class TheliaBundle extends Bundle ->addCompilerPass(new RegisterParserPluginPass()) ->addCompilerPass(new RegisterRouterPass()) ->addCompilerPass(new RegisterCouponPass()) - ->addCompilerPass(new RegisterRulePass()) - ; - + ->addCompilerPass(new RegisterCouponConditionPass()); } } diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRulePass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php similarity index 92% rename from core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRulePass.php rename to core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php index dcc54cf8e..7caf79c5e 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRulePass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterCouponConditionPass.php @@ -35,11 +35,13 @@ use Symfony\Component\DependencyInjection\Reference; * Class RegisterListenersPass * Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class * + * Register all available Conditions for the coupon module + * * @package Thelia\Core\DependencyInjection\Compiler * @author Guillaume MOREL * */ -class RegisterRulePass implements CompilerPassInterface +class RegisterCouponConditionPass implements CompilerPassInterface { /** * You can modify the container here before it is dumped to PHP code. @@ -55,11 +57,11 @@ class RegisterRulePass implements CompilerPassInterface } $couponManager = $container->getDefinition('thelia.coupon.manager'); - $services = $container->findTaggedServiceIds("thelia.coupon.addRule"); + $services = $container->findTaggedServiceIds("thelia.coupon.addCondition"); - foreach ($services as $id => $rule) { + foreach ($services as $id => $condition) { $couponManager->addMethodCall( - 'addAvailableRule', + 'addAvailableCondition', array( new Reference($id) ) diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php index c4ba661be..09e5a30e8 100644 --- a/core/lib/Thelia/Coupon/CouponManager.php +++ b/core/lib/Thelia/Coupon/CouponManager.php @@ -241,7 +241,7 @@ class CouponManager * * @param ConditionManagerInterface $condition ConditionManagerInterface */ - public function addAvailableRule(ConditionManagerInterface $condition) + public function addAvailableCondition(ConditionManagerInterface $condition) { $this->availableConditions[] = $condition; } diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index f3ee0df63..fcb2e793c 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -28,6 +28,7 @@ use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotEqualTo; +use Symfony\Component\Validator\Constraints\Range; /** * Created by JetBrains PhpStorm. @@ -110,7 +111,7 @@ class CouponCreationForm extends BaseForm ) ->add( 'isEnabled', - 'checkbox', + 'text', array() ) ->add( @@ -125,17 +126,17 @@ class CouponCreationForm extends BaseForm ) ->add( 'isCumulative', - 'checkbox', + 'text', array() ) ->add( 'isRemovingPostage', - 'checkbox', + 'text', array() ) ->add( 'isAvailableOnSpecialOffers', - 'checkbox', + 'text', array() ) ->add( diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 68cfb42e9..de36414bd 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -55,7 +55,7 @@ $(function($){ $.couponManager.conditionToSave = $.couponManager.conditionsToSave[id]; // Set the condition selector - $("#category-rule option").filter(function() { + $("#category-condition option").filter(function() { return $(this).val() == $.couponManager.conditionToSave.serviceId; }).prop('selected', true); @@ -90,7 +90,7 @@ $(function($){ // Save conditions on click $.couponManager.onClickSaveCondition = function() { $('#constraint-save-btn').on('click', function () { - if($('#category-rule').val() == 'thelia.condition.match_for_everyone') { + 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 ?"); if (r == true) { @@ -140,7 +140,7 @@ $(function($){ // Reload condition inputs when changing effect $.couponManager.onConditionChange = function() { - $('#category-rule').on('change', function () { + $('#category-condition').on('change', function () { $.couponManager.loadConditionInputs($(this).val(), function() {}); }); }; @@ -152,9 +152,9 @@ $(function($){ // Set max usage to unlimited or not $.couponManager.onUsageUnlimitedChange = function() { - var isUnlimited = $('#is-unlimited'); + var $isUnlimited = $('#is-unlimited'); if ($('#max-usage').val() == -1) { - isUnlimited.prop('checked', true); + $isUnlimited.prop('checked', true); $('#max-usage').hide(); $('#max-usage-label').hide(); } else { @@ -163,7 +163,7 @@ $(function($){ $('#max-usage-label').show(); } - isUnlimited.change(function(){ + $isUnlimited.change(function(){ var $this = $(this); if ($this.is(':checked')) { $('#max-usage').hide().val('-1'); diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index be9354362..97a10f122 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -43,7 +43,7 @@