diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 0b5b24daa..6803addfd 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -157,9 +157,10 @@ class CouponController extends BaseAdminController // If no input for expirationDate, now + 2 months $defaultDate = new \DateTime(); $args['defaultDate'] = $defaultDate->modify('+2 month') - ->format($lang->getDateFormat()); + ->format('Y-m-d'); } + $args['dateFormat'] = $this->getSession()->getLang()->getDateFormat(); $args['availableCoupons'] = $this->getAvailableCoupons(); $args['formAction'] = 'admin/coupon/create/'; @@ -224,7 +225,7 @@ class CouponController extends BaseAdminController 'shortDescription' => $coupon->getShortDescription(), 'description' => $coupon->getDescription(), 'isEnabled' => ($coupon->getIsEnabled() == 1), - 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()), + 'expirationDate' => $coupon->getExpirationDate('Y-m-d'), 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1), 'isCumulative' => ($coupon->getIsCumulative() == 1), 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), @@ -273,103 +274,6 @@ class CouponController extends BaseAdminController return $this->render('coupon-update', $args); } - -// /** -// * Manage Coupons Rule creation display -// * -// * @param int $couponId Coupon id -// * -// * @return \Symfony\Component\HttpFoundation\Response -// */ -// public function createRuleAction($couponId) -// { -// // Check current user authorization -// $response = $this->checkAuth('admin.coupon.update'); -// if ($response !== null) { -// return $response; -// } -// -// /** @var Coupon $coupon */ -// $coupon = CouponQuery::create()->findOneById($couponId); -// if (!$coupon) { -// $this->pageNotFound(); -// } -// -// // Parameters given to the template -// $args = array(); -// -// $i18n = new I18n(); -// /** @var Lang $lang */ -// $lang = $this->getSession()->get('lang'); -// $eventToDispatch = TheliaEvents::COUPON_RULE_CREATE; -// -// if ($this->getRequest()->isMethod('POST')) { -// $this->validateCreateOrUpdateForm( -// $i18n, -// $lang, -// $eventToDispatch, -// 'updated', -// 'update' -// ); -// } else { -// // Prepare the data that will hydrate the form -// -// /** @var ConstraintFactory $constraintFactory */ -// $constraintFactory = $this->container->get('thelia.constraint.factory'); -// -// $data = array( -// 'code' => $coupon->getCode(), -// 'title' => $coupon->getTitle(), -// 'amount' => $coupon->getAmount(), -// 'effect' => $coupon->getType(), -// 'shortDescription' => $coupon->getShortDescription(), -// 'description' => $coupon->getDescription(), -// 'isEnabled' => ($coupon->getIsEnabled() == 1), -// 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()), -// 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1), -// 'isCumulative' => ($coupon->getIsCumulative() == 1), -// 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), -// 'maxUsage' => $coupon->getMaxUsage(), -// 'rules' => $constraintFactory->unserializeCouponRuleCollection($coupon->getSerializedRules()), -// 'locale' => $coupon->getLocale(), -// ); -// -// /** @var CouponAdapterInterface $adapter */ -// $adapter = $this->container->get('thelia.adapter'); -// /** @var Translator $translator */ -// $translator = $this->container->get('thelia.translator'); -// -// $args['rulesObject'] = array(); -// /** @var CouponRuleInterface $rule */ -// foreach ($coupon->getRules()->getRules() as $rule) { -// $args['rulesObject'][] = array( -// 'name' => $rule->getName($translator), -// 'tooltip' => $rule->getToolTip($translator), -// 'validators' => $rule->getValidators() -// ); -// } -// -// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules()); -// -// // Setup the object form -// $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data); -// -// // Pass it to the parser -// $this->getParserContext()->addForm($changeForm); -// } -// -// $args['formAction'] = 'admin/coupon/update/' . $couponId; -// -// return $this->render( -// 'coupon-update', -// $args -// ); -// } - - - - - /** * Manage Coupons read display * @@ -569,7 +473,7 @@ class CouponController extends BaseAdminController /** * Validate the CreateOrUpdate form * - * @param string $i18n Local code (fr_FR) + * @param I18n $i18n Local code (fr_FR) * @param Lang $lang Local variables container * @param string $eventToDispatch Event which will activate actions * @param string $log created|edited @@ -577,7 +481,7 @@ class CouponController extends BaseAdminController * * @return $this */ - protected function validateCreateOrUpdateForm($i18n, $lang, $eventToDispatch, $log, $action) + protected function validateCreateOrUpdateForm(I18n $i18n, Lang $lang, $eventToDispatch, $log, $action) { // Create the form from the request $creationForm = new CouponCreationForm($this->getRequest()); @@ -597,7 +501,7 @@ class CouponController extends BaseAdminController $data['shortDescription'], $data['description'], $data['isEnabled'], - $i18n->getDateTimeFromForm($lang, $data['expirationDate']), + \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 9e41bae4f..1625ab685 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\Date; +use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotEqualTo; diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 7a7ce1e4a..032de412a 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -76,7 +76,6 @@ class Coupon extends BaseCoupon ->setType($effect) ->setAmount($amount) ->setIsRemovingPostage($isRemovingPostage) - ->setType($amount) ->setIsEnabled($isEnabled) ->setExpirationDate($expirationDate) ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 37f8de41f..41e0c1430 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -140,28 +140,21 @@ $(function($){ couponManager.onUsageUnlimitedChange = function() { if (!$('#max-usage').parent().hasClass('has-error')) { $('#max-usage').hide().attr('value', '-1'); + $('#max-usage-label').hide(); } $('#is-unlimited').change(function(){ var $this = $(this); if ($this.is(':checked')) { $('#max-usage').hide().attr('value', '-1'); + $('#max-usage-label').hide(); } else { $('#max-usage').show().val('').attr('value', ''); + $('#max-usage-label').show(); } }); }; 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 @@ -175,4 +168,5 @@ couponManager.ruleToSave.values = {}; // Rules payload to save couponManager.rulesToSave = []; // Rule being updated id -couponManager.ruleToUpdateId = false; \ No newline at end of file +couponManager.ruleToUpdateId = false; + diff --git a/templates/admin/default/coupon-create.html b/templates/admin/default/coupon-create.html index b87b21195..f8a0411e1 100755 --- a/templates/admin/default/coupon-create.html +++ b/templates/admin/default/coupon-create.html @@ -20,7 +20,6 @@ {form name="thelia.admin.coupon.creation"} {include file='coupon/form.html' formAction={url path={$formAction}} noRules=true} {/form} - {include file='includes/confirmation-modal.html'} @@ -42,4 +41,13 @@ {javascripts file='assets/js/coupon.js'} {/javascripts} + + {**} + {**} + + {/block} diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 92b834fe7..a4ec8b14a 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -11,7 +11,7 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field}