Working : Coupon : fix update effect (becomes type), update max usage
This commit is contained in:
@@ -160,26 +160,31 @@
|
|||||||
|
|
||||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||||
|
|
||||||
<route id="admin.coupon.list" path="/admin/coupon/">
|
<route id="admin.coupon.list" path="/admin/coupon">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::browseAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::browseAction</default>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.create" path="/admin/coupon/create/">
|
<route id="admin.coupon.create" path="/admin/coupon/create">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::createAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::createAction</default>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}/">
|
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::updateAction</default>
|
||||||
|
<requirement key="couponId">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}/">
|
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
||||||
|
<requirement key="couponId">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}/">
|
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
|
||||||
|
<requirement key="ruleId">.*</requirement>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update/">
|
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
|
||||||
|
<requirement key="couponId">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}/">
|
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\CouponController::consumeAction</default>
|
<default key="_controller">Thelia\Controller\Admin\CouponController::consumeAction</default>
|
||||||
|
<requirement key="couponCode">.*</requirement>
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
<!-- Routes to the Config (system variables) controller -->
|
<!-- Routes to the Config (system variables) controller -->
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class CouponController extends BaseAdminController
|
|||||||
$lang = $this->getSession()->getLang();
|
$lang = $this->getSession()->getLang();
|
||||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||||
|
|
||||||
// Create
|
// Update
|
||||||
if ($this->getRequest()->isMethod('POST')) {
|
if ($this->getRequest()->isMethod('POST')) {
|
||||||
$this->validateCreateOrUpdateForm(
|
$this->validateCreateOrUpdateForm(
|
||||||
$i18n,
|
$i18n,
|
||||||
@@ -210,7 +210,7 @@ class CouponController extends BaseAdminController
|
|||||||
'updated',
|
'updated',
|
||||||
'update'
|
'update'
|
||||||
);
|
);
|
||||||
} else { // Update
|
} else { // Display
|
||||||
|
|
||||||
// Prepare the data that will hydrate the form
|
// Prepare the data that will hydrate the form
|
||||||
/** @var ConstraintFactory $constraintFactory */
|
/** @var ConstraintFactory $constraintFactory */
|
||||||
@@ -495,11 +495,12 @@ class CouponController extends BaseAdminController
|
|||||||
|
|
||||||
// Get the form field values
|
// Get the form field values
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||||
$data['code'],
|
$data['code'],
|
||||||
$data['title'],
|
$data['title'],
|
||||||
$data['amount'],
|
$data['amount'],
|
||||||
$data['effect'],
|
$data['type'],
|
||||||
$data['shortDescription'],
|
$data['shortDescription'],
|
||||||
$data['description'],
|
$data['description'],
|
||||||
$data['isEnabled'],
|
$data['isEnabled'],
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
* @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 $effect Coupon effect
|
* @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
|
||||||
@@ -106,7 +106,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
$code,
|
$code,
|
||||||
$title,
|
$title,
|
||||||
$amount,
|
$amount,
|
||||||
$effect,
|
$type,
|
||||||
$shortDescription,
|
$shortDescription,
|
||||||
$description,
|
$description,
|
||||||
$isEnabled,
|
$isEnabled,
|
||||||
@@ -130,7 +130,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
$this->rules = $rules;
|
$this->rules = $rules;
|
||||||
$this->shortDescription = $shortDescription;
|
$this->shortDescription = $shortDescription;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->effect = $effect;
|
$this->type = $type;
|
||||||
$this->locale = $locale;
|
$this->locale = $locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,13 +264,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Coupon effect
|
* Get Coupon type (effect)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEffect()
|
public function getType()
|
||||||
{
|
{
|
||||||
return $this->effect;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class CouponCreationForm extends BaseForm
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
'effect',
|
'type',
|
||||||
'text',
|
'text',
|
||||||
array(
|
array(
|
||||||
'constraints' => array(
|
'constraints' => array(
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Coupon extends BaseCoupon
|
|||||||
* @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 $effect Coupon effect
|
* @param string $type Coupon type
|
||||||
* @param bool $isRemovingPostage Is removing Postage
|
* @param bool $isRemovingPostage Is removing Postage
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
* @param string $description Coupon description
|
* @param string $description Coupon description
|
||||||
@@ -67,13 +67,13 @@ class Coupon extends BaseCoupon
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
function createOrUpdate($code, $title, $amount, $effect, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null)
|
function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null)
|
||||||
{
|
{
|
||||||
$this->setCode($code)
|
$this->setCode($code)
|
||||||
->setTitle($title)
|
->setTitle($title)
|
||||||
->setShortDescription($shortDescription)
|
->setShortDescription($shortDescription)
|
||||||
->setDescription($description)
|
->setDescription($description)
|
||||||
->setType($effect)
|
->setType($type)
|
||||||
->setAmount($amount)
|
->setAmount($amount)
|
||||||
->setIsRemovingPostage($isRemovingPostage)
|
->setIsRemovingPostage($isRemovingPostage)
|
||||||
->setIsEnabled($isEnabled)
|
->setIsEnabled($isEnabled)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Coupon;
|
namespace Thelia\Coupon;
|
||||||
|
|
||||||
|
use Thelia\Coupon\RuleOrganizer;
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
* Date: 8/19/13
|
* Date: 8/19/13
|
||||||
@@ -47,7 +48,7 @@ class RuleOrganizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->object = new RuleOrganizer;
|
$this->object = new RuleOrganizer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -138,17 +138,24 @@ $(function($){
|
|||||||
|
|
||||||
// Set max usage to unlimited or not
|
// Set max usage to unlimited or not
|
||||||
couponManager.onUsageUnlimitedChange = function() {
|
couponManager.onUsageUnlimitedChange = function() {
|
||||||
if (!$('#max-usage').parent().hasClass('has-error')) {
|
var isUnlimited = $('#is-unlimited');
|
||||||
$('#max-usage').hide().attr('value', '-1');
|
if ($('#max-usage').val() == -1) {
|
||||||
$('#max-usage-label').hide();
|
isUnlimited.prop('checked', true);
|
||||||
}
|
$('#max-usage').hide();
|
||||||
$('#is-unlimited').change(function(){
|
|
||||||
var $this = $(this);
|
|
||||||
if ($this.is(':checked')) {
|
|
||||||
$('#max-usage').hide().attr('value', '-1');
|
|
||||||
$('#max-usage-label').hide();
|
$('#max-usage-label').hide();
|
||||||
} else {
|
} else {
|
||||||
$('#max-usage').show().val('').attr('value', '');
|
$isUnlimited.prop('checked', false);
|
||||||
|
$('#max-usage').show();
|
||||||
|
$('#max-usage-label').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
isUnlimited.change(function(){
|
||||||
|
var $this = $(this);
|
||||||
|
if ($this.is(':checked')) {
|
||||||
|
$('#max-usage').hide().val('-1');
|
||||||
|
$('#max-usage-label').hide();
|
||||||
|
} else {
|
||||||
|
$('#max-usage').show().val('');
|
||||||
$('#max-usage-label').show();
|
$('#max-usage-label').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -88,11 +88,11 @@
|
|||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
|
|
||||||
<label for="is-unlimited" class="checkbox control-label">
|
<label for="is-unlimited" class="checkbox control-label">
|
||||||
<input id="is-unlimited" type="checkbox" name="is-unlimited" {if $error}{else}checked{/if} >
|
<input id="is-unlimited" type="checkbox" name="is-unlimited" >
|
||||||
{intl l='Is unlimited'}
|
{intl l='Is unlimited'}
|
||||||
</label>
|
</label>
|
||||||
<label id="max-usage-label" for="max-usage" class="control-label">{intl l='Max usage :'}</label>
|
<label id="max-usage-label" for="max-usage" class="control-label">{intl l='Max usage :'}</label>
|
||||||
<input id="max-usage" type="text" class="form-control" name="{$name}" value="{$value}" placeholder="{intl l='max usage'}">
|
<input id="max-usage" type="text" class="form-control" name="{$name}" value="{if !$value}-1{else}{$value}{/if}" placeholder="{intl l='max usage'}">
|
||||||
{if $error}{$message}{/if}
|
{if $error}{$message}{/if}
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
@@ -101,17 +101,19 @@
|
|||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="well clearfix">
|
<div class="well clearfix">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{form_field form=$form field='effect'}
|
{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="effect" class="control-label">{intl l='Effect :'}</label>
|
<label for="type" class="control-label">{intl l='Type :'}</label>
|
||||||
<select name="{$name}" value="{$value}" id="effect" class="col-md-12 form-control">
|
<select name="{$name}" value="{$value}" id="type" class="col-md-12 form-control">
|
||||||
<option value="-1" data-description="">{intl l='Please select an effect'}</option>
|
<option value="-1" data-description="">{intl l='Please select an 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}>{$availableCoupon.name}</option>
|
<option value="{$availableCoupon.serviceId}" data-description="{$availableCoupon.toolTip}" {if $value == $availableCoupon.serviceId}selected="selected"{/if}>
|
||||||
|
{$availableCoupon.name}
|
||||||
|
</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
{if $error}{$message}{/if}
|
{if $error}{$message}{/if}
|
||||||
<span id="effectToolTip" class="help-block">{$availableCoupons.0.toolTip}</span>
|
<span id="typeToolTip" class="help-block">{$availableCoupons.0.toolTip}</span>
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user