WIP
All Unit Test are green
This commit is contained in:
@@ -41,7 +41,7 @@ use Thelia\Exception\InvalidRuleValueException;
|
||||
*/
|
||||
class AvailableForXArticles extends CouponRuleAbstract
|
||||
{
|
||||
/** Rule 1st parameter : price */
|
||||
/** Rule 1st parameter : quantity */
|
||||
CONST PARAM1_QUANTITY = 'quantity';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
@@ -121,7 +121,7 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1_QUANTITY => $this->adapter->getCartTotalPrice()
|
||||
self::PARAM1_QUANTITY => $this->adapter->getNbArticlesInCart()
|
||||
);
|
||||
|
||||
return $this;
|
||||
@@ -130,11 +130,21 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidRuleValueException
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
if (!isset($this->paramsToValidate)
|
||||
|| empty($this->paramsToValidate)
|
||||
||!isset($this->paramsToValidate[self::PARAM1_QUANTITY])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
}
|
||||
|
||||
$price = $this->paramsToValidate[self::PARAM1_QUANTITY];
|
||||
|
||||
return $this->isQuantityValid($price);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,6 +100,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
if (!$validator instanceof RuleValidator) {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
if (!in_array($validator->getOperator(), $this->availableOperators)) {
|
||||
throw new InvalidRuleOperatorException(
|
||||
get_class(),
|
||||
$validator->getOperator()
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->validators = $validators;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user