WIP : Coupon fix coupon creation issue

This commit is contained in:
gmorel
2013-09-13 18:03:08 +02:00
parent d829835d51
commit 6118a68370
8 changed files with 171 additions and 134 deletions

View File

@@ -157,9 +157,10 @@ class CouponController extends BaseAdminController
// If no input for expirationDate, now + 2 months
$defaultDate = new \DateTime();
$args['defaultDate'] = $defaultDate->modify('+2 month')
->format($lang->getDateFormat());
->format('Y-m-d');
}
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
$args['availableCoupons'] = $this->getAvailableCoupons();
$args['formAction'] = 'admin/coupon/create/';
@@ -224,7 +225,7 @@ class CouponController extends BaseAdminController
'shortDescription' => $coupon->getShortDescription(),
'description' => $coupon->getDescription(),
'isEnabled' => ($coupon->getIsEnabled() == 1),
'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
'expirationDate' => $coupon->getExpirationDate('Y-m-d'),
'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
'isCumulative' => ($coupon->getIsCumulative() == 1),
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
@@ -273,103 +274,6 @@ class CouponController extends BaseAdminController
return $this->render('coupon-update', $args);
}
// /**
// * Manage Coupons Rule creation display
// *
// * @param int $couponId Coupon id
// *
// * @return \Symfony\Component\HttpFoundation\Response
// */
// public function createRuleAction($couponId)
// {
// // Check current user authorization
// $response = $this->checkAuth('admin.coupon.update');
// if ($response !== null) {
// return $response;
// }
//
// /** @var Coupon $coupon */
// $coupon = CouponQuery::create()->findOneById($couponId);
// if (!$coupon) {
// $this->pageNotFound();
// }
//
// // Parameters given to the template
// $args = array();
//
// $i18n = new I18n();
// /** @var Lang $lang */
// $lang = $this->getSession()->get('lang');
// $eventToDispatch = TheliaEvents::COUPON_RULE_CREATE;
//
// if ($this->getRequest()->isMethod('POST')) {
// $this->validateCreateOrUpdateForm(
// $i18n,
// $lang,
// $eventToDispatch,
// 'updated',
// 'update'
// );
// } else {
// // Prepare the data that will hydrate the form
//
// /** @var ConstraintFactory $constraintFactory */
// $constraintFactory = $this->container->get('thelia.constraint.factory');
//
// $data = array(
// 'code' => $coupon->getCode(),
// 'title' => $coupon->getTitle(),
// 'amount' => $coupon->getAmount(),
// 'effect' => $coupon->getType(),
// 'shortDescription' => $coupon->getShortDescription(),
// 'description' => $coupon->getDescription(),
// 'isEnabled' => ($coupon->getIsEnabled() == 1),
// 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
// 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
// 'isCumulative' => ($coupon->getIsCumulative() == 1),
// 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
// 'maxUsage' => $coupon->getMaxUsage(),
// 'rules' => $constraintFactory->unserializeCouponRuleCollection($coupon->getSerializedRules()),
// 'locale' => $coupon->getLocale(),
// );
//
// /** @var CouponAdapterInterface $adapter */
// $adapter = $this->container->get('thelia.adapter');
// /** @var Translator $translator */
// $translator = $this->container->get('thelia.translator');
//
// $args['rulesObject'] = array();
// /** @var CouponRuleInterface $rule */
// foreach ($coupon->getRules()->getRules() as $rule) {
// $args['rulesObject'][] = array(
// 'name' => $rule->getName($translator),
// 'tooltip' => $rule->getToolTip($translator),
// 'validators' => $rule->getValidators()
// );
// }
//
// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules());
//
// // Setup the object form
// $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
//
// // Pass it to the parser
// $this->getParserContext()->addForm($changeForm);
// }
//
// $args['formAction'] = 'admin/coupon/update/' . $couponId;
//
// return $this->render(
// 'coupon-update',
// $args
// );
// }
/**
* Manage Coupons read display
*
@@ -569,7 +473,7 @@ class CouponController extends BaseAdminController
/**
* Validate the CreateOrUpdate form
*
* @param string $i18n Local code (fr_FR)
* @param I18n $i18n Local code (fr_FR)
* @param Lang $lang Local variables container
* @param string $eventToDispatch Event which will activate actions
* @param string $log created|edited
@@ -577,7 +481,7 @@ class CouponController extends BaseAdminController
*
* @return $this
*/
protected function validateCreateOrUpdateForm($i18n, $lang, $eventToDispatch, $log, $action)
protected function validateCreateOrUpdateForm(I18n $i18n, Lang $lang, $eventToDispatch, $log, $action)
{
// Create the form from the request
$creationForm = new CouponCreationForm($this->getRequest());
@@ -597,7 +501,7 @@ class CouponController extends BaseAdminController
$data['shortDescription'],
$data['description'],
$data['isEnabled'],
$i18n->getDateTimeFromForm($lang, $data['expirationDate']),
\DateTime::createFromFormat('Y-m-d', $data['expirationDate']),
$data['isAvailableOnSpecialOffers'],
$data['isCumulative'],
$data['isRemovingPostage'],

View File

@@ -24,6 +24,7 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotEqualTo;

View File

@@ -76,7 +76,6 @@ class Coupon extends BaseCoupon
->setType($effect)
->setAmount($amount)
->setIsRemovingPostage($isRemovingPostage)
->setType($amount)
->setIsEnabled($isEnabled)
->setExpirationDate($expirationDate)
->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)

