Working : coupon creation : add default rule (thelia.constraint.rule.available_for_everyone)
This commit is contained in:
@@ -32,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents;
|
|||||||
use Thelia\Core\HttpFoundation\Request;
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
use Thelia\Coupon\CouponFactory;
|
use Thelia\Coupon\CouponFactory;
|
||||||
use Thelia\Coupon\CouponManager;
|
use Thelia\Coupon\CouponManager;
|
||||||
|
use Thelia\Coupon\CouponRuleCollection;
|
||||||
use Thelia\Coupon\Type\CouponInterface;
|
use Thelia\Coupon\Type\CouponInterface;
|
||||||
use Thelia\Model\Coupon as CouponModel;
|
use Thelia\Model\Coupon as CouponModel;
|
||||||
|
|
||||||
@@ -137,11 +138,21 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
$coupon->setDispatcher($this->getDispatcher());
|
$coupon->setDispatcher($this->getDispatcher());
|
||||||
|
|
||||||
|
// Set default rule if none found
|
||||||
|
$noConditionRule = $this->container->get('thelia.constraint.rule.available_for_everyone');
|
||||||
|
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||||
|
$couponRuleCollection = new CouponRuleCollection();
|
||||||
|
$couponRuleCollection->add($noConditionRule);
|
||||||
|
$defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection(
|
||||||
|
$couponRuleCollection
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
$coupon->createOrUpdate(
|
$coupon->createOrUpdate(
|
||||||
$event->getCode(),
|
$event->getCode(),
|
||||||
$event->getTitle(),
|
$event->getTitle(),
|
||||||
$event->getAmount(),
|
$event->getAmount(),
|
||||||
$event->getEffect(),
|
$event->getType(),
|
||||||
$event->isRemovingPostage(),
|
$event->isRemovingPostage(),
|
||||||
$event->getShortDescription(),
|
$event->getShortDescription(),
|
||||||
$event->getDescription(),
|
$event->getDescription(),
|
||||||
@@ -150,9 +161,12 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
|||||||
$event->isAvailableOnSpecialOffers(),
|
$event->isAvailableOnSpecialOffers(),
|
||||||
$event->isCumulative(),
|
$event->isCumulative(),
|
||||||
$event->getMaxUsage(),
|
$event->getMaxUsage(),
|
||||||
|
$defaultSerializedRule,
|
||||||
$event->getLocale()
|
$event->getLocale()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$event->setCoupon($coupon);
|
$event->setCoupon($coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
|||||||
// Compute the image URL
|
// Compute the image URL
|
||||||
$processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath));
|
$processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath));
|
||||||
|
|
||||||
// compute the full resulution image path in cache
|
// compute the full resolution image path in cache
|
||||||
$original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache));
|
$original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache));
|
||||||
|
|
||||||
// Update the event with file path and file URL
|
// Update the event with file path and file URL
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ class CouponController extends BaseAdminController
|
|||||||
|
|
||||||
$args['urlReadCoupon'] = $this->getRoute(
|
$args['urlReadCoupon'] = $this->getRoute(
|
||||||
'admin.coupon.read',
|
'admin.coupon.read',
|
||||||
array('couponId' => 'couponId'),
|
array('couponId' => 0),
|
||||||
Router::ABSOLUTE_URL
|
Router::ABSOLUTE_URL
|
||||||
);
|
);
|
||||||
|
|
||||||
$args['urlEditCoupon'] = $this->getRoute(
|
$args['urlEditCoupon'] = $this->getRoute(
|
||||||
'admin.coupon.update',
|
'admin.coupon.update',
|
||||||
array('couponId' => 'couponId'),
|
array('couponId' => 0),
|
||||||
Router::ABSOLUTE_URL
|
Router::ABSOLUTE_URL
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ class CouponController extends BaseAdminController
|
|||||||
|
|
||||||
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
|
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
|
||||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||||
$args['formAction'] = 'admin/coupon/create/';
|
$args['formAction'] = 'admin/coupon/create';
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'coupon-create',
|
'coupon-create',
|
||||||
@@ -223,7 +223,7 @@ class CouponController extends BaseAdminController
|
|||||||
'code' => $coupon->getCode(),
|
'code' => $coupon->getCode(),
|
||||||
'title' => $coupon->getTitle(),
|
'title' => $coupon->getTitle(),
|
||||||
'amount' => $coupon->getAmount(),
|
'amount' => $coupon->getAmount(),
|
||||||
'effect' => $coupon->getType(),
|
'type' => $coupon->getType(),
|
||||||
'shortDescription' => $coupon->getShortDescription(),
|
'shortDescription' => $coupon->getShortDescription(),
|
||||||
'description' => $coupon->getDescription(),
|
'description' => $coupon->getDescription(),
|
||||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||||
@@ -271,7 +271,7 @@ class CouponController extends BaseAdminController
|
|||||||
Router::ABSOLUTE_URL
|
Router::ABSOLUTE_URL
|
||||||
);
|
);
|
||||||
|
|
||||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
$args['formAction'] = 'admin/coupon/update' . $couponId;
|
||||||
|
|
||||||
return $this->render('coupon-update', $args);
|
return $this->render('coupon-update', $args);
|
||||||
}
|
}
|
||||||
@@ -347,20 +347,7 @@ class CouponController extends BaseAdminController
|
|||||||
);
|
);
|
||||||
|
|
||||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||||
$coupon->getCode(),
|
$coupon->getCode(), $coupon->getTitle(), $coupon->getAmount(), $coupon->getType(), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), $coupon->getExpirationDate(), $coupon->getIsAvailableOnSpecialOffers(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getMaxUsage(), $coupon->getLocale()
|
||||||
$coupon->getTitle(),
|
|
||||||
$coupon->getAmount(),
|
|
||||||
$coupon->getType(),
|
|
||||||
$coupon->getShortDescription(),
|
|
||||||
$coupon->getDescription(),
|
|
||||||
$coupon->getIsEnabled(),
|
|
||||||
$coupon->getExpirationDate(),
|
|
||||||
$coupon->getIsAvailableOnSpecialOffers(),
|
|
||||||
$coupon->getIsCumulative(),
|
|
||||||
$coupon->getIsRemovingPostage(),
|
|
||||||
$coupon->getMaxUsage(),
|
|
||||||
$rules,
|
|
||||||
$coupon->getLocale()
|
|
||||||
);
|
);
|
||||||
$couponEvent->setCoupon($coupon);
|
$couponEvent->setCoupon($coupon);
|
||||||
|
|
||||||
@@ -497,20 +484,7 @@ class CouponController extends BaseAdminController
|
|||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||||
$data['code'],
|
$data['code'], $data['title'], $data['amount'], $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale']
|
||||||
$data['title'],
|
|
||||||
$data['amount'],
|
|
||||||
$data['type'],
|
|
||||||
$data['shortDescription'],
|
|
||||||
$data['description'],
|
|
||||||
$data['isEnabled'],
|
|
||||||
\DateTime::createFromFormat('Y-m-d', $data['expirationDate']),
|
|
||||||
$data['isAvailableOnSpecialOffers'],
|
|
||||||
$data['isCumulative'],
|
|
||||||
$data['isRemovingPostage'],
|
|
||||||
$data['maxUsage'],
|
|
||||||
new CouponRuleCollection(array()),
|
|
||||||
$data['locale']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Dispatch Event to the Action
|
// Dispatch Event to the Action
|
||||||
@@ -538,7 +512,6 @@ class CouponController extends BaseAdminController
|
|||||||
} catch (FormValidationException $e) {
|
} catch (FormValidationException $e) {
|
||||||
// Invalid data entered
|
// Invalid data entered
|
||||||
$message = 'Please check your input:';
|
$message = 'Please check your input:';
|
||||||
$this->logError($action, $message, $e);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Any other error
|
// Any other error
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
/** @var Coupon Coupon model */
|
/** @var Coupon Coupon model */
|
||||||
protected $coupon = null;
|
protected $coupon = null;
|
||||||
|
|
||||||
/** @var string Coupon effect */
|
/** @var string Coupon type */
|
||||||
protected $effect;
|
protected $type;
|
||||||
|
|
||||||
/** @var string Language code ISO (ex: fr_FR) */
|
/** @var string Language code ISO (ex: fr_FR) */
|
||||||
protected $locale = null;
|
protected $locale = null;
|
||||||
@@ -87,36 +87,22 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $code Coupon Code
|
* @param string $code Coupon Code
|
||||||
* @param string $title Coupon title
|
* @param string $title Coupon title
|
||||||
* @param float $amount Amount removed from the Total Checkout
|
* @param float $amount Amount removed from the Total Checkout
|
||||||
* @param string $type Coupon type
|
* @param string $type Coupon type
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
* @param string $description Coupon description
|
* @param string $description Coupon description
|
||||||
* @param boolean $isEnabled Enable/Disable
|
* @param boolean $isEnabled Enable/Disable
|
||||||
* @param \DateTime $expirationDate Coupon expiration date
|
* @param \DateTime $expirationDate Coupon expiration date
|
||||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||||
* @param boolean $isCumulative Is cumulative
|
* @param boolean $isCumulative Is cumulative
|
||||||
* @param boolean $isRemovingPostage Is removing Postage
|
* @param boolean $isRemovingPostage Is removing Postage
|
||||||
* @param int $maxUsage Coupon quantity
|
* @param int $maxUsage Coupon quantity
|
||||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$code,
|
$code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
|
||||||
$title,
|
|
||||||
$amount,
|
|
||||||
$type,
|
|
||||||
$shortDescription,
|
|
||||||
$description,
|
|
||||||
$isEnabled,
|
|
||||||
\DateTime $expirationDate,
|
|
||||||
$isAvailableOnSpecialOffers,
|
|
||||||
$isCumulative,
|
|
||||||
$isRemovingPostage,
|
|
||||||
$maxUsage,
|
|
||||||
$rules,
|
|
||||||
$locale
|
|
||||||
) {
|
) {
|
||||||
$this->amount = $amount;
|
$this->amount = $amount;
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
@@ -127,7 +113,6 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
$this->isEnabled = $isEnabled;
|
$this->isEnabled = $isEnabled;
|
||||||
$this->isRemovingPostage = $isRemovingPostage;
|
$this->isRemovingPostage = $isRemovingPostage;
|
||||||
$this->maxUsage = $maxUsage;
|
$this->maxUsage = $maxUsage;
|
||||||
$this->rules = $rules;
|
|
||||||
$this->shortDescription = $shortDescription;
|
$this->shortDescription = $shortDescription;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
@@ -206,22 +191,6 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
return $this->amount;
|
return $this->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return condition to validate the Coupon or not
|
|
||||||
*
|
|
||||||
* @return CouponRuleCollection
|
|
||||||
*/
|
|
||||||
public function getRules()
|
|
||||||
{
|
|
||||||
if ($this->rules === null || !is_object($this->rules)) {
|
|
||||||
$rules = $this->rules;
|
|
||||||
} else {
|
|
||||||
$rules = clone $this->rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Coupon expiration date
|
* Return Coupon expiration date
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -63,11 +63,12 @@ class Coupon extends BaseCoupon
|
|||||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||||
* @param boolean $isCumulative Is cumulative
|
* @param boolean $isCumulative Is cumulative
|
||||||
* @param int $maxUsage Coupon quantity
|
* @param int $maxUsage Coupon quantity
|
||||||
|
* @param string $defaultSerializedRule Serialized default rule added if none found
|
||||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null)
|
function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null)
|
||||||
{
|
{
|
||||||
$this->setCode($code)
|
$this->setCode($code)
|
||||||
->setTitle($title)
|
->setTitle($title)
|
||||||
@@ -82,6 +83,11 @@ class Coupon extends BaseCoupon
|
|||||||
->setIsCumulative($isCumulative)
|
->setIsCumulative($isCumulative)
|
||||||
->setMaxUsage($maxUsage);
|
->setMaxUsage($maxUsage);
|
||||||
|
|
||||||
|
// If no rule given, set default rule
|
||||||
|
if (null === $this->getSerializedRules()) {
|
||||||
|
$this->setSerializedRules($defaultSerializedRule);
|
||||||
|
}
|
||||||
|
|
||||||
// Set object language (i18n)
|
// Set object language (i18n)
|
||||||
if (!is_null($locale)) {
|
if (!is_null($locale)) {
|
||||||
$this->setLocale($locale);
|
$this->setLocale($locale);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@
|
|||||||
|
|
||||||
{loop name="menu-auth-coupon" type="auth" roles="ADMIN" permissions="admin.coupon.view"}
|
{loop name="menu-auth-coupon" type="auth" roles="ADMIN" permissions="admin.coupon.view"}
|
||||||
<li class="{if $admin_current_location == 'coupon'}active{/if}" id="coupon_menu">
|
<li class="{if $admin_current_location == 'coupon'}active{/if}" id="coupon_menu">
|
||||||
<a href="{url path='/admin/coupon/'}">{intl l="Coupons"}</a>
|
<a href="{url path='/admin/coupon'}">{intl l="Coupons"}</a>
|
||||||
</li>
|
</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
$(function($){
|
$(function($){
|
||||||
|
|
||||||
|
// Manage how coupon and rules are saved
|
||||||
|
$.couponManager = {};
|
||||||
|
// Rule to be saved
|
||||||
|
$.couponManager.ruleToSave = {};
|
||||||
|
$.couponManager.ruleToSave.serviceId = false;
|
||||||
|
$.couponManager.ruleToSave.operators = {};
|
||||||
|
$.couponManager.ruleToSave.values = {};
|
||||||
|
// Rules payload to save
|
||||||
|
$.couponManager.rulesToSave = [];
|
||||||
|
// Rule being updated id
|
||||||
|
$.couponManager.ruleToUpdateId = false;
|
||||||
|
|
||||||
// Clean array from deleteValue (undefined) keys
|
// Clean array from deleteValue (undefined) keys
|
||||||
Array.prototype.clean = function(deleteValue) {
|
Array.prototype.clean = function(deleteValue) {
|
||||||
for (var i = 0; i < this.length; i++) {
|
for (var i = 0; i < this.length; i++) {
|
||||||
@@ -12,109 +24,109 @@ $(function($){
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Remove 1 Rule then Save Rules AJAX
|
// Remove 1 Rule then Save Rules AJAX
|
||||||
couponManager.removeRuleAjax = function(id) {
|
$.couponManager.removeRuleAjax = function(id) {
|
||||||
// Delete rule in temporary array
|
// Delete rule in temporary array
|
||||||
delete couponManager.rulesToSave[id];
|
delete $.couponManager.rulesToSave[id];
|
||||||
couponManager.rulesToSave.clean(undefined);
|
$.couponManager.rulesToSave.clean(undefined);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
couponManager.saveRuleAjax();
|
$.couponManager.saveRuleAjax();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add 1 Rule / or update the temporary Rules array then Save Rules via AJAX
|
// Add 1 Rule / or update the temporary Rules array then Save Rules via AJAX
|
||||||
couponManager.createOrUpdateRuleAjax = function() {
|
$.couponManager.createOrUpdateRuleAjax = function() {
|
||||||
var id = couponManager.ruleToUpdateId;
|
var id = $.couponManager.ruleToUpdateId;
|
||||||
// If create
|
// If create
|
||||||
if(!id) {
|
if(!id) {
|
||||||
couponManager.rulesToSave.push(couponManager.ruleToSave);
|
$.couponManager.rulesToSave.push($.couponManager.ruleToSave);
|
||||||
} else { // else update
|
} else { // else update
|
||||||
couponManager.rulesToSave[id] = couponManager.ruleToSave;
|
$.couponManager.rulesToSave[id] = $.couponManager.ruleToSave;
|
||||||
// reset edit mode to off
|
// reset edit mode to off
|
||||||
couponManager.ruleToUpdateId = false;
|
$.couponManager.ruleToUpdateId = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
couponManager.saveRuleAjax();
|
$.couponManager.saveRuleAjax();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set rule inputs to allow editing
|
// Set rule inputs to allow editing
|
||||||
couponManager.updateRuleSelectAjax = function(id) {
|
$.couponManager.updateRuleSelectAjax = function(id) {
|
||||||
couponManager.ruleToUpdateId = id;
|
$.couponManager.ruleToUpdateId = id;
|
||||||
couponManager.ruleToSave = couponManager.rulesToSave[id];
|
$.couponManager.ruleToSave = $.couponManager.rulesToSave[id];
|
||||||
|
|
||||||
// Set the rule selector
|
// Set the rule selector
|
||||||
$("#category-rule option").filter(function() {
|
$("#category-rule option").filter(function() {
|
||||||
return $(this).val() == couponManager.ruleToSave.serviceId;
|
return $(this).val() == $.couponManager.ruleToSave.serviceId;
|
||||||
}).prop('selected', true);
|
}).prop('selected', true);
|
||||||
|
|
||||||
// Force rule input refresh
|
// Force rule input refresh
|
||||||
couponManager.loadRuleInputs(couponManager.ruleToSave.serviceId, function() {
|
$.couponManager.loadRuleInputs($.couponManager.ruleToSave.serviceId, function() {
|
||||||
couponManager.fillInRuleInputs();
|
$.couponManager.fillInRuleInputs();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fill in rule inputs
|
// Fill in rule inputs
|
||||||
couponManager.fillInRuleInputs = function() {
|
$.couponManager.fillInRuleInputs = function() {
|
||||||
var operatorId = null;
|
var operatorId = null;
|
||||||
var valueId = null;
|
var valueId = null;
|
||||||
var idName = null;
|
var idName = null;
|
||||||
|
|
||||||
var id = couponManager.ruleToUpdateId;
|
var id = $.couponManager.ruleToUpdateId;
|
||||||
if(id) {
|
if(id) {
|
||||||
couponManager.ruleToSave = couponManager.rulesToSave[id];
|
$.couponManager.ruleToSave = $.couponManager.rulesToSave[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (idName in couponManager.ruleToSave.operators) {
|
for (idName in $.couponManager.ruleToSave.operators) {
|
||||||
// Setting idName operator select
|
// Setting idName operator select
|
||||||
operatorId = idName + '-operator';
|
operatorId = idName + '-operator';
|
||||||
$('#' + operatorId).val(couponManager.ruleToSave.operators[idName]);
|
$('#' + operatorId).val($.couponManager.ruleToSave.operators[idName]);
|
||||||
|
|
||||||
// Setting idName value input
|
// Setting idName value input
|
||||||
valueId = idName + '-value';
|
valueId = idName + '-value';
|
||||||
$('#' + valueId).val(couponManager.ruleToSave.values[idName]);
|
$('#' + valueId).val($.couponManager.ruleToSave.values[idName]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save rules on click
|
// Save rules on click
|
||||||
couponManager.onClickSaveRule = function() {
|
$.couponManager.onClickSaveRule = function() {
|
||||||
$('#constraint-save-btn').on('click', function () {
|
$('#constraint-save-btn').on('click', function () {
|
||||||
if($('#category-rule').val() == 'thelia.constraint.rule.available_for_everyone') {
|
if($('#category-rule').val() == 'thelia.constraint.rule.available_for_everyone') {
|
||||||
// @todo translate + modal
|
// @todo translate + modal
|
||||||
var r= confirm("Do you really want to set this coupon available to everyone ?");
|
var r= confirm("Do you really want to set this coupon available to everyone ?");
|
||||||
if (r == true) {
|
if (r == true) {
|
||||||
couponManager.createOrUpdateRuleAjax();
|
$.couponManager.createOrUpdateRuleAjax();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onClickSaveRule();
|
$.couponManager.onClickSaveRule();
|
||||||
|
|
||||||
// Remove rule on click
|
// Remove rule on click
|
||||||
couponManager.onClickDeleteRule = function() {
|
$.couponManager.onClickDeleteRule = function() {
|
||||||
$('.constraint-delete-btn').on('click', function (e) {
|
$('.constraint-delete-btn').on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
couponManager.removeRuleAjax($this.attr('data-int'));
|
$.couponManager.removeRuleAjax($this.attr('data-int'));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onClickDeleteRule();
|
$.couponManager.onClickDeleteRule();
|
||||||
|
|
||||||
// Update rule on click
|
// Update rule on click
|
||||||
couponManager.onClickUpdateRule = function() {
|
$.couponManager.onClickUpdateRule = function() {
|
||||||
$('.constraint-update-btn').on('click', function (e) {
|
$('.constraint-update-btn').on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
couponManager.updateRuleSelectAjax($this.attr('data-int'));
|
$.couponManager.updateRuleSelectAjax($this.attr('data-int'));
|
||||||
|
|
||||||
// Hide row being updated
|
// Hide row being updated
|
||||||
$this.parent().parent().remove();
|
$this.parent().parent().remove();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onClickUpdateRule();
|
$.couponManager.onClickUpdateRule();
|
||||||
|
|
||||||
// Reload effect inputs when changing effect
|
// Reload effect inputs when changing effect
|
||||||
couponManager.onEffectChange = function() {
|
$.couponManager.onEffectChange = function() {
|
||||||
var optionSelected = $("option:selected", this);
|
var optionSelected = $("option:selected", this);
|
||||||
$('#effectToolTip').html(optionSelected.attr("data-description"));
|
$('#effectToolTip').html(optionSelected.attr("data-description"));
|
||||||
$('#effect').on('change', function () {
|
$('#effect').on('change', function () {
|
||||||
@@ -122,22 +134,22 @@ $(function($){
|
|||||||
$('#effectToolTip').html(optionSelected.attr("data-description"));
|
$('#effectToolTip').html(optionSelected.attr("data-description"));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onEffectChange();
|
$.couponManager.onEffectChange();
|
||||||
|
|
||||||
// Reload rule inputs when changing effect
|
// Reload rule inputs when changing effect
|
||||||
couponManager.onRuleChange = function() {
|
$.couponManager.onRuleChange = function() {
|
||||||
$('#category-rule').on('change', function () {
|
$('#category-rule').on('change', function () {
|
||||||
couponManager.loadRuleInputs($(this).val(), function() {});
|
$.couponManager.loadRuleInputs($(this).val(), function() {});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onRuleChange();
|
$.couponManager.onRuleChange();
|
||||||
|
|
||||||
// Fill in ready to be saved rule array
|
// Fill in ready to be saved rule array
|
||||||
// var onInputsChange = function()
|
// var onInputsChange = function()
|
||||||
// In AJAX response
|
// In AJAX response
|
||||||
|
|
||||||
// Set max usage to unlimited or not
|
// Set max usage to unlimited or not
|
||||||
couponManager.onUsageUnlimitedChange = function() {
|
$.couponManager.onUsageUnlimitedChange = function() {
|
||||||
var isUnlimited = $('#is-unlimited');
|
var isUnlimited = $('#is-unlimited');
|
||||||
if ($('#max-usage').val() == -1) {
|
if ($('#max-usage').val() == -1) {
|
||||||
isUnlimited.prop('checked', true);
|
isUnlimited.prop('checked', true);
|
||||||
@@ -160,20 +172,9 @@ $(function($){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
couponManager.onUsageUnlimitedChange();
|
$.couponManager.onUsageUnlimitedChange();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rule to save
|
|
||||||
|
|
||||||
var couponManager = {};
|
|
||||||
// Rule to be saved
|
|
||||||
couponManager.ruleToSave = {};
|
|
||||||
couponManager.ruleToSave.serviceId = false;
|
|
||||||
couponManager.ruleToSave.operators = {};
|
|
||||||
couponManager.ruleToSave.values = {};
|
|
||||||
// Rules payload to save
|
|
||||||
couponManager.rulesToSave = [];
|
|
||||||
// Rule being updated id
|
|
||||||
couponManager.ruleToUpdateId = false;
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
||||||
<li><a href="{url path='admin/coupon/'}">{intl l='Coupon'}</a></li>
|
<li><a href="{url path='admin/coupon'}">{intl l='Coupon'}</a></li>
|
||||||
<li>{intl l='Create'}</li>
|
<li>{intl l='Create'}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
||||||
<li><a href="{url path='admin/coupon/'}">{intl l='Coupon'}</a></li>
|
<li><a href="{url path='admin/coupon'}">{intl l='Coupon'}</a></li>
|
||||||
<li>{intl l='Browse'}</li>
|
<li>{intl l='Browse'}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -39,13 +39,29 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{loop type="coupon" name="list_coupon" is_enabled="1" backend_context="true"}
|
{loop type="coupon" name="list_coupon" is_enabled="1" backend_context="true"}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{block name="coupon-code"}<a href="{$urlReadCoupon|replace:'couponId':$ID}">{$CODE}</a>{/block}</td>
|
<td>{block name="coupon-code"}<a href="{$urlReadCoupon|replace:'0':$ID}">{$CODE}</a>{/block}</td>
|
||||||
<td>{block name="coupon-title"}{$TITLE}{/block}</td>
|
<td>{block name="coupon-title"}{$TITLE}{/block}</td>
|
||||||
<td>{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}</td>
|
<td>{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}</td>
|
||||||
<td>{block name="coupon-usage-left"}{$USAGE_LEFT}{/block}</td>
|
<td>
|
||||||
|
{block name="coupon-usage-left"}
|
||||||
|
{if $USAGE_LEFT == -1}
|
||||||
|
<span class="label label-success">
|
||||||
|
{intl l="Unlimited"}
|
||||||
|
</span>
|
||||||
|
{elseif $USAGE_LEFT}
|
||||||
|
<span class="label label-success">
|
||||||
|
{$USAGE_LEFT}
|
||||||
|
</span>
|
||||||
|
{else}
|
||||||
|
<span class="label label-warning">
|
||||||
|
0
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{/block}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{block name="coupon-action"}
|
{block name="coupon-action"}
|
||||||
<a href="{$urlEditCoupon|replace:'couponId':$ID}" class="btn btn-default btn-primary btn-medium">
|
<a href="{$urlEditCoupon|replace:'0':$ID}" class="btn btn-default btn-primary btn-medium">
|
||||||
<span class="glyphicon glyphicon-edit"></span> {intl l='Edit'}
|
<span class="glyphicon glyphicon-edit"></span> {intl l='Edit'}
|
||||||
</a>
|
</a>
|
||||||
{/block}
|
{/block}
|
||||||
@@ -80,7 +96,23 @@
|
|||||||
<td>{block name="coupon-code"}<a href="{$urlReadCoupon|replace:'couponId':$ID}">{$CODE}</a>{/block}</td>
|
<td>{block name="coupon-code"}<a href="{$urlReadCoupon|replace:'couponId':$ID}">{$CODE}</a>{/block}</td>
|
||||||
<td>{block name="coupon-title"}{$TITLE}{/block}</td>
|
<td>{block name="coupon-title"}{$TITLE}{/block}</td>
|
||||||
<td>{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}</td>
|
<td>{block name="coupon-expiration-date"}{$EXPIRATION_DATE}{/block}</td>
|
||||||
<td>{block name="coupon-usage-left"}{$USAGE_LEFT}{/block}</td>
|
<td>
|
||||||
|
{block name="coupon-usage-left"}
|
||||||
|
{if $USAGE_LEFT == -1}
|
||||||
|
<span class="label label-success">
|
||||||
|
{intl l="Unlimited"}
|
||||||
|
</span>
|
||||||
|
{elseif $USAGE_LEFT}
|
||||||
|
<span class="label label-success">
|
||||||
|
{$USAGE_LEFT}
|
||||||
|
</span>
|
||||||
|
{else}
|
||||||
|
<span class="label label-warning">
|
||||||
|
0
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
{/block}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{block name="coupon-action"}
|
{block name="coupon-action"}
|
||||||
<a href="{$urlEditCoupon|replace:'couponId':$ID}" class="btn btn-default btn-primary btn-medium">
|
<a href="{$urlEditCoupon|replace:'couponId':$ID}" class="btn btn-default btn-primary btn-medium">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
||||||
<li><a href="{url path='admin/coupon/'}">{intl l='Coupon'}</a></li>
|
<li><a href="{url path='admin/coupon'}">{intl l='Coupon'}</a></li>
|
||||||
<li>{$CODE}</li>
|
<li>{$CODE}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -64,7 +64,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{intl l='Usage left'}</td>
|
<td>{intl l='Usage left'}</td>
|
||||||
<td>
|
<td>
|
||||||
{if $USAGE_LEFT}
|
{if $USAGE_LEFT == -1}
|
||||||
|
<span class="label label-success">
|
||||||
|
{intl l="Unlimited"}
|
||||||
|
</span>
|
||||||
|
{elseif $USAGE_LEFT}
|
||||||
<span class="label label-success">
|
<span class="label label-success">
|
||||||
{$USAGE_LEFT}
|
{$USAGE_LEFT}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
<li><a href="{url path='admin/home'}">{intl l='Home'}</a></li>
|
||||||
<li><a href="{url path='admin/coupon/'}">{intl l='Coupon'}</a></li>
|
<li><a href="{url path='admin/coupon'}">{intl l='Coupon'}</a></li>
|
||||||
<li>{intl l='Update'} {$couponCode}</li>
|
<li>{intl l='Update'} {$couponCode}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
||||||
|
|
||||||
// Init Rules
|
// Init Rules
|
||||||
couponManager.initRules = function() {
|
$.couponManager.initRules = function() {
|
||||||
var rules = [];
|
var rules = [];
|
||||||
{foreach from=$rulesObject key=k item=rule}
|
{foreach from=$rulesObject key=k item=rule}
|
||||||
// Init rule
|
// Init rule
|
||||||
@@ -70,13 +70,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Save Rules AJAX
|
// Save Rules AJAX
|
||||||
couponManager.saveRuleAjax = function() {
|
$.couponManager.saveRuleAjax = function() {
|
||||||
$('#constraint-add-operators-values').html('<div class="loading" ></div>');
|
$('#constraint-add-operators-values').html('<div class="loading" ></div>');
|
||||||
var $url = '{$urlAjaxUpdateRules}';
|
var $url = '{$urlAjaxUpdateRules}';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: $url,
|
url: $url,
|
||||||
data: {literal}{{/literal}rules:JSON.stringify(couponManager.rulesToSave){literal}}{/literal},
|
data: {literal}{{/literal}rules:JSON.stringify($.couponManager.rulesToSave){literal}}{/literal},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
404: function() {
|
404: function() {
|
||||||
$('#constraint-add-operators-values').html(
|
$('#constraint-add-operators-values').html(
|
||||||
@@ -92,13 +92,13 @@
|
|||||||
return $(this).val() == 'thelia.constraint.rule.available_for_everyone';
|
return $(this).val() == 'thelia.constraint.rule.available_for_everyone';
|
||||||
}).prop('selected', true);
|
}).prop('selected', true);
|
||||||
|
|
||||||
couponManager.onClickUpdateRule();
|
$.couponManager.onClickUpdateRule();
|
||||||
couponManager.onClickDeleteRule();
|
$.couponManager.onClickDeleteRule();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reload rule inputs
|
// Reload rule inputs
|
||||||
couponManager.loadRuleInputs = function(ruleId, callBack) {
|
$.couponManager.loadRuleInputs = function(ruleId, callBack) {
|
||||||
$('#constraint-add-operators-values').html('<div class="loading" ></div>');
|
$('#constraint-add-operators-values').html('<div class="loading" ></div>');
|
||||||
var url = "{$urlAjaxGetRuleInput}";
|
var url = "{$urlAjaxGetRuleInput}";
|
||||||
url = url.replace('ruleId', ruleId)
|
url = url.replace('ruleId', ruleId)
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
}
|
}
|
||||||
}).done(function(data) {
|
}).done(function(data) {
|
||||||
$('#constraint-add-operators-values').html(data);
|
$('#constraint-add-operators-values').html(data);
|
||||||
couponManager.ruleToSave.serviceId = ruleId;
|
$.couponManager.ruleToSave.serviceId = ruleId;
|
||||||
if (ruleId == -1) {
|
if (ruleId == -1) {
|
||||||
// Placeholder can't be saved
|
// Placeholder can't be saved
|
||||||
$('#constraint-save-btn').hide();
|
$('#constraint-save-btn').hide();
|
||||||
@@ -125,7 +125,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Rules which will be saved
|
// Rules which will be saved
|
||||||
couponManager.rulesToSave = couponManager.initRules();
|
$.couponManager.rulesToSave = $.couponManager.initRules();
|
||||||
|
|
||||||
$('#constraint-save-btn').hide();
|
$('#constraint-save-btn').hide();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='success_url'}
|
{form_field form=$form field='success_url'}
|
||||||
<input type="hidden" name="{$name}" value="{url path='/admin/coupon/update/{id}/'}" />
|
<input type="hidden" name="{$name}" value="{url path='/admin/coupon/update/{id}'}" />
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
<div class="span4">
|
<div class="span4">
|
||||||
@@ -104,10 +104,10 @@
|
|||||||
{form_field form=$form field='type'}
|
{form_field form=$form field='type'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="type" class="control-label">{intl l='Type :'}</label>
|
<label for="type" class="control-label">{intl l='Type :'}</label>
|
||||||
<select name="{$name}" value="{$value}" id="type" class="col-md-12 form-control">
|
<select name="{$name}" id="type" class="col-md-12 form-control">
|
||||||
<option value="-1" data-description="">{intl l='Please select an type'}</option>
|
<option value="-1" data-description="">{intl l='Please select a coupon type'}</option>
|
||||||
{foreach from=$availableCoupons item=availableCoupon}
|
{foreach from=$availableCoupons item=availableCoupon}
|
||||||
<option value="{$availableCoupon.serviceId}" data-description="{$availableCoupon.toolTip}" {if $value == $availableCoupon.serviceId}selected="selected"{/if}>
|
<option value="{$availableCoupon.serviceId}" data-description="{$availableCoupon.toolTip}" {if $value == $availableCoupon.serviceId}selected{/if}>
|
||||||
{$availableCoupon.name}
|
{$availableCoupon.name}
|
||||||
</option>
|
</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
@@ -285,4 +285,3 @@
|
|||||||
</section>
|
</section>
|
||||||
{/if}
|
{/if}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user