From d41bbfc9eb3a1075ca6388b62bd926ef61c4817a Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 30 May 2014 19:58:02 +0200 Subject: [PATCH 01/23] Improved and simplified coupon form management --- core/lib/Thelia/Config/Resources/coupon.xml | 4 +- .../Controller/Admin/CouponController.php | 42 +------ .../Coupon/CouponCreateOrUpdateEvent.php | 7 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 112 ++++++++++++++++-- .../Thelia/Coupon/Type/CouponInterface.php | 18 +-- .../Coupon/Type/RemoveAmountOnCategories.php | 97 ++++++++++++++- core/lib/Thelia/Coupon/Type/RemoveXAmount.php | 49 +++++--- .../lib/Thelia/Coupon/Type/RemoveXPercent.php | 52 ++++---- core/lib/Thelia/Form/CouponCreationForm.php | 19 ++- core/lib/Thelia/Model/Coupon.php | 13 +- templates/backOffice/default/coupon/form.html | 2 - .../remove-amount-on-categories.html | 19 ++- .../type-fragments/remove-x-amount.html | 10 +- .../type-fragments/remove-x-percent.html | 9 +- .../coupon/type-fragments/remove-x.html | 6 +- 15 files changed, 317 insertions(+), 142 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/coupon.xml b/core/lib/Thelia/Config/Resources/coupon.xml index a8b2df45d..68486c969 100644 --- a/core/lib/Thelia/Config/Resources/coupon.xml +++ b/core/lib/Thelia/Config/Resources/coupon.xml @@ -30,12 +30,12 @@ - + diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 11abe29a3..abf3177aa 100644 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -25,9 +25,7 @@ use Thelia\Core\Security\AccessManager; use Thelia\Coupon\CouponFactory; use Thelia\Coupon\CouponManager; use Thelia\Condition\ConditionCollection; -use Thelia\Coupon\Type\CouponAbstract; use Thelia\Coupon\Type\CouponInterface; -use Thelia\Coupon\Type\RemoveXPercent; use Thelia\Form\CouponCreationForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Log\Tlog; @@ -577,7 +575,7 @@ class CouponController extends BaseAdminController $condition['serviceId'] = $availableCoupon->getServiceId(); $condition['name'] = $availableCoupon->getName(); $condition['toolTip'] = $availableCoupon->getToolTip(); - // $condition['inputName'] = $availableCoupon->getInputName(); + $cleanedCoupons[] = $condition; } @@ -676,35 +674,6 @@ class CouponController extends BaseAdminController } - /** - * Add percentage logic if found in the Coupon post data - * - * @param array $effects Effect parameters to populate - * @param array $extendedInputNames Extended Inputs to manage - * - * @return array Populated effect with percentage - */ - protected function addExtendedLogic(array $effects, array $extendedInputNames) - { - /** @var Request $request */ - $request = $this->container->get('request'); - $postData = $request->request; - // Validate quantity input - - if ($postData->has(RemoveXPercent::INPUT_EXTENDED__NAME)) { - $extentedPostData = $postData->get(RemoveXPercent::INPUT_EXTENDED__NAME); - - foreach ($extendedInputNames as $extendedInputName) { - if (isset($extentedPostData[$extendedInputName])) { - $inputValue = $extentedPostData[$extendedInputName]; - $effects[$extendedInputName] = $inputValue; - } - } - } - - return $effects; - } - /** * Feed the Coupon Create or Update event with the User inputs * @@ -718,16 +687,15 @@ class CouponController extends BaseAdminController // Get the form field values $data = $form->getData(); $serviceId = $data['type']; - /** @var CouponInterface $couponManager */ - $couponManager = $this->container->get($serviceId); - $effects = [CouponAbstract::INPUT_AMOUNT_NAME => $data[CouponAbstract::INPUT_AMOUNT_NAME]]; - $effects = $this->addExtendedLogic($effects, $couponManager->getExtendedInputs()); + + /** @var CouponInterface $coupon */ + $coupon = $this->container->get($serviceId); $couponEvent = new CouponCreateOrUpdateEvent( $data['code'], $serviceId, $data['title'], - $effects, + $coupon->getEffects($data), $data['shortDescription'], $data['description'], $data['isEnabled'], diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index 755dbe9f7..ae2312aae 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -327,10 +327,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent */ public function setEffects(array $effects) { - if (null === $effects['amount']) { - throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array'); - } - $this->amount = $effects['amount']; + // Amount is now optionnal. + $this->amount = isset($effects['amount']) ? $effects['amount'] : 0; + $this->effects = $effects; } diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index 424de8323..d04c29b89 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -17,6 +17,7 @@ use Thelia\Condition\ConditionEvaluator; use Thelia\Condition\ConditionOrganizerInterface; use Thelia\Core\Translation\Translator; use Thelia\Coupon\FacadeInterface; +use Thelia\Form\CouponCreationForm; use Thelia\Model\CouponCountry; use Thelia\Model\CouponModule; @@ -29,12 +30,21 @@ use Thelia\Model\CouponModule; */ abstract class CouponAbstract implements CouponInterface { - const INPUT_EXTENDED__NAME = 'thelia_coupon_creation_extended'; + /** + * The dataset name for all coupon specific input fields, that do not appear in the CouPonCreationForm form. + * + * In the input form, these fields have to be created like: + * + * thelia_coupon_specific[my_field, thelia_coupon_creation_extended[my_other_field] + * + * use the makeCouponField() method to do that safely. + */ + const COUPON_DATASET_NAME = 'coupon_specific'; - const INPUT_AMOUNT_NAME = 'amount'; - - /** @var array Extended Inputs to manage */ - protected $extendedInputs = array(); + /** + * A standard 'amount' filed name, thant can be used in coupons which extends this class + */ + const AMOUNT_FIELD_NAME = 'amount'; /** @var FacadeInterface Provide necessary value from Thelia */ protected $facade = null; @@ -161,7 +171,8 @@ abstract class CouponAbstract implements CouponInterface $this->facade = $facade; $this->effects = $effects; - $this->amount = $effects[self::INPUT_AMOUNT_NAME]; + // Amount is now optional. + $this->amount = isset($effects[self::AMOUNT_FIELD_NAME]) ? $effects[self::AMOUNT_FIELD_NAME] : 0; $this->freeShippingForCountries = $freeShippingForCountries; $this->freeShippingForModules = $freeShippingForModules; @@ -383,6 +394,18 @@ abstract class CouponAbstract implements CouponInterface return $this->conditionEvaluator->isMatching($this->conditions); } + /** + * This is the field label than will be displayed in the form. + * This method should be overridden to be useful. + * + * For backward compatibility only. + * + * @return string + */ + public function getInputName() { + return "Please override getInputName() method"; + } + /** * Draw the input displayed in the BackOffice * allowing Admin to set its Coupon effect @@ -394,19 +417,86 @@ abstract class CouponAbstract implements CouponInterface { return $this->facade->getParser()->render('coupon/type-fragments/remove-x.html', [ 'label' => $this->getInputName(), - 'fieldName' => self::INPUT_AMOUNT_NAME, + 'fieldId' => self::AMOUNT_FIELD_NAME, + 'fieldName' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), 'value' => $this->amount ]); } /** - * Get all extended inputs name to manage + * This methods checks a field value. If the field has a correct value, this value is returned + * Otherwise, an InvalidArgumentException describing the problem should be thrown. * + * This method should be ovveriden to be useful. + * + * @param $fieldName + * @param $fieldValue * @return mixed + * @throws \InvalidArgumentException if the field valiue is not valid. */ - public function getExtendedInputs() - { - return $this->extendedInputs; + protected function checkCouponFieldValue($fieldName, $fieldValue) { + return $fieldValue; } + /** + * A helper to get the value of a standard field name + * + * @param string $fieldName the field name + * @param array $data the input form data (e.g. $form->getData()) + * @param mixed $defaultValue the default value if the field is not found. + * + * @return mixed the input value, or the default one + * + * @throws \InvalidArgumentException if the field is not found, and no default value has been defined. + */ + protected function getCouponFieldValue($fieldName, $data, $defaultValue = null) { + if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) { + + return $this->checkCouponFieldValue( + $fieldName, + $data[self::COUPON_DATASET_NAME][$fieldName] + ); + } + else if (null !== $defaultValue) { + return $defaultValue; + } + else { + throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName)); + } + } + + /** + * A helper to create an standard field name that will be used in the coupon form + * + * @param string $fieldName the field name + * @return string the complete name, ready to be used in a form. + */ + protected function makeCouponFieldName($fieldName) { + return sprintf("%s[%s][%s]", CouponCreationForm::COUPON_CREATION_FORM_NAME, self::COUPON_DATASET_NAME, $fieldName); + } + + /** + * Return a list of the fields name for this coupon. + * + * @return array + */ + protected function getFieldList() { + return [self::AMOUNT_FIELD_NAME]; + } + + /** + * Create the effect array from the list of fields + * + * @param array $data the input form data (e.g. $form->getData()) + * @return array a filedName => fieldValue array + */ + public function getEffects($data) { + $effects = []; + + foreach($this->getFieldList() as $fieldName) { + $effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data); + } + + return $effects; + } } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index 69eca002a..f9acc973d 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -15,6 +15,7 @@ namespace Thelia\Coupon\Type; use Propel\Runtime\Collection\ObjectCollection; use Thelia\Condition\ConditionCollection; use Thelia\Coupon\FacadeInterface; +use Thelia\Form\CouponCreationForm; /** * Represents a Coupon ready to be processed in a Checkout process @@ -220,13 +221,6 @@ interface CouponInterface */ public function drawBackOfficeInputs(); - /** - * Get all extended inputs name to manage - * - * @return mixed - */ - public function getExtendedInputs(); - /** * @return ObjectCollection list of country IDs for which shipping is free. All if empty */ @@ -236,4 +230,14 @@ interface CouponInterface * @return ObjectCollection list of module IDs for which shipping is free. All if empty */ public function getFreeShippingForModules(); + + /** + * Create the effect array from the list of fields + * + * @param array $data the input form data (e.g. $form->getData()) + * + * @return array a filedName => fieldValue array + */ + public function getEffects($data); + } diff --git a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php index 2372dbfb4..9994219e2 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php +++ b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php @@ -12,6 +12,9 @@ namespace Thelia\Coupon\Type; +use Thelia\Core\Translation\Translator; +use Thelia\Coupon\FacadeInterface; + /** * Allow to remove an amount from the checkout total * @@ -26,6 +29,44 @@ class RemoveAmountOnCategories extends CouponAbstract /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories'; + var $category_list = array(); + + /** + * @inheritdoc + */ + public function set( + FacadeInterface $facade, + $code, + $title, + $shortDescription, + $description, + array $effects, + $isCumulative, + $isRemovingPostage, + $isAvailableOnSpecialOffers, + $isEnabled, + $maxUsage, + \DateTime $expirationDate, + $freeShippingForCountries, + $freeShippingForModules, + $perCustomerUsageCount + ) + { + parent::set( + $facade, $code, $title, $shortDescription, $description, $effects, + $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate, + $freeShippingForCountries, + $freeShippingForModules, + $perCustomerUsageCount + ); + + $this->category_list = isset($effects[self::CATEGORIES_LIST]) ? $effects[self::CATEGORIES_LIST] : array(); + + if (! is_array($this->category_list)) $this->category_list = array($this->category_list); + + return $this; + } + /** * Get I18n name * @@ -64,18 +105,64 @@ class RemoveAmountOnCategories extends CouponAbstract */ public function exec() { + // TODO !!! return $this->amount; } public function drawBackOfficeInputs() { return $this->facade->getParser()->render('coupon/type-fragments/remove-amount-on-categories.html', [ - 'amount_field_name' => self::INPUT_AMOUNT_NAME, - 'amount_value' => $this->amount, - 'categories_field_name' => self::CATEGORIES_LIST, - 'categories_values' => isset($this->values[self::CATEGORIES_LIST]) ? $this->values[self::CATEGORIES_LIST] : array() + // The standard "Amount" field + 'amount_field_name' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), + 'amount_value' => $this->amount, - ]); + // The categories list field + 'categories_field_id' => self::CATEGORIES_LIST, + 'categories_field_name' => $this->makeCouponFieldName(self::CATEGORIES_LIST), + + // The selected categories + 'categories_values' => $this->category_list + ]); } + + /** + * Return a list of the fields name for this coupon. + * + * @return array + */ + protected function getFieldList() { + return [self::AMOUNT_FIELD_NAME, self::CATEGORIES_LIST]; + } + + + /** + * @inheritdoc + */ + protected function checkCouponFieldValue($fieldName, $fieldValue) + { + if ($fieldName === self::AMOUNT_FIELD_NAME) { + + if (floatval($fieldValue) < 0) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Value %val for Discount Amount is invalid. Please enter a positive value.', + [ '%val' => $fieldValue] + ) + ); + } + } + else if ($fieldName === self::CATEGORIES_LIST) { + if (empty($fieldValue)) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Please select at least one category' + ) + ); + } + } + + return $fieldValue; + } + } diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php index c644706a2..fe5322e22 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php @@ -12,6 +12,8 @@ namespace Thelia\Coupon\Type; +use Thelia\Core\Translation\Translator; + /** * Allow to remove an amount from the checkout total * @@ -36,18 +38,6 @@ class RemoveXAmount extends CouponAbstract ->trans('Fixed Amount Discount', array(), 'coupon'); } - /** - * Get I18n amount input name - * - * @return string - */ - public function getInputName() - { - return $this->facade - ->getTranslator() - ->trans('Discount amount', array(), 'coupon'); - } - /** * Get I18n tooltip * @@ -69,9 +59,38 @@ class RemoveXAmount extends CouponAbstract public function drawBackOfficeInputs() { return $this->facade->getParser()->render('coupon/type-fragments/remove-x-amount.html', [ - 'label' => $this->getInputName(), - 'fieldName' => self::INPUT_AMOUNT_NAME, + 'fieldName' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), 'value' => $this->amount ]); } -} + + /** + * Return a list of the fields name for this coupon. + * + * @return array + */ + protected function getFieldList() { + return [self::AMOUNT_FIELD_NAME]; + } + + /** + * @inheritdoc + */ + protected function checkCouponFieldValue($fieldName, $fieldValue) + { + if ($fieldName === self::AMOUNT_FIELD_NAME) { + + if (floatval($fieldValue) < 0) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Value %val for Disount Amount is invalid. Please enter a positive value.', + [ '%val' => $fieldValue] + ) + ); + } + } + + return $fieldValue; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php index e5a98c5fb..06c73981a 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php @@ -12,6 +12,7 @@ namespace Thelia\Coupon\Type; +use Thelia\Core\Translation\Translator; use Thelia\Coupon\FacadeInterface; /** @@ -29,11 +30,6 @@ class RemoveXPercent extends CouponAbstract /** @var float Percentage removed from the Cart */ protected $percentage = 0; - /** @var array Extended Inputs to manage */ - protected $extendedInputs = array( - self::INPUT_PERCENTAGE_NAME - ); - /** * @inheritdoc */ @@ -87,6 +83,26 @@ class RemoveXPercent extends CouponAbstract return round($this->facade->getCartTotalTaxPrice() * $this->percentage/100, 2); } + /** + * @inheritdoc + */ + protected function checkCouponFieldValue($fieldName, $fieldValue) + { + if ($fieldName === self::INPUT_PERCENTAGE_NAME) { + + if (floatval($fieldValue) <= 0) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Value %val for Percent Discount is invalid. Please enter a positive value between 1 and 100.', + [ '%val' => $fieldValue] + ) + ); + } + } + + return $fieldValue; + } + /** * Get I18n name * @@ -99,18 +115,6 @@ class RemoveXPercent extends CouponAbstract ->trans('Remove X percent to total cart', array(), 'coupon'); } - /** - * Get I18n amount input name - * - * @return string - */ - public function getInputName() - { - return $this->facade - ->getTranslator() - ->trans('Percent Discount', array(), 'coupon'); - } - /** * Get I18n tooltip * @@ -138,11 +142,17 @@ class RemoveXPercent extends CouponAbstract public function drawBackOfficeInputs() { return $this->facade->getParser()->render('coupon/type-fragments/remove-x-percent.html', [ - 'label' => $this->getInputName(), - 'typeKey' => self::INPUT_AMOUNT_NAME, - 'fieldId' => self::INPUT_PERCENTAGE_NAME, - 'fieldName' => self::INPUT_EXTENDED__NAME, + 'fieldName' => $this->makeCouponFieldName(self::INPUT_PERCENTAGE_NAME), 'value' => $this->percentage ]); } + + /** + * Return a list of the fields name for this coupon. + * + * @return array + */ + protected function getFieldList() { + return [self::INPUT_PERCENTAGE_NAME]; + } } diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 688e8a6ba..acb16ce70 100644 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -33,6 +33,8 @@ use Thelia\Module\BaseModule; */ class CouponCreationForm extends BaseForm { + const COUPON_CREATION_FORM_NAME = 'thelia_coupon_creation'; + /** * Build Coupon form * @@ -110,14 +112,6 @@ class CouponCreationForm extends BaseForm ) ) ) - ->add( - 'amount', - 'money', - array( - 'constraints' => array( - new NotBlank() - )) - ) ->add( 'isEnabled', 'text', @@ -198,7 +192,12 @@ class CouponCreationForm extends BaseForm new NotBlank() ) ) - ); + ) + ->add('coupon_specific', 'collection', array( + 'allow_add' => true, + 'allow_delete' => true, + )) + ; } /** @@ -226,6 +225,6 @@ class CouponCreationForm extends BaseForm */ public function getName() { - return 'thelia_coupon_creation'; + return self::COUPON_CREATION_FORM_NAME; } } diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 45f701876..921078eda 100644 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -184,7 +184,8 @@ class Coupon extends BaseCoupon */ public function getAmount() { - $amount = $this->getEffects()['amount']; + // Amount is now optional + $amount = isset($this->getEffects()['amount']) ? $this->getEffects()['amount'] : 0; return floatval($amount); } @@ -199,10 +200,6 @@ class Coupon extends BaseCoupon { $effects = $this->unserializeEffects($this->getSerializedEffects()); - if (null === $effects['amount']) { - throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect coming from database'); - } - return $effects; } @@ -210,18 +207,12 @@ class Coupon extends BaseCoupon * Get the Coupon effects * * @param array $effects Effect ready to be serialized - * Needs at least the key 'amount' - * with the amount removed from the cart * * @throws Exception\InvalidArgumentException * @return $this */ public function setEffects(array $effects) { - if (null === $effects['amount']) { - throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array'); - } - $this->setSerializedEffects($this->serializeEffects($effects)); return $this; diff --git a/templates/backOffice/default/coupon/form.html b/templates/backOffice/default/coupon/form.html index 19ed9254e..bdb8b7226 100644 --- a/templates/backOffice/default/coupon/form.html +++ b/templates/backOffice/default/coupon/form.html @@ -181,9 +181,7 @@ {/form_field}
- {form_field form=$form field='amount'} {$couponInputsHtml nofilter} - {/form_field}
diff --git a/templates/backOffice/default/coupon/type-fragments/remove-amount-on-categories.html b/templates/backOffice/default/coupon/type-fragments/remove-amount-on-categories.html index b14a171a5..396a1ef01 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-amount-on-categories.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-amount-on-categories.html @@ -1,7 +1,11 @@ -
- + +
+ + +
- + + {loop type="currency" name="get-symbol" default_only="true"}
{$SYMBOL}
{/loop} @@ -9,11 +13,14 @@
- - {loop type="category-tree" category=0 name="list-of-categories" backend_context="1"} - + {/loop} + {intl l='Use Ctrl+click to select (or deselect) more that one category'}
diff --git a/templates/backOffice/default/coupon/type-fragments/remove-x-amount.html b/templates/backOffice/default/coupon/type-fragments/remove-x-amount.html index 6159af73f..fe9cf285f 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-x-amount.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-x-amount.html @@ -1,9 +1,11 @@ -
- +
+ +
- + + {loop type="currency" name="get-symbol" default_only="true"} -
{$SYMBOL}
+
{$SYMBOL}
{/loop}
diff --git a/templates/backOffice/default/coupon/type-fragments/remove-x-percent.html b/templates/backOffice/default/coupon/type-fragments/remove-x-percent.html index 4c7c8d9d9..f06b42a6a 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-x-percent.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-x-percent.html @@ -1,8 +1,9 @@ - -
- +
+ + +
- +
%
diff --git a/templates/backOffice/default/coupon/type-fragments/remove-x.html b/templates/backOffice/default/coupon/type-fragments/remove-x.html index 3ac1bab7b..05a606d5a 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-x.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-x.html @@ -1,4 +1,4 @@ -
- - +
+ +
From 06307a8c1a6cf81b4a93a86a93f5d81682000f45 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 30 May 2014 20:12:23 +0200 Subject: [PATCH 02/23] Removed no longer useful tests --- .../Tests/Coupon/Type/RemoveXAmountTest.php | 16 ---------------- .../Tests/Coupon/Type/RemoveXPercentTest.php | 18 ------------------ 2 files changed, 34 deletions(-) diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index ed03a6fc3..730250967 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -196,22 +196,6 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } - /** - * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip - */ - public function testGetInputName() - { - $inputName = 'Amount removed from the cart'; - $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); - - /** @var FacadeInterface $stubFacade */ - $coupon = new RemoveXAmount($stubFacade); - - $actual = $coupon->getInputName(); - $expected = $inputName; - $this->assertEquals($expected, $actual); - } - /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index 2b36d27a2..5b58f59a7 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -152,8 +152,6 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(254, $coupon->getMaxUsage()); $this->assertEquals($date, $coupon->getExpirationDate()); - $this->assertEquals(array(RemoveXPercent::INPUT_PERCENTAGE_NAME), $coupon->getExtendedInputs()); - $this->assertEquals(40.00, $coupon->exec()); } @@ -188,22 +186,6 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } - /** - * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip - */ - public function testGetInputName() - { - $inputName = 'Percentage removed from the cart'; - $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); - - /** @var FacadeInterface $stubFacade */ - $coupon = new RemoveXPercent($stubFacade); - - $actual = $coupon->getInputName(); - $expected = $inputName; - $this->assertEquals($expected, $actual); - } - /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. From a862c5918985e67e24a0d573047173c6d8c4496d Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 30 May 2014 20:12:41 +0200 Subject: [PATCH 03/23] Fixed coupon input field name --- setup/faker.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup/faker.php b/setup/faker.php index 6843097b7..08da3889a 100644 --- a/setup/faker.php +++ b/setup/faker.php @@ -685,7 +685,7 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon1->setEffects(array( - RemoveXAmount::INPUT_AMOUNT_NAME => 10.00, + RemoveXAmount::AMOUNT_FIELD_NAME => 10.00, )); $coupon1->setIsUsed(true); $coupon1->setIsEnabled(true); @@ -744,8 +744,7 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon2->setEffects(array( - RemoveXPercent::INPUT_AMOUNT_NAME => 0.00, - RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00, + RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00 )); $coupon2->setIsUsed(true); $coupon2->setIsEnabled(true); @@ -790,7 +789,6 @@ Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentes Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'); $coupon3->setEffects(array( - RemoveXPercent::INPUT_AMOUNT_NAME => 0.00, RemoveXPercent::INPUT_PERCENTAGE_NAME => 10.00, )); $coupon3->setIsUsed(false); From 37e2f639d790e301e5051dad9caf545ce80006ab Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 30 May 2014 20:17:41 +0200 Subject: [PATCH 04/23] Checked coupon type before trying to get the service. --- .../Controller/Admin/CouponController.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index abf3177aa..db199c23a 100644 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -622,16 +622,21 @@ class CouponController extends BaseAdminController return $response; } - $this->checkXmlHttpRequest(); + if (! empty($couponServiceId)) { + $this->checkXmlHttpRequest(); - /** @var CouponInterface $coupon */ - $couponManager = $this->container->get($couponServiceId); + /** @var CouponInterface $coupon */ + $couponManager = $this->container->get($couponServiceId); - if (!$couponManager instanceof CouponInterface) { - $this->pageNotFound(); + if (!$couponManager instanceof CouponInterface) { + $this->pageNotFound(); + } + + $response = new ResponseRest($couponManager->drawBackOfficeInputs()); + } + else { + $response = new ResponseRest(''); } - - $response = new ResponseRest($couponManager->drawBackOfficeInputs()); return $response; } From 04b5b5e6b5bf7ddb9e788f306f40926fc6de78d2 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 31 May 2014 15:41:51 +0200 Subject: [PATCH 05/23] PHP-CS fixer --- .../Controller/Admin/CouponController.php | 5 ++- core/lib/Thelia/Core/Event/SessionEvent.php | 4 +- .../Core/EventListener/SessionListener.php | 3 +- core/lib/Thelia/Core/TheliaKernelEvents.php | 3 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 37 ++++++++++--------- .../Thelia/Coupon/Type/CouponInterface.php | 1 - .../Coupon/Type/RemoveAmountOnCategories.php | 36 ++++++++++++++---- core/lib/Thelia/Coupon/Type/RemoveXAmount.php | 5 ++- .../lib/Thelia/Coupon/Type/RemoveXPercent.php | 3 +- 9 files changed, 60 insertions(+), 37 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index db199c23a..94c84775c 100644 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -633,8 +633,9 @@ class CouponController extends BaseAdminController } $response = new ResponseRest($couponManager->drawBackOfficeInputs()); - } - else { + } else { + // Return an empty response if the service ID is not defined + // Typically, when the user chooses "Please select a coupon type" $response = new ResponseRest(''); } diff --git a/core/lib/Thelia/Core/Event/SessionEvent.php b/core/lib/Thelia/Core/Event/SessionEvent.php index 6def3ac01..8503495cc 100644 --- a/core/lib/Thelia/Core/Event/SessionEvent.php +++ b/core/lib/Thelia/Core/Event/SessionEvent.php @@ -14,7 +14,6 @@ namespace Thelia\Core\Event; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; - /** * Class SessionEvent * @package Thelia\Core\Event @@ -71,5 +70,4 @@ class SessionEvent extends ActionEvent return $this->session; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/EventListener/SessionListener.php b/core/lib/Thelia/Core/EventListener/SessionListener.php index f8d1f809d..aafcc53ca 100644 --- a/core/lib/Thelia/Core/EventListener/SessionListener.php +++ b/core/lib/Thelia/Core/EventListener/SessionListener.php @@ -21,7 +21,6 @@ use Thelia\Core\HttpFoundation\Session\Session; use Thelia\Core\TheliaKernelEvents; use Thelia\Model\ConfigQuery; - /** * Class SessionListener * @package Thelia\Core\EventListener @@ -79,4 +78,4 @@ class SessionListener implements EventSubscriberInterface ] ]; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/TheliaKernelEvents.php b/core/lib/Thelia/Core/TheliaKernelEvents.php index d1d3fe276..2348d55d9 100644 --- a/core/lib/Thelia/Core/TheliaKernelEvents.php +++ b/core/lib/Thelia/Core/TheliaKernelEvents.php @@ -12,7 +12,6 @@ namespace Thelia\Core; - /** * Class TheliaKernelEvents * @package Thelia\Core @@ -23,4 +22,4 @@ final class TheliaKernelEvents const SESSION = "thelia_kernel.session"; -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index d04c29b89..02336cc2e 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -402,7 +402,8 @@ abstract class CouponAbstract implements CouponInterface * * @return string */ - public function getInputName() { + public function getInputName() + { return "Please override getInputName() method"; } @@ -434,33 +435,32 @@ abstract class CouponAbstract implements CouponInterface * @return mixed * @throws \InvalidArgumentException if the field valiue is not valid. */ - protected function checkCouponFieldValue($fieldName, $fieldValue) { + protected function checkCouponFieldValue($fieldName, $fieldValue) + { return $fieldValue; } /** * A helper to get the value of a standard field name * - * @param string $fieldName the field name - * @param array $data the input form data (e.g. $form->getData()) - * @param mixed $defaultValue the default value if the field is not found. + * @param string $fieldName the field name + * @param array $data the input form data (e.g. $form->getData()) + * @param mixed $defaultValue the default value if the field is not found. * * @return mixed the input value, or the default one * * @throws \InvalidArgumentException if the field is not found, and no default value has been defined. */ - protected function getCouponFieldValue($fieldName, $data, $defaultValue = null) { + protected function getCouponFieldValue($fieldName, $data, $defaultValue = null) + { if (isset($data[self::COUPON_DATASET_NAME][$fieldName])) { - return $this->checkCouponFieldValue( $fieldName, $data[self::COUPON_DATASET_NAME][$fieldName] ); - } - else if (null !== $defaultValue) { + } elseif (null !== $defaultValue) { return $defaultValue; - } - else { + } else { throw new \InvalidArgumentException(sprintf("The coupon field name %s was not found in the coupon form", $fieldName)); } } @@ -468,10 +468,11 @@ abstract class CouponAbstract implements CouponInterface /** * A helper to create an standard field name that will be used in the coupon form * - * @param string $fieldName the field name + * @param string $fieldName the field name * @return string the complete name, ready to be used in a form. */ - protected function makeCouponFieldName($fieldName) { + protected function makeCouponFieldName($fieldName) + { return sprintf("%s[%s][%s]", CouponCreationForm::COUPON_CREATION_FORM_NAME, self::COUPON_DATASET_NAME, $fieldName); } @@ -480,20 +481,22 @@ abstract class CouponAbstract implements CouponInterface * * @return array */ - protected function getFieldList() { + protected function getFieldList() + { return [self::AMOUNT_FIELD_NAME]; } /** * Create the effect array from the list of fields * - * @param array $data the input form data (e.g. $form->getData()) + * @param array $data the input form data (e.g. $form->getData()) * @return array a filedName => fieldValue array */ - public function getEffects($data) { + public function getEffects($data) + { $effects = []; - foreach($this->getFieldList() as $fieldName) { + foreach ($this->getFieldList() as $fieldName) { $effects[$fieldName] = $this->getCouponFieldValue($fieldName, $data); } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index f9acc973d..a9382749f 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -15,7 +15,6 @@ namespace Thelia\Coupon\Type; use Propel\Runtime\Collection\ObjectCollection; use Thelia\Condition\ConditionCollection; use Thelia\Coupon\FacadeInterface; -use Thelia\Form\CouponCreationForm; /** * Represents a Coupon ready to be processed in a Checkout process diff --git a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php index 9994219e2..665a02bff 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php +++ b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php @@ -14,6 +14,8 @@ namespace Thelia\Coupon\Type; use Thelia\Core\Translation\Translator; use Thelia\Coupon\FacadeInterface; +use Thelia\Model\CartItem; +use Thelia\Model\Category; /** * Allow to remove an amount from the checkout total @@ -29,7 +31,7 @@ class RemoveAmountOnCategories extends CouponAbstract /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories'; - var $category_list = array(); + public $category_list = array(); /** * @inheritdoc @@ -105,8 +107,29 @@ class RemoveAmountOnCategories extends CouponAbstract */ public function exec() { - // TODO !!! - return $this->amount; + // This coupon subtracts the specified amount from the order total + // for each product of the selected categories. + $discount = 0; + + $cartItems = $this->facade->getCart()->getCartItems(); + + /** @var CartItem $cartItem */ + foreach ($cartItems as $cartItem) { + + $categories = $cartItem->getProduct()->getCategories(); + + /** @var Category $category */ + foreach ($categories as $category) { + + if (in_array($category->getId(), $this->category_list)) { + $discount += $cartItem->getQuantity() * $this->amount; + + break; + } + } + } + + return $discount; } public function drawBackOfficeInputs() @@ -131,11 +154,11 @@ class RemoveAmountOnCategories extends CouponAbstract * * @return array */ - protected function getFieldList() { + protected function getFieldList() + { return [self::AMOUNT_FIELD_NAME, self::CATEGORIES_LIST]; } - /** * @inheritdoc */ @@ -151,8 +174,7 @@ class RemoveAmountOnCategories extends CouponAbstract ) ); } - } - else if ($fieldName === self::CATEGORIES_LIST) { + } elseif ($fieldName === self::CATEGORIES_LIST) { if (empty($fieldValue)) { throw new \InvalidArgumentException( Translator::getInstance()->trans( diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php index fe5322e22..1f83c6eec 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php @@ -69,7 +69,8 @@ class RemoveXAmount extends CouponAbstract * * @return array */ - protected function getFieldList() { + protected function getFieldList() + { return [self::AMOUNT_FIELD_NAME]; } @@ -93,4 +94,4 @@ class RemoveXAmount extends CouponAbstract return $fieldValue; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php index 06c73981a..e1cc20252 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php @@ -152,7 +152,8 @@ class RemoveXPercent extends CouponAbstract * * @return array */ - protected function getFieldList() { + protected function getFieldList() + { return [self::INPUT_PERCENTAGE_NAME]; } } From 413df429411ce3e917d9b76bb6d2dcfe95c27b08 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 31 May 2014 16:27:32 +0200 Subject: [PATCH 06/23] Added "js" parameter to intl function for a safe usage in JS string, --- .../Core/Template/Smarty/Plugins/Translation.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php index aa66c114f..22ba0d14f 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php @@ -47,20 +47,26 @@ class Translation extends AbstractSmartyPlugin */ public function translate($params, &$smarty) { - // All parameters other than 'l' and 'd' are supposed to be variables. Build an array of var => value pairs + // All parameters other than 'l' and 'd' and 'js' are supposed to be variables. Build an array of var => value pairs // and pass it to the translator $vars = array(); foreach ($params as $name => $value) { - if ($name != 'l' && $name != 'd') $vars["%$name"] = $value; + if ($name != 'l' && $name != 'd' && $name != 'js') $vars["%$name"] = $value; } - return $this->translator->trans( + $str = $this->translator->trans( $this->getParam($params, 'l'), $vars, $this->getParam($params, 'd', $this->defaultTranslationDomain) ); -} + + if ($this->getParam($params, 'js', 0)) { + $str = preg_replace("/(['\"])/", "\\\\$1", $str); + } + + return $str; + } /** * Define the various smarty plugins handled by this class From 1a3cc6896a1801c6d614a0660e45b05dc5e335db Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Wed, 4 Jun 2014 16:14:04 +0200 Subject: [PATCH 07/23] Changed "return_to" into "previous" --- core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 03d605358..8a6bc5e5b 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -153,7 +153,7 @@ class UrlGenerator extends AbstractSmartyPlugin { return array( "current" => "getCurrentUrl", - "return_to" => "getReturnToUrl", + "previous " => "getPreviousUrl", "index" => "getIndexUrl", ); } @@ -178,7 +178,7 @@ class UrlGenerator extends AbstractSmartyPlugin return $this->request->getUri(); } - protected function getReturnToUrl() + protected function getPreviousUrl() { return URL::getInstance()->absoluteUrl($this->request->getSession()->getReturnToUrl()); } From eb23187782d59480cbd57addcb731ac7aabdf1b4 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 5 Jun 2014 18:49:40 +0200 Subject: [PATCH 08/23] replaced ucfirst by underscoreToCamelcase for calculating method name --- .../Smarty/Plugins/DataAccessFunctions.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 588cbe76d..656817efc 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -402,7 +402,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin return $noGetterData[$keyAttribute]; } - $getter = sprintf("get%s", ucfirst($attribute)); + $getter = sprintf("get%s", underscoreToCamelcase($attribute)); if (method_exists($data, $getter)) { $return = $data->$getter(); @@ -427,6 +427,26 @@ class DataAccessFunctions extends AbstractSmartyPlugin return ''; } + /** + * Transcode an underscored string into a camel-cased string, eg. default_folder into DefaultFolder + * + * @param string $str the string to convert from underscore to camel-case + * + * @return string the camel cased string. + */ + private function underscoreToCamelcase($str) { + // Split string in words. + $words = explode('_', strtolower($str)); + + $return = ''; + + foreach ($words as $word) { + $return .= ucfirst(trim($word)); + } + + return $return; + } + /** * Define the various smarty plugins hendled by this class * From 49411183da7efc3cabb7415d2590fc85c56e6a6d Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 10 Jun 2014 15:52:08 +0200 Subject: [PATCH 09/23] Fixed InvalidArgumentException: No module found for code 'default' --- templates/backOffice/default/translations.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/backOffice/default/translations.html b/templates/backOffice/default/translations.html index fbe0321d4..c09017e64 100644 --- a/templates/backOffice/default/translations.html +++ b/templates/backOffice/default/translations.html @@ -48,7 +48,7 @@ - +
@@ -299,6 +299,7 @@ $('#item_to_translate').change(function() { $('#item-id').val(''); + $('#item_name').val(''); $('.item-id-selector').hide(); }); @@ -321,7 +322,7 @@ translation_changed = true; ev.preventDefault(); - }) + }); $('#translation_form').submit(function(ev) { From 4ab3149bca7a218530b61df18d2cfe8998363bc9 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 10 Jun 2014 15:54:42 +0200 Subject: [PATCH 10/23] Changed {navigate to="return_to"} to {navigate to="previous"} --- templates/frontOffice/default/index.html | 1 + templates/frontOffice/default/login.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/frontOffice/default/index.html b/templates/frontOffice/default/index.html index 53aa8c0f1..f5bcfa668 100644 --- a/templates/frontOffice/default/index.html +++ b/templates/frontOffice/default/index.html @@ -12,6 +12,7 @@ {block name='breadcrumb'}{/block} {block name="main-content"} + u={viewurl view="legal"}