View File

@@ -140,28 +140,21 @@ $(function($){
couponManager.onUsageUnlimitedChange = function() {
if (!$('#max-usage').parent().hasClass('has-error')) {
$('#max-usage').hide().attr('value', '-1');
$('#max-usage-label').hide();
}
$('#is-unlimited').change(function(){
var $this = $(this);
if ($this.is(':checked')) {
$('#max-usage').hide().attr('value', '-1');
$('#max-usage-label').hide();
} else {
$('#max-usage').show().val('').attr('value', '');
$('#max-usage-label').show();
}
});
};
couponManager.onUsageUnlimitedChange();
// // -- Effect description
// if($('[name=effect]').length){
// var $effectSelect = $('[name=effect]'),
// $helpBlock = $effectSelect.next('.help-block');
//
// $effectSelect.change(function(){
// var description = $(this).find(":selected").data('description');
// $helpBlock.text(description);
// });
// }
});
// Rule to save
@@ -176,3 +169,4 @@ couponManager.ruleToSave.values = {};
couponManager.rulesToSave = [];
// Rule being updated id
couponManager.ruleToUpdateId = false;

View File

@@ -20,7 +20,6 @@
{form name="thelia.admin.coupon.creation"}
{include file='coupon/form.html' formAction={url path={$formAction}} noRules=true}
{/form}
</section> <!-- #wrapper -->
{include file='includes/confirmation-modal.html'}
@@ -42,4 +41,13 @@
{javascripts file='assets/js/coupon.js'}
<script src="{$asset_url}"></script>
{/javascripts}
{*<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>*}
{*<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />*}
<script>
$(function($){
{*$('.datepicker').datepicker({ dateFormat: "{$dateFormat}", defaultDate: +60, minDate: "+0m" });*}
});
</script>
{/block}

View File

