diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 6b09b6fca..a5e27be2d 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -103,25 +103,25 @@ - + Thelia\Controller\Admin\CouponController::browseAction - + Thelia\Controller\Admin\CouponController::createAction - + Thelia\Controller\Admin\CouponController::updateAction - + Thelia\Controller\Admin\CouponController::readAction - + Thelia\Controller\Admin\CouponController::getRuleInputAction Thelia\Controller\Admin\CouponController::updateRulesAction - + Thelia\Controller\Admin\CouponController::consumeAction diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 8a4d283f9..0b5b24daa 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -74,7 +74,54 @@ class CouponController extends BaseAdminController { $this->checkAuth('ADMIN', 'admin.coupon.view'); - return $this->render('coupon-list'); + $args['urlReadCoupon'] = $this->getRoute( + 'admin.coupon.read', + array('couponId' => 'couponId'), + Router::ABSOLUTE_URL + ); + + $args['urlEditCoupon'] = $this->getRoute( + 'admin.coupon.update', + array('couponId' => 'couponId'), + Router::ABSOLUTE_URL + ); + + $args['urlCreateCoupon'] = $this->getRoute( + 'admin.coupon.create', + array(), + Router::ABSOLUTE_URL + ); + + return $this->render('coupon-list', $args); + } + + /** + * Manage Coupons read display + * + * @param int $couponId Coupon Id + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function readAction($couponId) + { + $this->checkAuth('ADMIN', 'admin.coupon.read'); + + // Database request repeated in the loop but cached + $search = CouponQuery::create(); + $coupon = $search->findOneById($couponId); + + if ($coupon === null) { + return $this->pageNotFound(); + } + + $args['couponId'] = $couponId; + $args['urlEditCoupon'] = $this->getRoute( + 'admin.coupon.update', + array('couponId' => $couponId), + Router::ABSOLUTE_URL + ); + + return $this->render('coupon-read', $args); } /** @@ -95,7 +142,7 @@ class CouponController extends BaseAdminController $i18n = new I18n(); /** @var Lang $lang */ - $lang = $this->getSession()->get('lang'); + $lang = $this->getSession()->getLang(); $eventToDispatch = TheliaEvents::COUPON_CREATE; if ($this->getRequest()->isMethod('POST')) { @@ -113,7 +160,8 @@ class CouponController extends BaseAdminController ->format($lang->getDateFormat()); } - $args['formAction'] = 'admin/coupon/create'; + $args['availableCoupons'] = $this->getAvailableCoupons(); + $args['formAction'] = 'admin/coupon/create/'; return $this->render( 'coupon-create', @@ -205,7 +253,7 @@ class CouponController extends BaseAdminController // Pass it to the parser $this->getParserContext()->addForm($changeForm); } - + $args['couponCode'] = $coupon->getCode(); $args['availableCoupons'] = $this->getAvailableCoupons(); $args['availableRules'] = $this->getAvailableRules(); $args['urlAjaxGetRuleInput'] = $this->getRoute( @@ -320,27 +368,7 @@ class CouponController extends BaseAdminController - /** - * Manage Coupons read display - * - * @param int $couponId Coupon Id - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function readAction($couponId) - { - $this->checkAuth('ADMIN', 'admin.coupon.read'); - // Database request repeated in the loop but cached - $search = CouponQuery::create(); - $coupon = $search->findOneById($couponId); - - if ($coupon === null) { - return $this->pageNotFound(); - } - - return $this->render('coupon-read', array('couponId' => $couponId)); - } /** * Manage Coupons read display @@ -657,17 +685,17 @@ class CouponController extends BaseAdminController /** @var CouponManager $couponManager */ $couponManager = $this->container->get('thelia.coupon.manager'); $availableCoupons = $couponManager->getAvailableCoupons(); - $cleanedRules = array(); + $cleanedCoupons = array(); /** @var CouponInterface $availableCoupon */ foreach ($availableCoupons as $availableCoupon) { $rule = array(); $rule['serviceId'] = $availableCoupon->getServiceId(); $rule['name'] = $availableCoupon->getName(); $rule['toolTip'] = $availableCoupon->getToolTip(); - $cleanedRules[] = $rule; + $cleanedCoupons[] = $rule; } - return $cleanedRules; + return $cleanedCoupons; } /** diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 9cef73e37..4e8ca3e71 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -24,6 +24,7 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\Util\PropelModelPager; use Thelia\Constraint\ConstraintFactory; use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Core\HttpFoundation\Request; @@ -38,6 +39,7 @@ use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\CouponQuery; use Thelia\Model\Coupon as MCoupon; use Thelia\Type; +use Thelia\Type\BooleanOrBothType; /** * Created by JetBrains PhpStorm. @@ -53,17 +55,22 @@ use Thelia\Type; class Coupon extends BaseI18nLoop { /** + * Define all args used in your loop + * * @return ArgumentCollection */ protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createIntListTypeArgument('id') + Argument::createIntListTypeArgument('id'), + Argument::createBooleanOrBothTypeArgument('is_enabled', 1) ); } /** - * @param $pagination + * Execute Loop + * + * @param PropelModelPager $pagination * * @return \Thelia\Core\Template\Element\LoopResult */ @@ -75,11 +82,16 @@ class Coupon extends BaseI18nLoop $locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION', 'SHORT_DESCRIPTION')); $id = $this->getId(); + $isEnabled = $this->getIsEnabled(); if (null !== $id) { $search->filterById($id, Criteria::IN); } + if ($isEnabled != BooleanOrBothType::ANY) { + $search->filterByIsEnabled($isEnabled ? 1 : 0); + } + // Perform search $coupons = $this->search($search, $pagination); @@ -122,7 +134,7 @@ class Coupon extends BaseI18nLoop $cleanedRules = array(); /** @var CouponRuleInterface $rule */ - foreach ($rules->getRules() as $key => $rule) { + foreach ($rules->getRules() as $rule) { $cleanedRules[] = $rule->getToolTip(); } $loopResultRow->set("ID", $coupon->getId()) diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index d63a4284d..9e41bae4f 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -23,7 +23,10 @@ namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\Date; +use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\NotEqualTo; /** * Created by JetBrains PhpStorm. @@ -68,7 +71,6 @@ class CouponCreationForm extends BaseForm 'shortDescription', 'text', array( - 'invalid_message' => 'test', 'constraints' => array( new NotBlank() ) @@ -78,7 +80,6 @@ class CouponCreationForm extends BaseForm 'description', 'textarea', array( - 'invalid_message' => 'test', 'constraints' => array( new NotBlank() ) @@ -88,16 +89,23 @@ class CouponCreationForm extends BaseForm 'effect', 'text', array( - 'invalid_message' => 'test', 'constraints' => array( - new NotBlank() + new NotBlank(), + new NotEqualTo( + array( + 'value' => -1 + ) + ) ) ) ) ->add( 'amount', 'money', - array() + array( + 'constraints' => array( + new NotBlank() + )) ) ->add( 'isEnabled', @@ -109,7 +117,8 @@ class CouponCreationForm extends BaseForm 'text', array( 'constraints' => array( - new NotBlank() + new NotBlank(), + new Date() ) ) ) @@ -133,7 +142,12 @@ class CouponCreationForm extends BaseForm 'text', array( 'constraints' => array( - new NotBlank() + new NotBlank(), + new GreaterThanOrEqual( + array( + 'value' => -1 + ) + ) ) ) ) diff --git a/install/insert.sql b/install/insert.sql index fce22b924..f8123f859 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -18,7 +18,7 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()), ('page_not_found_view', '404.html', 0, 0, NOW(), NOW()), ('use_tax_free_amounts', 0, 1, 0, NOW(), NOW()), -('process_assets', '0', 0, 0, NOW(), NOW()); +('process_assets', '1', 0, 0, NOW(), NOW()); INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index b15c624f3..3b97c069b 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -146,7 +146,7 @@ {loop name="menu-auth-coupon" type="auth" roles="ADMIN" permissions="admin.coupon.view"}
  • - {intl l="Coupons"} + {intl l="Coupons"}
  • {/loop} diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index d07217061..37f8de41f 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -115,6 +115,8 @@ $(function($){ // Reload effect inputs when changing effect couponManager.onEffectChange = function() { + var optionSelected = $("option:selected", this); + $('#effectToolTip').html(optionSelected.attr("data-description")); $('#effect').on('change', function () { var optionSelected = $("option:selected", this); $('#effectToolTip').html(optionSelected.attr("data-description")); @@ -134,6 +136,32 @@ $(function($){ // var onInputsChange = function() // In AJAX response + // Set max usage to unlimited or not + couponManager.onUsageUnlimitedChange = function() { + if (!$('#max-usage').parent().hasClass('has-error')) { + $('#max-usage').hide().attr('value', '-1'); + } + $('#is-unlimited').change(function(){ + var $this = $(this); + if ($this.is(':checked')) { + $('#max-usage').hide().attr('value', '-1'); + } else { + $('#max-usage').show().val('').attr('value', ''); + } + }); + }; + couponManager.onUsageUnlimitedChange(); + +// // -- Effect description +// if($('[name=effect]').length){ +// var $effectSelect = $('[name=effect]'), +// $helpBlock = $effectSelect.next('.help-block'); +// +// $effectSelect.change(function(){ +// var description = $(this).find(":selected").data('description'); +// $helpBlock.text(description); +// }); +// } }); // Rule to save diff --git a/templates/admin/default/assets/js/main.js b/templates/admin/default/assets/js/main.js index d472a22a9..094dfe623 100644 --- a/templates/admin/default/assets/js/main.js +++ b/templates/admin/default/assets/js/main.js @@ -40,34 +40,7 @@ }); }*/ - // -- Effect description - if($('[name=effect]').length){ - var $effectSelect = $('[name=effect]'), - $helpBlock = $effectSelect.next('.help-block'); - $effectSelect.change(function(){ - var description = $(this).find(":selected").data('description'); - $helpBlock.text(description); - }); - } - - // -- Max usage -- - if($('#is-unlimited').length){ - - if($('#is-unlimited').is(':checked')){ - $('#max-usage').hide().attr('value', '-1'); - } - - $('#is-unlimited').change(function(){ - if($('#is-unlimited').is(':checked')){ - $('#max-usage').hide().attr('value', '-1'); - } - else{ - $('#max-usage').show().val('').attr('value', ''); - } - }); - - } // -- Bootstrap tooltip -- if($('[rel="tooltip"]').length){ diff --git a/templates/admin/default/coupon-create.html b/templates/admin/default/coupon-create.html index e8fcb73f5..b87b21195 100755 --- a/templates/admin/default/coupon-create.html +++ b/templates/admin/default/coupon-create.html @@ -7,12 +7,14 @@ {form name="thelia.admin.coupon.creation"} @@ -33,9 +35,11 @@ {/javascripts} - + {javascripts file='assets/js/json2.js'} + + {/javascripts} + + {javascripts file='assets/js/coupon.js'} + + {/javascripts} {/block} diff --git a/templates/admin/default/coupon-list.html b/templates/admin/default/coupon-list.html index e4a1d5e36..2eafde586 100755 --- a/templates/admin/default/coupon-list.html +++ b/templates/admin/default/coupon-list.html @@ -7,70 +7,50 @@
    - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {loop type="coupon" name="list_coupon" is_enabled="1" backend_context="true"} + + + + + + + + {/loop}
    - List of enabled coupons + {intl l='Enabled coupons'}
    CodeTitleExpiration dateUsage leftActions{block name="coupon-label-code"}{intl l='Code'}{/block}{block name="coupon-label-title"}{intl l='Title'}{/block}{block name="coupon-label-expiration-date"}{intl l='Expiration date'}{/block}{block name="coupon-label-usage-left"}{intl l='Usage left'}{/block}{block name="coupon-label-action"}{/block}
    XMAS13Coupon for XMAS -30 €18/10/201349 - Edit - Disable -
    XMAS13Coupon for XMAS -30 €05/09/201320 - Edit - Disable -
    XMAS13Coupon for XMAS -30 €03/12/20139 - Edit - Disable -
    XMAS13Coupon for XMAS -30 €25/01/20134 - Edit - Disable -
    {block name="coupon-code"}{$CODE}{/block}{block name="coupon-title"}{$TITLE}{/block}{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}{block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + {block name="coupon-action"} + + {intl l='Edit'} + + {/block} +
    @@ -80,58 +60,33 @@
    - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {loop type="coupon" name="list_coupon" is_enabled="0" backend_context="true"} + + + + + + + + {/loop}
    - List of disabled coupons + {intl l='Disabled coupons'}
    CodeTitleExpiration dateUsage leftActions{block name="coupon-label-code"}{intl l='Code'}{/block}{block name="coupon-label-title"}{intl l='Title'}{/block}{block name="coupon-label-expiration-date"}{intl l='Expiration date'}{/block}{block name="coupon-label-usage-left"}{intl l='Usage left'}{/block}{block name="coupon-label-action"}{/block}
    XMAS13Coupon for XMAS -30 €18/10/201349 - Edit - Enabled -
    XMAS13Coupon for XMAS -20 €05/09/201349 - Edit - Enabled -
    XMAS13Coupon for XMAS -50 €03/12/201349 - Edit - Enabled -
    XMAS13Coupon for XMAS -5 €25/01/201349 - Edit - Enabled -
    {block name="coupon-code"}{$CODE}{/block}{block name="coupon-title"}{$TITLE}{/block}{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}{block name="coupon-usage-left"}{$USAGE_LEFT}{/block} + {block name="coupon-action"} + + {intl l='Edit'} + + {/block} +
    @@ -139,9 +94,6 @@
    -{include file='includes/confirmation-modal.html' id="disable" message="{intl l='Do you really want to disable this element ?'}"} -{include file='includes/confirmation-modal.html' id="enable" message="{intl l='Do you really want to enable this element ?'}"} - {/block} diff --git a/templates/admin/default/coupon-read.html b/templates/admin/default/coupon-read.html index 985bf5499..4ae5e5c68 100755 --- a/templates/admin/default/coupon-read.html +++ b/templates/admin/default/coupon-read.html @@ -4,141 +4,146 @@ {block name="main-content"}
    - + {loop type="coupon" name="read_coupon" id={$couponId} backend_context="true"} - {loop type="coupon" name="read_coupon" id={$couponId} backend_context="true"} - -
    -
    - -
    - - {if !$IS_ENABLED}{intl l='This coupon is disabled, you can enable to the bottom of this form.'}{/if} -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    {intl l='Title'}{$TITLE}
    - {if $IS_ENABLED} - - {intl l="Is enabled"} - - {else} - - {intl l="Is disabled"} - - {/if} -
    - {$TOOLTIP} -
    {intl l='Expiration date'}{$EXPIRATION_DATE} ({$DAY_LEFT_BEFORE_EXPIRATION} {intl l="days left"})
    {intl l='Usage left'} - {if $USAGE_LEFT} - - {$USAGE_LEFT} - - {else} - - 0 - - {/if} -
    {$SHORT_DESCRIPTION}
    {$DESCRIPTION}
    - {if $IS_CUMULATIVE} - - {intl l="May be cumulative"} - - {else} - - {intl l="Can't be cumulative"} - - {/if} -
    - {if $IS_REMOVING_POSTAGE} - - {intl l="Will remove postage"} - - {else} - - {intl l="Won't remove postage"} - - {/if} -
    - {if $IS_AVAILABLE_ON_SPECIAL_OFFERS} - - {intl l="Will be available on special offers"} - - {else} - - {intl l="Won't be available on special offers"} - - {/if} -
    {intl l='Amount'}{$AMOUNT}
    {intl l='Application field'} -
      - {foreach from=$APPLICATION_CONDITIONS item=rule name=rulesForeach} - {if !$smarty.foreach.rulesForeach.first} -
    • {intl l='And'}
    • - {/if} -
    • {$rule nofilter}
    • - {/foreach} -
    -
    {intl l='Actions'} - {intl l='Edit'} -
    - {/loop} + -
    + +
    +
    + + {if !$IS_ENABLED} +
    + + {intl l='This coupon is disabled, you can enable to the bottom of this form.'} +
    + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {intl l='Title'}{$TITLE}
    + {if $IS_ENABLED} + + {intl l="Is enabled"} + + {else} + + {intl l="Is disabled"} + + {/if} +
    + {$TOOLTIP} +
    {intl l='Amount'}{$AMOUNT}
    {intl l='Expiration date'}{$EXPIRATION_DATE} ({$DAY_LEFT_BEFORE_EXPIRATION} {intl l="days left"})
    {intl l='Usage left'} + {if $USAGE_LEFT} + + {$USAGE_LEFT} + + {else} + + 0 + + {/if} +
    + {if $IS_CUMULATIVE} + + {intl l="May be cumulative"} + + {else} + + {intl l="Can't be cumulative"} + + {/if} +
    + {if $IS_REMOVING_POSTAGE} + + {intl l="Will remove postage"} + + {else} + + {intl l="Won't remove postage"} + + {/if} +
    + {if $IS_AVAILABLE_ON_SPECIAL_OFFERS} + + {intl l="Will be available on special offers"} + + {else} + + {intl l="Won't be available on special offers"} + + {/if} +
    {intl l='Application field'} +
      + {foreach from=$APPLICATION_CONDITIONS item=rule name=rulesForeach} + {if !$smarty.foreach.rulesForeach.first} +
    • {intl l='And'}
    • + {/if} +
    • {$rule nofilter}
    • + {/foreach} +
    +
    {$SHORT_DESCRIPTION}
    {$DESCRIPTION}
    + + {intl l='Edit'} + +
    +
    +
    + {/loop}
    {include file='includes/confirmation-modal.html' id="enable" message="{intl l='Do you really want to enable this element ?'}"} diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index e1621c3f8..0902dae4c 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -7,12 +7,14 @@ {form name="thelia.admin.coupon.creation"} diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 85b9438ef..92b834fe7 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -11,118 +11,119 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field}
    -
    - - {form_field form=$form field='code'} + {form_field form=$form field='code'} +
    + {if $error}{$message}{/if} - {/form_field} -
    +
    + {/form_field} -
    - - {form_field form=$form field='title'} + {form_field form=$form field='title'} +
    + {if $error}{$message}{/if} - {/form_field} -
    +
    + {/form_field} -
    - +
    + {/form_field} -
    - +
    + {/form_field} -
    - +
    + {/form_field} -
    -
    -
    - - {form_field form=$form field='effect'} + {form_field form=$form field='effect'} +
    + {if $error}{$message}{/if} - {/form_field} - {$availableCoupons.0.toolTip} -
    + {$availableCoupons.0.toolTip} +
    + {/form_field}
    -
    - - {form_field form=$form field='amount'} + {form_field form=$form field='amount'} +
    + {if $error}{$message}{/if} - {/form_field} -
    - {*
    *} +
    + {/form_field} + {*
    *} {**} {*form_field form=$form field='category'*} {* + {form_field form=$form field='shortDescription'} +
    + + {if $error}{$message}{/if} - {/form_field} -
    +
    + {/form_field}
    -
    - - {form_field form=$form field='description'} + {form_field form=$form field='description'} +
    + {if $error}{$message}{/if} - {/form_field} -
    +
    + {/form_field} - +
    @@ -186,16 +187,16 @@
    - + {intl l='Save this rule'}
    diff --git a/templates/admin/default/includes/coupon_breadcrumb.html b/templates/admin/default/includes/coupon_breadcrumb.html deleted file mode 100755 index 878d9605d..000000000 --- a/templates/admin/default/includes/coupon_breadcrumb.html +++ /dev/null @@ -1,5 +0,0 @@ -{* Breadcrumb for coupon browsing and editing *} - -
  • Home
  • -
  • Coupon
  • -
  • Browse
  • \ No newline at end of file