Refactored coupons to reduce code duplication

This commit is contained in:
Franck Allimant
2014-06-12 13:14:46 +02:00
parent db29505fee
commit 95841809c4
13 changed files with 502 additions and 550 deletions

View File

@@ -0,0 +1,150 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Coupon\Type;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\CartItem;
/**
* Allow to remove an amount from the checkout total
*
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
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;
}
}

View File

@@ -0,0 +1,162 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Coupon\Type;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\CartItem;
/**
* Allow to remove an amount from the checkout total
*
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
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;
}
}

View File

@@ -21,56 +21,30 @@ use Thelia\Model\Category;
* Allow to remove an amount from the checkout total
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
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;
}
}

View File

@@ -21,56 +21,25 @@ use Thelia\Model\Product;
* Allow to remove an amount from the checkout total
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
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;
}
}
}

View File

@@ -19,54 +19,28 @@ use Thelia\Model\Category;
/**
* @author Franck Allimant <franck@cqfdev.fr>
*
*/
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;

View File

@@ -21,60 +21,30 @@ use Thelia\Model\Product;
* Allow to remove an amount from the checkout total
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
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;
}
}
}