@@ -11,7 +11,7 @@
{/form_field}
{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}
<div class="span4">
@@ -35,40 +35,40 @@
{form_field form=$form field='isEnabled'}
<div class="form-group {if $error}has-error{/if}">
<label for="enabled" class="checkbox control-label">
<input id="enabled" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
<label for="is-enabled" class="checkbox control-label">
<input id="is-enabled" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
{if $error}{$message}{/if}
{intl l='Is enabled ?'}
{intl l='Is enabled'}
</label>
</div>
{/form_field}
{form_field form=$form field='isAvailableOnSpecialOffers'}
<div class="form-group {if $error}has-error{/if}">
<label for="available-on-special-offers" class="checkbox control-label">
<input id="available-on-special-offers" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
<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{else}value="0"{/if} >
{if $error}{$message}{/if}
{intl l='Is available on special offers ?'}
{intl l='Is available on special offers'}
</label>
</div>
{/form_field}
{form_field form=$form field='isCumulative'}
<div class="form-group {if $error}has-error{/if}">
<label for="cumulative" class="checkbox control-label">
<input id="cumulative" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
<label for="is-cumulative" class="checkbox control-label">
<input id="is-cumulative" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
{if $error}{$message}{/if}
{intl l='Is cumulative ?'}
{intl l='Is cumulative'}
</label>
</div>
{/form_field}
{form_field form=$form field='isRemovingPostage'}
<div class="form-group {if $error}has-error{/if}">
<label for="renoving-postage" class="checkbox control-label">
<input id="renoving-postage" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
<label for="is-removing-postage" class="checkbox control-label">
<input id="is-removing-postage" type="checkbox" name="{$name}" {if $value}value="1" checked{else}value="0"{/if} >
{if $error}{$message}{/if}
{intl l='Is removing postage ?'}
{intl l='Is removing postage'}
</label>
</div>
{/form_field}
@@ -77,7 +77,7 @@
<div class="form-group {if $error}has-error{/if}">
<label for="expiration-date" class="control-label">{intl l='Expiration date :'}</label>
<div class="input-append date" data-date="12/02/2012" data-date-format="dd/mm/yyyy">
<input type="text" id="expiration-date" name="{$name}" class="form-control" value="{if $defaultDate}{$defaultDate}{else}{$value}{/if}">
<input type="text" id="expiration-date" name="{$name}" class="form-control datepicker" data-date-format="yyyy-mm-dd" value="{if $defaultDate}{$defaultDate}{else}{$value}{/if}" placeholder="{intl l='yyyy-mm-dd'}">
{if $error}{$message}{/if}
<span class="add-on"><span class="icon-th"></span></span>
</div>
@@ -86,11 +86,12 @@
{form_field form=$form field='maxUsage'}
<div class="form-group {if $error}has-error{/if}">
<label for="max-usage" class="control-label">{intl l='Max usage :'}</label>
<label for="is-unlimited" class="checkbox control-label">
<input id="is-unlimited" type="checkbox" name="is-unlimited" {if $error}{else}checked{/if} >
{intl l='Is unlimited ?'}
{intl l='Is unlimited'}
</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'}">
{if $error}{$message}{/if}
</div>
@@ -118,6 +119,7 @@
<div class="col-md-6">
{form_field form=$form field='amount'}
<div class="form-group {if $error}has-error{/if}">
{$value}
<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'}">
{if $error}{$message}{/if}
@@ -157,7 +159,7 @@
</div>
{/form_field}
<button type="submit" class="btn btn-default btn-primary">{intl l='Save your modifications'}</button>
<button id="save-coupon-btn" type="submit" class="btn btn-default btn-primary">{intl l='Save your modifications'}</button>
</div>
</div>

View File

@@ -3,7 +3,7 @@ casper.test.comment('Please edit 00_parameters.js to add your configuration');
var thelia2_login_admin_url = thelia2_base_url + 'admin/login';
var thelia2_login_coupon_list_url = thelia2_base_url + 'admin/login';
var thelia2_login_coupon_create_url = thelia2_base_url + 'admin/coupon/create';
var thelia2_login_coupon_create_url = thelia2_base_url + 'admin/coupon/create/';
var thelia2_login_coupon_read_url = thelia2_base_url + 'admin/coupon/read/1';
var thelia2_login_coupon_update_url = thelia2_base_url + 'admin/coupon/update/1';

View File

