WIP
- Coupon Add/Edit/Delete rule AJAX
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -10,103 +10,103 @@
|
||||
{include file="includes/coupon_breadcrumb.html"}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
||||
{loop type="coupon" name="read_coupon" id={$couponId} backend_context="true"}
|
||||
<div class="page-header">
|
||||
<h1>Coupons : <small>Read coupon n°1</small></h1>
|
||||
<h1>{intl l='Coupon : '}<small>#CODE</small></h1>
|
||||
</div>
|
||||
|
||||
|
||||
<section class="row">
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
{loop type="coupon" name="read_coupon" id=1 backend_context="true"}
|
||||
<div class="alert alert-info">
|
||||
<span class="glyphicon glyphicon-question-sign"></span>
|
||||
{if #IS_ENABLED}{else}This coupon is disabled, you can enable to the bottom of this form.{/if}
|
||||
</div>
|
||||
|
||||
<table class="table table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Code</td>
|
||||
<td>#CODE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td>#TITLE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Expiration date</td>
|
||||
<td>EXPIRATION_DATE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Usage left</td>
|
||||
<td>
|
||||
{if #USAGE_LEFT}
|
||||
<span class="label label-success">
|
||||
#USAGE_LEFT
|
||||
</span>
|
||||
{else}
|
||||
<span class="label label-important">
|
||||
0
|
||||
</span>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">#SHORT_DESCRIPTION</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">#DESCRIPTION</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{if #IS_CUMULATIVE}
|
||||
<span class="label label-success">
|
||||
{intl l="May be cumulative"}
|
||||
</span>
|
||||
{else}
|
||||
<span class="label label-important">
|
||||
{intl l="Can't be cumulative"}
|
||||
</span>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{if #IS_REMOVING_POSTAGE}
|
||||
<span class="label label-important">
|
||||
{intl l="Will remove postage"}
|
||||
</span>
|
||||
{else}
|
||||
<div class="alert alert-info">
|
||||
<span class="glyphicon glyphicon-question-sign"></span>
|
||||
{if #IS_ENABLED}{else}{intl l='This coupon is disabled, you can enable to the bottom of this form.'}{/if}
|
||||
</div>
|
||||
|
||||
<table class="table table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{intl l='Title'}</td>
|
||||
<td>#TITLE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{intl l='Expiration date'}</td>
|
||||
<td>#EXPIRATION_DATE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{intl l='Usage left'}</td>
|
||||
<td>
|
||||
{if #USAGE_LEFT}
|
||||
<span class="label label-success">
|
||||
{intl l="Won't remove postage"}
|
||||
#USAGE_LEFT
|
||||
</span>
|
||||
{else}
|
||||
<span class="label label-important">
|
||||
0
|
||||
</span>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">#SHORT_DESCRIPTION</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">#DESCRIPTION</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{if #IS_CUMULATIVE}
|
||||
<span class="label label-success">
|
||||
{intl l="May be cumulative"}
|
||||
</span>
|
||||
{else}
|
||||
<span class="label label-important">
|
||||
{intl l="Can't be cumulative"}
|
||||
</span>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Amount</td>
|
||||
<td>#AMOUNT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Conditions of application</td>
|
||||
<td>
|
||||
<ul class="list-unstyled">
|
||||
<li>Total cart supperior to 400 €</li>
|
||||
<li><span class="label label-info">OR</span></li>
|
||||
<li>At least 4 products</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Actions</td>
|
||||
<td>
|
||||
<a href="#url" class="btn btn-default btn-primary btn-medium"><span class="icon-edit icon-white"></span> Edit</a>
|
||||
<a href="#url" class="btn btn-default btn-success btn-medium" data-toggle="confirm" data-target="#enable"><span class="glyphicon glyphicon-ok"></span> Enabled</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{if #IS_REMOVING_POSTAGE}
|
||||
<span class="label label-important">
|
||||
{intl l="Will remove postage"}
|
||||
</span>
|
||||
{else}
|
||||
<span class="label label-success">
|
||||
{intl l="Won't remove postage"}
|
||||
</span>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{intl l='Amount'}</td>
|
||||
<td>#AMOUNT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{intl l='Application field'}</td>
|
||||
<td>
|
||||
<ul class="list-unstyled">
|
||||
{foreach from=$APPLICATION_CONDITIONS item=rule name=rulesForeach}
|
||||
{if !$smarty.foreach.rulesForeach.first}
|
||||
<li><span class="label label-info">{intl l='And'}</span></li>
|
||||
{/if}
|
||||
<li>{$rule nofilter}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{intl l='Actions'}</td>
|
||||
<td>
|
||||
<a href="#url" class="btn btn-default btn-primary btn-medium"><span class="icon-edit icon-white"></span> {intl l='Edit'}</a>
|
||||
<a href="#url" class="btn btn-default btn-success btn-medium" data-toggle="confirm" data-target="#enable"><span class="glyphicon glyphicon-ok"></span> {intl l='Enabled'}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{/loop}
|
||||
</div>
|
||||
</section>
|
||||
@@ -121,7 +121,4 @@
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
{javascripts file='assets/bootstrap-editable/js/bootstrap-editable.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
{/block}
|
||||
|
||||
@@ -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('<div class="loading" ></div>');
|
||||
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('<div class="loading" ></div>');
|
||||
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();
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -167,9 +167,6 @@
|
||||
<table class="table table-striped">
|
||||
<caption class="clearfix">
|
||||
{intl l='Rules'}
|
||||
<a class="btn btn-default btn-primary pull-right" title="{intl l='Add a new rule'}">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span>
|
||||
</a>
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -178,9 +175,15 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$rulesObject item=rule}
|
||||
{foreach from=$rulesObject item=rule name=rulesForeach}
|
||||
<tr>
|
||||
<td>{$rule.tooltip}</td>
|
||||
<td>
|
||||
{if !$smarty.foreach.rulesForeach.first}
|
||||
<span class="label label-info">{intl l='And'}</span>
|
||||
{/if}
|
||||
{$rule.tooltip nofilter}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<a href="#url" class="btn btn-default btn-primary btn-medium"><span class="glyphicon glyphicon-edit"></span> {intl l='Edit'}</a>
|
||||
<a href="#url" class="btn btn-default btn-danger btn-medium" data-toggle="confirm" data-target="#delete"><span class="glyphicon glyphicon-remove"></span> {intl l='Delete'}</a>
|
||||
@@ -194,9 +197,32 @@
|
||||
|
||||
<section class="row">
|
||||
<div class="col-md-12 general-block-decorator clearfix">
|
||||
<a title="{intl l='Save this rule'}" class="btn btn-default btn-primary pull-right">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span>
|
||||
</a>
|
||||
<table class="table table-striped">
|
||||
<caption class="clearfix">
|
||||
{intl l='Add a Rule'}
|
||||
<a title="{intl l='Save this rule'}" class="btn btn-default btn-primary pull-right">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span>
|
||||
</a>
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l='Conditions link'}</th>
|
||||
<th>{intl l='Rule Type'}</th>
|
||||
<th>{intl l='Operator'}</th>
|
||||
<th>{intl l='Value'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td></tr>
|
||||
<td></tr>
|
||||
<td></tr>
|
||||
<td></tr>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<div id="rule-add-organizer" class="form-group col-md-2">
|
||||
<label for="type">{intl l='Condition type :'}</label>
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{*test*}
|
||||
{*{$ruleId}*}
|
||||
{*{$inputs|var_dump}*}
|
||||
|
||||
{foreach from=$inputs key=name item=input}
|
||||
{foreach from=$inputs.inputs key=name item=input}
|
||||
<label for="operator">{$input.title}</label>
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
@@ -71,4 +67,15 @@
|
||||
{*</tr>*}
|
||||
{*</tbody></table>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
|
||||
<script>
|
||||
var ruleToSave = [];
|
||||
ruleToSave['serviceId'] = '{$ruleId}';
|
||||
ruleToSave['operators'] = [];
|
||||
ruleToSave['values'] = [];
|
||||
{foreach from=$inputs.inputs key=name item=input}
|
||||
ruleToSave['operators']['{$name nofilter}'] = 'to set';
|
||||
ruleToSave['values']['{$name nofilter}'] = 'to set';
|
||||
{/foreach}
|
||||
</script>
|
||||
Reference in New Issue
Block a user