diff --git a/core/lib/Thelia/Coupon/Type/AbstractRemoveOnCategories.php b/core/lib/Thelia/Coupon/Type/AbstractRemoveOnCategories.php new file mode 100644 index 000000000..6d6622126 --- /dev/null +++ b/core/lib/Thelia/Coupon/Type/AbstractRemoveOnCategories.php @@ -0,0 +1,150 @@ + + */ +abstract class AbstractRemoveOnCategories extends CouponAbstract +{ + const CATEGORIES_LIST = 'categories'; + + protected $category_list = array(); + + /** + * Set the value of specific coupon fields. + * + * @param Array $effects the Coupon effects params + */ + protected abstract function setFieldsValue($effects); + + /** + * Get the discount for a specific cart item. + * + * @param CartItem $cartItem the cart item + * @return float the discount value + */ + protected abstract function getCartItemDiscount($cartItem); + + /** + * @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; + } + /** + * @inheritdoc + */ + public function exec() + { + // 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) { + if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { + $categories = $cartItem->getProduct()->getCategories(); + + /** @var Category $category */ + foreach ($categories as $category) { + + if (in_array($category->getId(), $this->category_list)) { + $discount += $this->getCartItemDiscount($cartItem); + + break; + } + } + } + } + + return $discount; + } + + /** + * @inheritdoc + */ + public function drawBaseBackOfficeInputs($templateName, $otherFields) + { + return $this->facade->getParser()->render($templateName, array_merge($otherFields, [ + + // The categories list field + 'categories_field_name' => $this->makeCouponFieldName(self::CATEGORIES_LIST), + 'categories_values' => $this->category_list + ])); + } + + /** + * @inheritdoc + */ + protected function getBaseFieldList($otherFields) + { + return array_merge($otherFields, [self::CATEGORIES_LIST]); + } + + /** + * @inheritdoc + */ + protected function checkBaseCouponFieldValue($fieldName, $fieldValue) + { + if ($fieldName === self::CATEGORIES_LIST) { + if (empty($fieldValue)) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Please select at least one category' + ) + ); + } + } + + return $fieldValue; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/AbstractRemoveOnProducts.php b/core/lib/Thelia/Coupon/Type/AbstractRemoveOnProducts.php new file mode 100644 index 000000000..2bb5ecea8 --- /dev/null +++ b/core/lib/Thelia/Coupon/Type/AbstractRemoveOnProducts.php @@ -0,0 +1,162 @@ + + */ +abstract class AbstractRemoveOnProducts extends CouponAbstract +{ + const CATEGORY_ID = 'category_id'; + const PRODUCTS_LIST = 'products'; + + public $category_id = 0; + public $product_list = array(); + + /** + * Set the value of specific coupon fields. + * + * @param Array $effects the Coupon effects params + */ + protected abstract function setFieldsValue($effects); + + /** + * Get the discount for a specific cart item. + * + * @param CartItem $cartItem the cart item + * @return float the discount value + */ + protected abstract function getCartItemDiscount($cartItem); + + /** + * @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->product_list = isset($effects[self::PRODUCTS_LIST]) ? $effects[self::PRODUCTS_LIST] : array(); + + if (! is_array($this->product_list)) $this->product_list = array($this->product_list); + + $this->category_id = isset($effects[self::CATEGORY_ID]) ? $effects[self::CATEGORY_ID] : 0; + + $this->setFieldsValue($effects); + + return $this; + } + + /** + * @inheritdoc + */ + public function exec() + { + // This coupon subtracts the specified amount from the order total + // for each product of the selected products. + $discount = 0; + + $cartItems = $this->facade->getCart()->getCartItems(); + + /** @var CartItem $cartItem */ + foreach ($cartItems as $cartItem) { + if (in_array($cartItem->getProduct()->getId(), $this->product_list)) { + if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { + $discount += $this->getCartItemDiscount($cartItem); + } + } + } + + return $discount; + } + + /** + * @inheritdoc + */ + public function drawBaseBackOfficeInputs($templateName, $otherFields) + { + return $this->facade->getParser()->render($templateName, array_merge($otherFields, [ + + // The category ID field + 'category_id_field_name' => $this->makeCouponFieldName(self::CATEGORY_ID), + 'category_id_value' => $this->category_id, + + // The products list field + 'products_field_name' => $this->makeCouponFieldName(self::PRODUCTS_LIST), + 'products_values' => $this->product_list, + 'products_values_csv' => implode(', ', $this->product_list) + ])); + } + + /** + * @inheritdoc + */ + protected function getBaseFieldList($otherFields) + { + return array_merge($otherFields, [self::CATEGORY_ID, self::PRODUCTS_LIST]); + } + + /** + * @inheritdoc + */ + protected function checkBaseCouponFieldValue($fieldName, $fieldValue) + { + if ($fieldName === self::CATEGORY_ID) { + if (empty($fieldValue)) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Please select a category' + ) + ); + } + } elseif ($fieldName === self::PRODUCTS_LIST) { + if (empty($fieldValue)) { + throw new \InvalidArgumentException( + Translator::getInstance()->trans( + 'Please select at least one product' + ) + ); + } + } + + return $fieldValue; + } +} diff --git a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php index d65b462f7..e5f3070b0 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php +++ b/core/lib/Thelia/Coupon/Type/RemoveAmountOnCategories.php @@ -21,56 +21,30 @@ use Thelia\Model\Category; * Allow to remove an amount from the checkout total * * @package Coupon - * @author Guillaume MOREL - * + * @author Franck Allimant */ -class RemoveAmountOnCategories extends CouponAbstract +class RemoveAmountOnCategories extends AbstractRemoveOnCategories { - const CATEGORIES_LIST = 'categories'; - /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_amount_on_categories'; - public $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; + protected function setFieldsValue($effects) { + // Nothing to do, the amount is processed by CouponAbstract. } /** * @inheritdoc */ + public function getCartItemDiscount($cartItem) { + return $cartItem->getQuantity() * $this->amount; + } + + /** + * @inheritdoc + */ public function getName() { return $this->facade @@ -94,53 +68,15 @@ class RemoveAmountOnCategories extends CouponAbstract return $toolTip; } - /** - * @inheritdoc - */ - public function exec() - { - // 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) { - - if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { - $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; - } - /** * @inheritdoc */ public function drawBackOfficeInputs() { - return $this->facade->getParser()->render('coupon/type-fragments/remove-amount-on-categories.html', [ - - // The standard "Amount" field - 'amount_field_name' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), - 'amount_value' => $this->amount, - - // The categories list field - 'categories_field_name' => $this->makeCouponFieldName(self::CATEGORIES_LIST), - 'categories_values' => $this->category_list - ]); + return $this->drawBaseBackOfficeInputs('coupon/type-fragments/remove-amount-on-categories.html', [ + 'amount_field_name' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), + 'amount_value' => $this->amount + ]); } /** @@ -148,7 +84,7 @@ class RemoveAmountOnCategories extends CouponAbstract */ protected function getFieldList() { - return [self::AMOUNT_FIELD_NAME, self::CATEGORIES_LIST]; + return $this->getBaseFieldList([self::AMOUNT_FIELD_NAME]); } /** @@ -156,6 +92,8 @@ class RemoveAmountOnCategories extends CouponAbstract */ protected function checkCouponFieldValue($fieldName, $fieldValue) { + $this->checkBaseCouponFieldValue($fieldName, $fieldValue); + if ($fieldName === self::AMOUNT_FIELD_NAME) { if (floatval($fieldValue) < 0) { @@ -166,17 +104,8 @@ class RemoveAmountOnCategories extends CouponAbstract ) ); } - } elseif ($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/RemoveAmountOnProducts.php b/core/lib/Thelia/Coupon/Type/RemoveAmountOnProducts.php index 9a3fb8b93..1061171e6 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveAmountOnProducts.php +++ b/core/lib/Thelia/Coupon/Type/RemoveAmountOnProducts.php @@ -21,56 +21,25 @@ use Thelia\Model\Product; * Allow to remove an amount from the checkout total * * @package Coupon - * @author Guillaume MOREL - * + * @author Franck Allimant */ -class RemoveAmountOnProducts extends CouponAbstract +class RemoveAmountOnProducts extends AbstractRemoveOnProducts { - const CATEGORY_ID = 'category_id'; - const PRODUCTS_LIST = 'products'; - /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_amount_on_products'; - public $category_id = 0; - public $product_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 - ); + protected function setFieldsValue($effects) { + // Nothing to do: amount is processed by CouponAbstract + } - $this->product_list = isset($effects[self::PRODUCTS_LIST]) ? $effects[self::PRODUCTS_LIST] : array(); - - if (! is_array($this->product_list)) $this->product_list = array($this->product_list); - - $this->category_id = isset($effects[self::CATEGORY_ID]) ? $effects[self::CATEGORY_ID] : 0; - - return $this; + /** + * @inheritdoc + */ + protected function getCartItemDiscount($cartItem) { + return $cartItem->getQuantity() * $this->amount; } /** @@ -101,58 +70,23 @@ class RemoveAmountOnProducts extends CouponAbstract return $toolTip; } - /** - * @inheritdoc - */ - public function exec() - { - // This coupon subtracts the specified amount from the order total - // for each product of the selected products. - $discount = 0; - - $cartItems = $this->facade->getCart()->getCartItems(); - - /** @var CartItem $cartItem */ - foreach ($cartItems as $cartItem) { - - if (in_array($cartItem->getProduct()->getId(), $this->product_list)) { - if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { - $discount += $cartItem->getQuantity() * $this->amount; - } - } - } - - return $discount; - } - /** * @inheritdoc */ public function drawBackOfficeInputs() { - return $this->facade->getParser()->render('coupon/type-fragments/remove-amount-on-products.html', [ - - // The standard "Amount" field - 'amount_field_name' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), - 'amount_value' => $this->amount, - - // The category ID field - 'category_id_field_name' => $this->makeCouponFieldName(self::CATEGORY_ID), - 'category_id_value' => $this->category_id, - - // The products list field - 'products_field_name' => $this->makeCouponFieldName(self::PRODUCTS_LIST), - 'products_values' => $this->product_list, - 'products_values_csv' => implode(', ', $this->product_list) + return $this->drawBaseBackOfficeInputs('coupon/type-fragments/remove-amount-on-products.html', [ + 'amount_field_name' => $this->makeCouponFieldName(self::AMOUNT_FIELD_NAME), + 'amount_value' => $this->amount ]); - } + } /** * @inheritdoc */ protected function getFieldList() { - return [self::AMOUNT_FIELD_NAME, self::CATEGORY_ID, self::PRODUCTS_LIST]; + return $this->getBaseFieldList([self::AMOUNT_FIELD_NAME]); } /** @@ -160,6 +94,8 @@ class RemoveAmountOnProducts extends CouponAbstract */ protected function checkCouponFieldValue($fieldName, $fieldValue) { + $this->checkBaseCouponFieldValue($fieldName, $fieldValue); + if ($fieldName === self::AMOUNT_FIELD_NAME) { if (floatval($fieldValue) < 0) { @@ -170,24 +106,8 @@ class RemoveAmountOnProducts extends CouponAbstract ) ); } - } elseif ($fieldName === self::CATEGORY_ID) { - if (empty($fieldValue)) { - throw new \InvalidArgumentException( - Translator::getInstance()->trans( - 'Please select a category' - ) - ); - } - } elseif ($fieldName === self::PRODUCTS_LIST) { - if (empty($fieldValue)) { - throw new \InvalidArgumentException( - Translator::getInstance()->trans( - 'Please select at least one product' - ) - ); - } } return $fieldValue; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/RemovePercentageOnCategories.php b/core/lib/Thelia/Coupon/Type/RemovePercentageOnCategories.php index 892984a14..dc5a533bd 100644 --- a/core/lib/Thelia/Coupon/Type/RemovePercentageOnCategories.php +++ b/core/lib/Thelia/Coupon/Type/RemovePercentageOnCategories.php @@ -19,54 +19,28 @@ use Thelia\Model\Category; /** * @author Franck Allimant - * */ -class RemovePercentageOnCategories extends CouponAbstract +class RemovePercentageOnCategories extends AbstractRemoveOnCategories { - const CATEGORIES_LIST = 'categories'; const PERCENTAGE = 'percentage'; /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_percentage_on_categories'; - protected $category_list = array(); - protected $percentage = 0; /** * @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 - ); + protected function setFieldsValue($effects) { + $this->percentage = $effects[self::PERCENTAGE]; + } - $this->category_list = isset($effects[self::CATEGORIES_LIST]) ? $effects[self::CATEGORIES_LIST] : array(); - $this->percentage = isset($effects[self::PERCENTAGE]) ? $effects[self::PERCENTAGE] : 0; - - if (! is_array($this->category_list)) $this->category_list = array($this->category_list); - return $this; + /** + * @inheritdoc + */ + public function getCartItemDiscount($cartItem) { + return $cartItem->getQuantity() * $cartItem->getPrice() * $this->percentage; } /** @@ -95,52 +69,15 @@ class RemovePercentageOnCategories extends CouponAbstract return $toolTip; } - /** - * @inheritdoc - */ - public function exec() - { - // 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) { - if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { - $categories = $cartItem->getProduct()->getCategories(); - - /** @var Category $category */ - foreach ($categories as $category) { - - if (in_array($category->getId(), $this->category_list)) { - $discount += $cartItem->getPrice() * $this->percentage; - - break; - } - } - } - } - - return $discount; - } - /** * @inheritdoc */ public function drawBackOfficeInputs() { - return $this->facade->getParser()->render('coupon/type-fragments/remove-percentage-on-categories.html', [ - - // The standard "Amount" field - 'percentage_field_name' => $this->makeCouponFieldName(self::PERCENTAGE), - 'percentage_value' => $this->percentage, - - // The categories list field - 'categories_field_name' => $this->makeCouponFieldName(self::CATEGORIES_LIST), - 'categories_values' => $this->category_list - ]); + return $this->drawBaseBackOfficeInputs('coupon/type-fragments/remove-percentage-on-categories.html', [ + 'percentage_field_name' => $this->makeCouponFieldName(self::PERCENTAGE), + 'percentage_value' => $this->percentage, + ]); } /** @@ -148,7 +85,7 @@ class RemovePercentageOnCategories extends CouponAbstract */ protected function getFieldList() { - return [self::PERCENTAGE, self::CATEGORIES_LIST]; + return $this->getBaseFieldList([self::PERCENTAGE]); } /** @@ -156,6 +93,8 @@ class RemovePercentageOnCategories extends CouponAbstract */ protected function checkCouponFieldValue($fieldName, $fieldValue) { + $this->checkBaseCouponFieldValue($fieldName, $fieldValue); + if ($fieldName === self::PERCENTAGE) { $pcent = floatval($fieldValue); @@ -168,14 +107,6 @@ class RemovePercentageOnCategories extends CouponAbstract ) ); } - } elseif ($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/RemovePercentageOnProducts.php b/core/lib/Thelia/Coupon/Type/RemovePercentageOnProducts.php index 030a87c23..332d0feed 100644 --- a/core/lib/Thelia/Coupon/Type/RemovePercentageOnProducts.php +++ b/core/lib/Thelia/Coupon/Type/RemovePercentageOnProducts.php @@ -21,60 +21,30 @@ use Thelia\Model\Product; * Allow to remove an amount from the checkout total * * @package Coupon - * @author Guillaume MOREL - * + * @author Franck Allimant */ -class RemovePercentageOnProducts extends CouponAbstract +class RemovePercentageOnProducts extends AbstractRemoveOnProducts { - const CATEGORY_ID = 'category_id'; - const PRODUCTS_LIST = 'products'; - const PERCENTAGE = 'percentage'; + const PERCENTAGE = 'percentage'; /** @var string Service Id */ protected $serviceId = 'thelia.coupon.type.remove_percentage_on_products'; - public $category_id = 0; - public $product_list = array(); public $percentage = 0; /** * @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->product_list = isset($effects[self::PRODUCTS_LIST]) ? $effects[self::PRODUCTS_LIST] : array(); - - if (! is_array($this->product_list)) $this->product_list = array($this->product_list); - - $this->category_id = isset($effects[self::CATEGORY_ID]) ? $effects[self::CATEGORY_ID] : 0; + protected function setFieldsValue($effects) { $this->percentage = $effects[self::PERCENTAGE]; + } - return $this; + /** + * @inheritdoc + */ + protected function getCartItemDiscount($cartItem) { + return $cartItem->getQuantity() * $cartItem->getPrice() * $this->percentage; } /** @@ -105,49 +75,15 @@ class RemovePercentageOnProducts extends CouponAbstract return $toolTip; } - /** - * @inheritdoc - */ - public function exec() - { - // This coupon subtracts the specified amount from the order total - // for each product of the selected products. - $discount = 0; - - $cartItems = $this->facade->getCart()->getCartItems(); - - /** @var CartItem $cartItem */ - foreach ($cartItems as $cartItem) { - if (in_array($cartItem->getProduct()->getId(), $this->product_list)) { - if (! $cartItem->getPromo() || $this->isAvailableOnSpecialOffers()) { - $discount += $cartItem->getQuantity() * $cartItem->getPrice() * $this->percentage; - } - } - } - - return $discount; - } - /** * @inheritdoc */ public function drawBackOfficeInputs() { - return $this->facade->getParser()->render('coupon/type-fragments/remove-percentage-on-products.html', [ - - // The standard "Amount" field - 'percentage_field_name' => $this->makeCouponFieldName(self::PERCENTAGE), - 'percentage_value' => $this->percentage, - - // The category ID field - 'category_id_field_name' => $this->makeCouponFieldName(self::CATEGORY_ID), - 'category_id_value' => $this->category_id, - - // The products list field - 'products_field_name' => $this->makeCouponFieldName(self::PRODUCTS_LIST), - 'products_values' => $this->product_list, - 'products_values_csv' => implode(', ', $this->product_list) - ]); + return $this->drawBaseBackOfficeInputs('coupon/type-fragments/remove-percentage-on-products.html', [ + 'percentage_field_name' => $this->makeCouponFieldName(self::PERCENTAGE), + 'percentage_value' => $this->percentage, + ]); } /** @@ -155,7 +91,7 @@ class RemovePercentageOnProducts extends CouponAbstract */ protected function getFieldList() { - return [self::PERCENTAGE, self::CATEGORY_ID, self::PRODUCTS_LIST]; + return $this->getBaseFieldList([self::PERCENTAGE]); } /** @@ -163,6 +99,8 @@ class RemovePercentageOnProducts extends CouponAbstract */ protected function checkCouponFieldValue($fieldName, $fieldValue) { + $this->checkBaseCouponFieldValue($fieldName, $fieldValue); + if ($fieldName === self::PERCENTAGE) { $pcent = floatval($fieldValue); @@ -175,24 +113,8 @@ class RemovePercentageOnProducts extends CouponAbstract ) ); } - } elseif ($fieldName === self::CATEGORY_ID) { - if (empty($fieldValue)) { - throw new \InvalidArgumentException( - Translator::getInstance()->trans( - 'Please select a category' - ) - ); - } - } elseif ($fieldName === self::PRODUCTS_LIST) { - if (empty($fieldValue)) { - throw new \InvalidArgumentException( - Translator::getInstance()->trans( - 'Please select at least one product' - ) - ); - } } return $fieldValue; } -} +} \ No newline at end of file diff --git a/templates/backOffice/default/coupon/type-fragments/ajax-attribute-avs-list.html b/templates/backOffice/default/coupon/type-fragments/ajax-attribute-avs-list.html new file mode 100644 index 000000000..3033f94c9 --- /dev/null +++ b/templates/backOffice/default/coupon/type-fragments/ajax-attribute-avs-list.html @@ -0,0 +1,3 @@ +{loop type="attribute_availability" attribute={$smarty.post.attribute_id} name="list-of-attribute_avs" backend_context="1"} + +{/loop} \ No newline at end of file diff --git a/templates/backOffice/default/coupon/type-fragments/base-remove-on-categories.html b/templates/backOffice/default/coupon/type-fragments/base-remove-on-categories.html new file mode 100644 index 000000000..39b81e4c1 --- /dev/null +++ b/templates/backOffice/default/coupon/type-fragments/base-remove-on-categories.html @@ -0,0 +1,14 @@ +{block name="discount-field"}{/block} + +
+ + + + + + {intl l='Use Ctrl+click to select (or deselect) more that one category'} +
diff --git a/templates/backOffice/default/coupon/type-fragments/base-remove-on-products.html b/templates/backOffice/default/coupon/type-fragments/base-remove-on-products.html new file mode 100644 index 000000000..3f5cc4a94 --- /dev/null +++ b/templates/backOffice/default/coupon/type-fragments/base-remove-on-products.html @@ -0,0 +1,63 @@ +{block name="discount-field"}{/block} + +
+ + + + +
+ + + +
+ + + + + + {intl l='Use Ctrl+click to select (or deselect) more that one product'} +
+ + 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 15c528331..7f6a82c72 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,26 +1,16 @@ +{extends file="coupon/type-fragments/base-remove-on-categories.html"} -
+{block name="discount-field"} +
- + -
- +
+ - {loop type="currency" name="get-symbol" default_only="true"} -
{$SYMBOL}
- {/loop} + {loop type="currency" name="get-symbol" default_only="true"} +
{$SYMBOL}
+ {/loop} +
-
- -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
+{/block} \ No newline at end of file diff --git a/templates/backOffice/default/coupon/type-fragments/remove-amount-on-products.html b/templates/backOffice/default/coupon/type-fragments/remove-amount-on-products.html index 57d45684c..033adeee1 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-amount-on-products.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-amount-on-products.html @@ -1,77 +1,16 @@ +{extends file="coupon/type-fragments/base-remove-on-products.html"} -
+{block name="discount-field"} +
- + -
- +
+ - {loop type="currency" name="get-symbol" default_only="true"} -
{$SYMBOL}
- {/loop} + {loop type="currency" name="get-symbol" default_only="true"} +
{$SYMBOL}
+ {/loop} +
-
- -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
- - - -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
- - +{/block} \ No newline at end of file diff --git a/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-categories.html b/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-categories.html index 08c3655f1..8a45e1a7a 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-categories.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-categories.html @@ -1,24 +1,14 @@ +{extends file="coupon/type-fragments/base-remove-on-categories.html"} -
+{block name="discount-field"} +
- + -
- +
+ -
%
+
%
+
-
- -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
+{/block} \ No newline at end of file diff --git a/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-products.html b/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-products.html index 4787da2ee..f60b2bf11 100644 --- a/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-products.html +++ b/templates/backOffice/default/coupon/type-fragments/remove-percentage-on-products.html @@ -1,75 +1,14 @@ +{extends file="coupon/type-fragments/base-remove-on-products.html"} -
+{block name="discount-field"} +
- + -
- +
+ -
%
+
%
+
-
- -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
- - - -
- - - - - - {intl l='Use Ctrl+click to select (or deselect) more that one category'} -
- - +{/block} \ No newline at end of file