@@ -15,8 +15,137 @@ casper.test.comment('Testing coupons');
// @todo implement
////CREATE
// @todo implement
casper.start(thelia2_login_coupon_create_url, function() {
this.test.assertHttpStatus(200);
this.test.comment('Now on : ' + this.getCurrentUrl());
this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png');
this.test.comment('COUPON - CREATE EMPTY');
// Click on is unlimited button
this.click("form #is-unlimited");
this.sendKeys('input#max-usage', '-2');
// cleaning expiration date default value
this.evaluate(function() {
$("#expiration-date").val('').change();
return true;
});
this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png');
this.click("form .control-group .btn.btn-default.btn-primary");
});
casper.wait(1000, function() {
this.echo("\nWaiting....");
});
// Test Coupon creation if no input
casper.then(function(){
this.test.assertHttpStatus(200);
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-empty-coupon.png');
this.test.assertExists('.has-error #code', 'Error on code input found');
this.test.assertExists('.has-error #title', 'Error on title input found');
this.test.assertExists('.has-error #expiration-date', 'Error on expiration date input found');
this.test.assertExists('.has-error #max-usage', 'Error on max usage input found');
this.test.assertExists('.has-error #description', 'Error on description input found');
this.test.assertExists('.has-error #effect', 'Error on effect input found');
this.test.assertExists('.has-error #amount', 'Error on amount input found');
this.test.assertExists('.has-error #short-description', 'Error on short-description input found');
});
// Test Coupon creation if good input
casper.then(function(){
this.sendKeys('input#code', 'XMAS10');
this.sendKeys('input#title', 'christmas');
this.click("form #is-enabled");
this.click("form #is-available-on-special-offers");
this.click("form #is-cumulative");
this.click("form #is-removing-postage");
this.evaluate(function() {
$("#expiration-date").val('2013-11-14').change();
return true;
});
// Click on is unlimited button
this.click("form #is-unlimited");
this.sendKeys('input#max-usage', '40');
this.evaluate(function() {
$('#effect').val('thelia.coupon.type.remove_x_amount').change();
return true;
});
this.test.assertSelectorHasText(
'#effectToolTip',
this.evaluate(function () {
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
}),
'Tooltip found'
);
this.sendKeys('input#amount', '42.12');
this.sendKeys('#short-description', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.');
this.sendKeys('#description', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.');
this.capture('tests/functionnal/casperjs/screenshot/coupons/coupon-created-ready-to-be-saved.png');
this.click("#save-coupon-btn");
});
casper.wait(2000, function() {
this.echo("\nWaiting....");
});
// Test Coupon creation if good input is well saved
casper.then(function(){
this.test.assertHttpStatus(302);
this.test.comment('Now on : ' + this.getCurrentUrl());
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-coupon.png');
this.test.assertField('thelia_coupon_creation[code]', 'XMAS10', 'Code found');
this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found');
this.test.assert(this.evaluate(function () {
return document.getElementById('is-enabled').checked;
}), 'Checkbox is enabled checked');
this.test.assert(this.evaluate(function () {
return document.getElementById('is-available-on-special-offers').checked;
}), 'Checkbox is available on special offers checked');
this.test.assert(this.evaluate(function () {
return document.getElementById('is-cumulative').checked;
}), 'Checkbox is cumulative checked');
this.test.assert(this.evaluate(function () {
return document.getElementById('is-removing-postage').checked;
}), 'Checkbox is cumulative checked');
this.test.assertField('thelia_coupon_creation[expirationDate]', '2013-11-14', 'Expiration date found');
this.test.assertField('thelia_coupon_creation[maxUsage]', '40', 'Max usage found');
this.test.assert(this.evaluate(function () {
return !document.getElementById('is-unlimited').checked;
}), 'Checkbox is unlimited not checked');
this.test.assert(
this.evaluate(function () {
return $("#effect").val();
}),
'thelia.coupon.type.remove_x_amount',
'Effect found'
);
this.test.assertSelectorHasText(
'#effectToolTip',
this.evaluate(function () {
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
}),
'Tooltip found'
);
this.test.assertField('thelia_coupon_creation[amount]', '42.12', 'Amount found');
this.test.assertField('thelia_coupon_creation[shortDescription]', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.', 'Short description found');
this.test.assertField('thelia_coupon_creation[description]', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.', 'Description found');
});
////EDIT CHECK
// @todo implement