WIP
- Add Coupon, Rules, CouponManager, Adapter as Services - Refactor Coupon to use these services
This commit is contained in:
@@ -62,30 +62,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
/** @var PriceParam Price Validator */
|
||||
protected $priceValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators)
|
||||
{
|
||||
parent::__construct($adapter, $validators);
|
||||
|
||||
if (isset($validators[self::PARAM1_PRICE])
|
||||
&& $validators[self::PARAM1_PRICE] instanceof RuleValidator
|
||||
) {
|
||||
$this->priceValidator = $validators[self::PARAM1_PRICE];
|
||||
} else {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
@@ -171,17 +147,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
* Serialization purpose
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
return $this->validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
@@ -203,13 +168,11 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
/** @var Translator $translator */
|
||||
$translator = $this->get('thelia.translator');
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$translator, $this->priceValidator->getOperator()
|
||||
$this->translator, $this->priceValidator->getOperator()
|
||||
);
|
||||
|
||||
$toolTip = $translator->trans(
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart total amount is <strong>%operator%</strong> %amount% %currency%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
|
||||
@@ -56,31 +56,6 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
/** @var QuantityParam Quantity Validator */
|
||||
protected $quantityValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*
|
||||
* @throws InvalidRuleException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators = null)
|
||||
{
|
||||
parent::__construct($adapter, $validators);
|
||||
|
||||
if (isset($validators[self::PARAM1_QUANTITY])
|
||||
&& $validators[self::PARAM1_QUANTITY] instanceof RuleValidator
|
||||
) {
|
||||
$this->quantityValidator = $validators[self::PARAM1_QUANTITY];
|
||||
} else {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
@@ -176,10 +151,7 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
/** @var Translator $translator */
|
||||
$translator = $this->adapter->get('thelia.translator');
|
||||
|
||||
return $translator->trans(
|
||||
return $this->translator->trans(
|
||||
'Number of articles in cart',
|
||||
array(),
|
||||
'constraint'
|
||||
@@ -193,14 +165,11 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
/** @var Translator $translator */
|
||||
$translator = $this->adapter->get('thelia.translator');
|
||||
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$translator, $this->priceValidator->getOperator()
|
||||
$this->translator, $this->priceValidator->getOperator()
|
||||
);
|
||||
|
||||
$toolTip = $translator->trans(
|
||||
$toolTip = $this->translator->trans(
|
||||
'If cart products quantity is <strong>%operator%</strong> %quantity%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
@@ -256,5 +225,4 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
return $serializableRule;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
@@ -60,29 +61,17 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Ex:
|
||||
* Param 1 :
|
||||
* $priceValidator = new RuleValidator(
|
||||
* Operators::INFERIOR,
|
||||
* new IntegerParam(10)
|
||||
* )
|
||||
* $validators[AvailableForTotalAmount::PARAM1_PRICE] = $priceValidator
|
||||
*
|
||||
* Param 2 :
|
||||
* $paramsToValidate[AvailableForTotalAmount::PARAM1_PRICE] = 9
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
* @param Translator $translator Service translator
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators)
|
||||
function __construct(Translator $translator)
|
||||
{
|
||||
$this->setValidators($validators);
|
||||
$this->adapter = $adapter;
|
||||
$this->setParametersToValidate($this->adapter);
|
||||
$this->translator($translator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,4 +169,15 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
throw new \Thelia\Exception\NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all validators
|
||||
* Serialization purpose
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidators()
|
||||
{
|
||||
return $this->validators;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,13 @@ use Thelia\Coupon\CouponAdapterInterface;
|
||||
*/
|
||||
interface CouponRuleInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translator $translator Service translator
|
||||
*/
|
||||
function __construct(Translator $translator);
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Thelia\Constraint\Rule;
|
||||
class SerializableRule
|
||||
{
|
||||
/** @var string Rule Service id */
|
||||
public $ruleClassName = null;
|
||||
public $ruleServiceId = null;
|
||||
|
||||
/** @var array Operators set by Admin for this Rule */
|
||||
public $operators = array();
|
||||
|
||||
Reference in New Issue
Block a user