WIP : Coupon : Fix condition selection JS + Dependency Injection register
This commit is contained in:
@@ -208,10 +208,7 @@ class CouponController extends BaseAdminController
|
|||||||
$conditions = $conditionFactory->unserializeConditionCollection(
|
$conditions = $conditionFactory->unserializeConditionCollection(
|
||||||
$coupon->getSerializedConditions()
|
$coupon->getSerializedConditions()
|
||||||
);
|
);
|
||||||
var_dump($coupon->getIsEnabled());;
|
|
||||||
var_dump($coupon->getIsAvailableOnSpecialOffers());;
|
|
||||||
var_dump($coupon->getIsCumulative());;
|
|
||||||
var_dump($coupon->getIsRemovingPostage());;
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'code' => $coupon->getCode(),
|
'code' => $coupon->getCode(),
|
||||||
'title' => $coupon->getTitle(),
|
'title' => $coupon->getTitle(),
|
||||||
@@ -219,11 +216,11 @@ var_dump($coupon->getIsRemovingPostage());;
|
|||||||
'type' => $coupon->getType(),
|
'type' => $coupon->getType(),
|
||||||
'shortDescription' => $coupon->getShortDescription(),
|
'shortDescription' => $coupon->getShortDescription(),
|
||||||
'description' => $coupon->getDescription(),
|
'description' => $coupon->getDescription(),
|
||||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
'isEnabled' => $coupon->getIsEnabled(),
|
||||||
'expirationDate' => $coupon->getExpirationDate('Y-m-d'),
|
'expirationDate' => $coupon->getExpirationDate('Y-m-d'),
|
||||||
'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
|
'isAvailableOnSpecialOffers' => $coupon->getIsAvailableOnSpecialOffers(),
|
||||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
'isCumulative' => $coupon->getIsCumulative(),
|
||||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
'isRemovingPostage' => $coupon->getIsRemovingPostage(),
|
||||||
'maxUsage' => $coupon->getMaxUsage(),
|
'maxUsage' => $coupon->getMaxUsage(),
|
||||||
'conditions' => $conditions,
|
'conditions' => $conditions,
|
||||||
'locale' => $coupon->getLocale(),
|
'locale' => $coupon->getLocale(),
|
||||||
@@ -264,7 +261,7 @@ var_dump($coupon->getIsRemovingPostage());;
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use Thelia\Core\DependencyInjection\Compiler\RegisterCouponPass;
|
|||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
|
||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
|
||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterRulePass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterCouponConditionPass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First Bundle use in Thelia
|
* First Bundle use in Thelia
|
||||||
@@ -63,8 +63,6 @@ class TheliaBundle extends Bundle
|
|||||||
->addCompilerPass(new RegisterParserPluginPass())
|
->addCompilerPass(new RegisterParserPluginPass())
|
||||||
->addCompilerPass(new RegisterRouterPass())
|
->addCompilerPass(new RegisterRouterPass())
|
||||||
->addCompilerPass(new RegisterCouponPass())
|
->addCompilerPass(new RegisterCouponPass())
|
||||||
->addCompilerPass(new RegisterRulePass())
|
->addCompilerPass(new RegisterCouponConditionPass());
|
||||||
;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,13 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||||||
* Class RegisterListenersPass
|
* Class RegisterListenersPass
|
||||||
* Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class
|
* Source code come from Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass class
|
||||||
*
|
*
|
||||||
|
* Register all available Conditions for the coupon module
|
||||||
|
*
|
||||||
* @package Thelia\Core\DependencyInjection\Compiler
|
* @package Thelia\Core\DependencyInjection\Compiler
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class RegisterRulePass implements CompilerPassInterface
|
class RegisterCouponConditionPass implements CompilerPassInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* You can modify the container here before it is dumped to PHP code.
|
* You can modify the container here before it is dumped to PHP code.
|
||||||
@@ -55,11 +57,11 @@ class RegisterRulePass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$couponManager = $container->getDefinition('thelia.coupon.manager');
|
$couponManager = $container->getDefinition('thelia.coupon.manager');
|
||||||
$services = $container->findTaggedServiceIds("thelia.coupon.addRule");
|
$services = $container->findTaggedServiceIds("thelia.coupon.addCondition");
|
||||||
|
|
||||||
foreach ($services as $id => $rule) {
|
foreach ($services as $id => $condition) {
|
||||||
$couponManager->addMethodCall(
|
$couponManager->addMethodCall(
|
||||||
'addAvailableRule',
|
'addAvailableCondition',
|
||||||
array(
|
array(
|
||||||
new Reference($id)
|
new Reference($id)
|
||||||
)
|
)
|
||||||
@@ -241,7 +241,7 @@ class CouponManager
|
|||||||
*
|
*
|
||||||
* @param ConditionManagerInterface $condition ConditionManagerInterface
|
* @param ConditionManagerInterface $condition ConditionManagerInterface
|
||||||
*/
|
*/
|
||||||
public function addAvailableRule(ConditionManagerInterface $condition)
|
public function addAvailableCondition(ConditionManagerInterface $condition)
|
||||||
{
|
{
|
||||||
$this->availableConditions[] = $condition;
|
$this->availableConditions[] = $condition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use Symfony\Component\Validator\Constraints\DateTime;
|
|||||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\NotEqualTo;
|
use Symfony\Component\Validator\Constraints\NotEqualTo;
|
||||||
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
@@ -110,7 +111,7 @@ class CouponCreationForm extends BaseForm
|
|||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
'isEnabled',
|
'isEnabled',
|
||||||
'checkbox',
|
'text',
|
||||||
array()
|
array()
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
@@ -125,17 +126,17 @@ class CouponCreationForm extends BaseForm
|
|||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
'isCumulative',
|
'isCumulative',
|
||||||
'checkbox',
|
'text',
|
||||||
array()
|
array()
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
'isRemovingPostage',
|
'isRemovingPostage',
|
||||||
'checkbox',
|
'text',
|
||||||
array()
|
array()
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
'isAvailableOnSpecialOffers',
|
'isAvailableOnSpecialOffers',
|
||||||
'checkbox',
|
'text',
|
||||||
array()
|
array()
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ $(function($){
|
|||||||
$.couponManager.conditionToSave = $.couponManager.conditionsToSave[id];
|
$.couponManager.conditionToSave = $.couponManager.conditionsToSave[id];
|
||||||
|
|
||||||
// Set the condition selector
|
// Set the condition selector
|
||||||
$("#category-rule option").filter(function() {
|
$("#category-condition option").filter(function() {
|
||||||
return $(this).val() == $.couponManager.conditionToSave.serviceId;
|
return $(this).val() == $.couponManager.conditionToSave.serviceId;
|
||||||
}).prop('selected', true);
|
}).prop('selected', true);
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ $(function($){
|
|||||||
// Save conditions on click
|
// Save conditions on click
|
||||||
$.couponManager.onClickSaveCondition = function() {
|
$.couponManager.onClickSaveCondition = function() {
|
||||||
$('#constraint-save-btn').on('click', function () {
|
$('#constraint-save-btn').on('click', function () {
|
||||||
if($('#category-rule').val() == 'thelia.condition.match_for_everyone') {
|
if($('#category-condition').val() == 'thelia.condition.match_for_everyone') {
|
||||||
// // @todo translate message + put it in modal
|
// // @todo translate message + put it in 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) {
|
||||||
@@ -140,7 +140,7 @@ $(function($){
|
|||||||
|
|
||||||
// Reload condition inputs when changing effect
|
// Reload condition inputs when changing effect
|
||||||
$.couponManager.onConditionChange = function() {
|
$.couponManager.onConditionChange = function() {
|
||||||
$('#category-rule').on('change', function () {
|
$('#category-condition').on('change', function () {
|
||||||
$.couponManager.loadConditionInputs($(this).val(), function() {});
|
$.couponManager.loadConditionInputs($(this).val(), function() {});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -152,9 +152,9 @@ $(function($){
|
|||||||
|
|
||||||
// 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);
|
||||||
$('#max-usage').hide();
|
$('#max-usage').hide();
|
||||||
$('#max-usage-label').hide();
|
$('#max-usage-label').hide();
|
||||||
} else {
|
} else {
|
||||||
@@ -163,7 +163,7 @@ $(function($){
|
|||||||
$('#max-usage-label').show();
|
$('#max-usage-label').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
isUnlimited.change(function(){
|
$isUnlimited.change(function(){
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
if ($this.is(':checked')) {
|
if ($this.is(':checked')) {
|
||||||
$('#max-usage').hide().val('-1');
|
$('#max-usage').hide().val('-1');
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function($){
|
$(function($){
|
||||||
miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
// miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
||||||
|
|
||||||
// Init Conditions
|
// Init Conditions
|
||||||
$.couponManager.initConditions = function() {
|
$.couponManager.initConditions = function() {
|
||||||
|
|||||||
@@ -45,7 +45,6 @@
|
|||||||
|
|
||||||
{form_field form=$form field='isAvailableOnSpecialOffers'}
|
{form_field form=$form field='isAvailableOnSpecialOffers'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
{$value|var_dump}
|
|
||||||
<label for="is-available-on-special-offers" class="checkbox control-label">
|
<label for="is-available-on-special-offers" class="checkbox control-label">
|
||||||
<input id="is-available-on-special-offers" type="checkbox" name="{$name}" {if $value}value="1" checked{/if} />
|
<input id="is-available-on-special-offers" type="checkbox" name="{$name}" {if $value}value="1" checked{/if} />
|
||||||
{if $error}{$message}{/if}
|
{if $error}{$message}{/if}
|
||||||
@@ -122,7 +121,6 @@
|
|||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{form_field form=$form field='amount'}
|
{form_field form=$form field='amount'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
{$value}
|
|
||||||
<label for="amount" class="control-label">{intl l='Amount :'}</label>
|
<label for="amount" class="control-label">{intl l='Amount :'}</label>
|
||||||
<input id="amount" type="text" class="form-control" name="{$name}" value="{$value}" placeholder="{intl l='14.50'}">
|
<input id="amount" type="text" class="form-control" name="{$name}" value="{$value}" placeholder="{intl l='14.50'}">
|
||||||
{if $error}{$message}{/if}
|
{if $error}{$message}{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user