diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php index 868db4dd7..1cab6c48b 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php @@ -203,8 +203,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface $validator['availableOperators'] = $translatedOperators; $translatedInputs[$key] = $validator; } + $validators = array(); + $validators['inputs'] = $translatedInputs; + $validators['setOperators'] = $this->operators; + $validators['setValues'] = $this->values; - return $translatedInputs; + return $validators; } /** diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index d2368a573..dd2bfe54d 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -184,8 +184,9 @@ class CouponController extends BaseAdminController ); /** @var CouponRuleInterface $rule */ - foreach ($rules as $rule) { + foreach ($rules->getRules() as $rule) { $args['rulesObject'][] = array( + 'serviceId' => $rule->getServiceId(), 'name' => $rule->getName(), 'tooltip' => $rule->getToolTip(), 'validators' => $rule->getValidators() @@ -338,15 +339,15 @@ class CouponController extends BaseAdminController { $this->checkAuth('ADMIN', 'admin.coupon.read'); - if (!$this->getRequest()->isXmlHttpRequest()) { - $this->redirect( - $this->getRoute( - 'admin', - array(), - Router::ABSOLUTE_URL - ) - ); - } +// if (!$this->getRequest()->isXmlHttpRequest()) { +// $this->redirect( +// $this->getRoute( +// 'admin', +// array(), +// Router::ABSOLUTE_URL +// ) +// ); +// } /** @var ConstraintFactory $constraintFactory */ $constraintFactory = $this->container->get('thelia.constraint.factory'); diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index ee3cc0a5a..9b3ebb615 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -24,6 +24,9 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Constraint\ConstraintFactory; +use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; @@ -84,10 +87,27 @@ class Coupon extends BaseI18nLoop $coupons = $this->search($search, $pagination); $loopResult = new LoopResult(); + /** @var ConstraintFactory $constraintFactory */ + $constraintFactory = $this->container->get('thelia.constraint.factory'); + + /** @var Request $request */ + $request = $this->container->get('request'); + /** @var Lang $lang */ + $lang = $request->getSession()->getLang(); + /** @var MCoupon $coupon */ foreach ($coupons as $coupon) { $loopResultRow = new LoopResultRow(); + $rules = $constraintFactory->unserializeCouponRuleCollection( + $coupon->getSerializedRules() + ); + + $cleanedRules = array(); + /** @var CouponRuleInterface $rule */ + foreach ($rules->getRules() as $key => $rule) { + $cleanedRules[] = $rule->getToolTip(); + } $loopResultRow->set("ID", $coupon->getId()) ->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED')) ->set("LOCALE", $locale) @@ -95,13 +115,13 @@ class Coupon extends BaseI18nLoop ->set("TITLE", $coupon->getVirtualColumn('i18n_TITLE')) ->set("SHORT_DESCRIPTION", $coupon->getVirtualColumn('i18n_SHORT_DESCRIPTION')) ->set("DESCRIPTION", $coupon->getVirtualColumn('i18n_DESCRIPTION')) - ->set("EXPIRATION_DATE", $coupon->getExpirationDate()) + ->set("EXPIRATION_DATE", $coupon->getExpirationDate($lang->getDateFormat())) ->set("USAGE_LEFT", $coupon->getMaxUsage()) ->set("IS_CUMULATIVE", $coupon->getIsCumulative()) ->set("IS_REMOVING_POSTAGE", $coupon->getIsRemovingPostage()) ->set("IS_ENABLED", $coupon->getIsEnabled()) ->set("AMOUNT", $coupon->getAmount()) - ->set("APPLICATION_CONDITIONS", $coupon->getRules()); + ->set("APPLICATION_CONDITIONS", $cleanedRules); $loopResult->addRow($loopResultRow); } diff --git a/install/faker.php b/install/faker.php index 04495a15e..5bb21d4fa 100755 --- a/install/faker.php +++ b/install/faker.php @@ -556,6 +556,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon1->setSerializedRules($serializedRules); + $coupon1->setMaxUsage(40); $coupon1->setIsCumulative(1); $coupon1->setIsRemovingPostage(0); $coupon1->save(); @@ -606,6 +607,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); $coupon2->setSerializedRules($serializedRules); + $coupon1->setMaxUsage(-1); $coupon2->setIsCumulative(0); $coupon2->setIsRemovingPostage(1); $coupon2->save(); diff --git a/templates/admin/default/coupon-read.html b/templates/admin/default/coupon-read.html index f187df7a0..3c2d4bff1 100755 --- a/templates/admin/default/coupon-read.html +++ b/templates/admin/default/coupon-read.html @@ -10,103 +10,103 @@ {include file="includes/coupon_breadcrumb.html"} - + + {loop type="coupon" name="read_coupon" id={$couponId} backend_context="true"}
- {loop type="coupon" name="read_coupon" id=1 backend_context="true"} -
- - {if #IS_ENABLED}{else}This coupon is disabled, you can enable to the bottom of this form.{/if} -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
Code#CODE
Title#TITLE
Expiration dateEXPIRATION_DATE
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} +
+ + {if #IS_ENABLED}{else}{intl l='This coupon is disabled, you can enable to the bottom of this form.'}{/if} +
+ + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - -
{intl l='Title'}#TITLE
{intl l='Expiration date'}#EXPIRATION_DATE
{intl l='Usage left'} + {if #USAGE_LEFT} - {intl l="Won't remove postage"} + #USAGE_LEFT + + {else} + + 0 + + {/if} +
#SHORT_DESCRIPTION
#DESCRIPTION
+ {if #IS_CUMULATIVE} + + {intl l="May be cumulative"} + + {else} + + {intl l="Can't be cumulative"} {/if} -
Amount#AMOUNT
Conditions of application -
    -
  • Total cart supperior to 400 €
  • -
  • OR
  • -
  • At least 4 products
  • -
-
Actions - Edit - Enabled -
+
+ {if #IS_REMOVING_POSTAGE} + + {intl l="Will remove postage"} + + {else} + + {intl l="Won't remove postage"} + + {/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'} + {intl l='Enabled'} +
{/loop}
@@ -121,7 +121,4 @@ {/javascripts} - {javascripts file='assets/bootstrap-editable/js/bootstrap-editable.js'} - - {/javascripts} {/block} diff --git a/templates/admin/default/coupon-update.html b/templates/admin/default/coupon-update.html index 425d9a7ac..9a69ee8a0 100755 --- a/templates/admin/default/coupon-update.html +++ b/templates/admin/default/coupon-update.html @@ -37,29 +37,86 @@ $(function($){ miniBrowser(0, '/test_to_remove/datas_coupon_edit.json'); - $('#effect').on('change', function (e) { - var optionSelected = $("option:selected", this); - $('#effectToolTip').html(optionSelected.attr("data-description")); - }); - $('#category-rule').on('change', function (e) { - $('#rule-add-operators-values').html('
'); - var url = "{$urlAjaxGetRuleInput}"; - url = url.replace('ruleId', $(this).val()) - console.log(url); - $.ajax({ - url: url, - statusCode: { - 404: function() { - $('#rule-add-operators-values').html( - '{intl l='Please select another rule'}' - ); - } - } - }).done(function(data) { - $('#rule-add-operators-values').html(data); + + + + + // Init Rules + var initRule = function() { + var rules = []; + {foreach from=$rulesObject key=k item=rule} + var rule = []; + rule['serviceId'] = '{$rule.serviceId nofilter}'; + rule['operators'] = []; + rule['values'] = []; + + {foreach from=$rule.validators.setOperators key=input item=operator} + rule['operators']['{$input nofilter}'] = '{$operator nofilter}'; + rule['values']['{$input nofilter}'] = '{$rule.validators.setValues[$input] nofilter}'; + {/foreach} + rules.push(rule); + {/foreach} + + return rules; + } + + // Save Rules AJAX + var saveRuleAjax = function() { + console.log(rules); + console.log('save'); + } + + // Remove 1 Rule then Save Rules AJAX + var removeRuleAjax = function($id) { + rules.slice($id, 1); + saveRuleAjax(); + } + + // Add 1 Rule then Save Rules AJAX + var addRuleAjax = function() { + rules.pop(ruleToSave); + saveRuleAjax(); + } + + + var rules = initRule(); + console.log(rules); + + + // Reload effect inputs when changing effect + var onEffectChange = function() { + $('#effect').on('change', function (e) { + var optionSelected = $("option:selected", this); + $('#effectToolTip').html(optionSelected.attr("data-description")); }); - }); + } + onEffectChange(); + + // Reload rule inputs when changing effect + var onRuleChange = function() { + $('#category-rule').on('change', function (e) { + $('#rule-add-operators-values').html('
'); + var url = "{$urlAjaxGetRuleInput}"; + url = url.replace('ruleId', $(this).val()) + console.log(url); + $.ajax({ + url: url, + statusCode: { + 404: function() { + $('#rule-add-operators-values').html( + '{intl l='Please select another rule'}' + ); + } + } + }).done(function(data) { + $('#rule-add-operators-values').html(data); + }); + }); + } + onRuleChange(); + + }); diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index b092e30b1..8ebd64ec1 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -167,9 +167,6 @@ @@ -178,9 +175,15 @@ - {foreach from=$rulesObject item=rule} + {foreach from=$rulesObject item=rule name=rulesForeach} - + + *} {*
{intl l='Rules'} - - -
{$rule.tooltip} + {if !$smarty.foreach.rulesForeach.first} + {intl l='And'} + {/if} + {$rule.tooltip nofilter} + {intl l='Edit'} {intl l='Delete'} @@ -194,9 +197,32 @@
- - - + + + + + + + + + + + + + + + + + + +
+ {intl l='Add a Rule'} + + + +
{intl l='Conditions link'}{intl l='Rule Type'}{intl l='Operator'}{intl l='Value'}
+ +
diff --git a/templates/admin/default/coupon/rule-input-ajax.html b/templates/admin/default/coupon/rule-input-ajax.html index 4e7ab4533..1d4502a1c 100644 --- a/templates/admin/default/coupon/rule-input-ajax.html +++ b/templates/admin/default/coupon/rule-input-ajax.html @@ -1,8 +1,4 @@ -{*test*} -{*{$ruleId}*} -{*{$inputs|var_dump}*} - -{foreach from=$inputs key=name item=input} +{foreach from=$inputs.inputs key=name item=input}
@@ -71,4 +67,15 @@ {*
*} {**} - {**} \ No newline at end of file + {**} + + \ No newline at end of file