Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (18) and others # Via franck (9) and others * 'master' of https://github.com/thelia/thelia: (39 commits) Working : Working : Working : Working : Fixed minor visual glitches Working : Resize countries flag + Add bootstrap-switch fix test suite clear asset cache in cache:cler command Added a 'development mode' to assetic smarty plugin rewriting router use good Request object Added Tools\URL test case, and a test case superclass for initializing Tools\URL remove unused UrlWritin controller create router for rewriting matching customer substitutions fix typo in front id Working : For attributes on labels Working : For attributes on labels add label_attr attribute to form smarty plugin start refactorin rewriting routing ... Conflicts: core/lib/Thelia/Config/Resources/routing/front.xml templates/admin/default/assets/less/thelia/bootstrap-editable.less templates/admin/default/categories.html
This commit is contained in:
@@ -53,31 +53,6 @@ class AvailableForCustomer extends CouponRuleAbstract
|
||||
/** @var RuleValidator Customer Validator */
|
||||
protected $customerValidator = 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)
|
||||
{
|
||||
parent::__construct($adapter, $validators);
|
||||
|
||||
if (isset($validators[self::PARAM1])
|
||||
&& $validators[self::PARAM1] instanceof RuleValidator
|
||||
) {
|
||||
$this->customerValidator = $validators[self::PARAM1];
|
||||
} else {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
|
||||
@@ -52,6 +52,9 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
/** Rule 1st parameter : currency */
|
||||
CONST PARAM1_CURRENCY = 'currency';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_total_amount';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
Operators::INFERIOR,
|
||||
@@ -59,7 +62,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
Operators::SUPERIOR,
|
||||
);
|
||||
|
||||
/** @var PriceParam Price Validator */
|
||||
/** @var RuleValidator Price Validator */
|
||||
protected $priceValidator = null;
|
||||
|
||||
/**
|
||||
@@ -90,7 +93,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
|
||||
$this->checkBackOfficeInputsOperators();
|
||||
|
||||
return $this->isPriceValid($price->getPrice());
|
||||
return $this->isPriceValid($price->getPrice(), $price->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,33 +104,51 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
if (!isset($this->paramsToValidate)
|
||||
|| empty($this->paramsToValidate)
|
||||
||!isset($this->paramsToValidate[self::PARAM1_PRICE])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
$currency = $this->adapter->getCheckoutCurrency();
|
||||
if (empty($currency)) {
|
||||
throw new InvalidRuleValueException(
|
||||
get_class(), self::PARAM1_CURRENCY
|
||||
);
|
||||
}
|
||||
|
||||
$price = $this->paramsToValidate[self::PARAM1_PRICE];
|
||||
$price = $this->adapter->getCartTotalPrice();
|
||||
if (empty($price)) {
|
||||
throw new InvalidRuleValueException(
|
||||
get_class(), self::PARAM1_PRICE
|
||||
);
|
||||
}
|
||||
|
||||
return $this->isPriceValid($price);
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1_PRICE => $this->adapter->getCartTotalPrice(),
|
||||
self::PARAM1_CURRENCY => $this->adapter->getCheckoutCurrency()
|
||||
);
|
||||
|
||||
return $this->isPriceValid($price, $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a price is valid
|
||||
*
|
||||
* @param float $price Price to check
|
||||
* @param float $price Price to check
|
||||
* @param string $currency Price currency
|
||||
*
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
protected function isPriceValid($price)
|
||||
protected function isPriceValid($price, $currency)
|
||||
{
|
||||
$priceValidator = $this->priceValidator;
|
||||
try {
|
||||
$priceValidator->getParam()->compareTo($price);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
|
||||
/** @var PriceParam $param */
|
||||
$param = $priceValidator->getParam();
|
||||
if ($currency == $param->getCurrency()) {
|
||||
try {
|
||||
$priceValidator->getParam()->compareTo($price);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_CURRENCY);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -141,7 +162,8 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1_PRICE => $this->adapter->getCartTotalPrice()
|
||||
self::PARAM1_PRICE => $this->adapter->getCartTotalPrice(),
|
||||
self::PARAM1_CURRENCY => $this->adapter->getCheckoutCurrency()
|
||||
);
|
||||
|
||||
return $this;
|
||||
@@ -191,7 +213,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
* @param array $operators Rule Operator set by the Admin
|
||||
* @param array $values Rule Values set by the Admin
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws \InvalidArgumentException
|
||||
* @return $this
|
||||
*/
|
||||
public function populateFromForm(array $operators, array $values)
|
||||
@@ -199,17 +221,22 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
if ($values[self::PARAM1_PRICE] === null
|
||||
|| $values[self::PARAM1_CURRENCY] === null
|
||||
) {
|
||||
throw new InvalidArgumentException(
|
||||
throw new \InvalidArgumentException(
|
||||
'The Rule ' . get_class() . 'needs at least a quantity set (' . self::PARAM1_PRICE . ', ' . self::PARAM1_CURRENCY . ')'
|
||||
);
|
||||
}
|
||||
|
||||
$this->priceValidator = new PriceParam(
|
||||
$this->adapter,
|
||||
$values[self::PARAM1_PRICE],
|
||||
$values[self::PARAM1_CURRENCY]
|
||||
$this->priceValidator = new RuleValidator(
|
||||
$operators[self::PARAM1_PRICE],
|
||||
new PriceParam(
|
||||
$this->translator,
|
||||
$values[self::PARAM1_PRICE],
|
||||
$values[self::PARAM1_CURRENCY]
|
||||
)
|
||||
);
|
||||
|
||||
$this->validators = array(self::PARAM1_PRICE => $this->priceValidator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -221,13 +248,14 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
public function getSerializableRule()
|
||||
{
|
||||
$serializableRule = new SerializableRule();
|
||||
$serializableRule->ruleServiceId = $this->serviceId;
|
||||
$serializableRule->operators = array(
|
||||
self::PARAM1_PRICE => $this->priceValidator->getOperator()
|
||||
);
|
||||
|
||||
$serializableRule->values = array(
|
||||
self::PARAM1_PRICE => $this->priceValidator->getPrice(),
|
||||
self::PARAM1_CURRENCY => $this->priceValidator->getCurrency()
|
||||
self::PARAM1_PRICE => $this->priceValidator->getParam()->getPrice(),
|
||||
self::PARAM1_CURRENCY => $this->priceValidator->getParam()->getCurrency()
|
||||
);
|
||||
|
||||
return $serializableRule;
|
||||
|
||||
@@ -46,6 +46,9 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
/** Rule 1st parameter : quantity */
|
||||
CONST PARAM1_QUANTITY = 'quantity';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_x_articles';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
Operators::INFERIOR,
|
||||
@@ -198,11 +201,16 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
);
|
||||
}
|
||||
|
||||
$this->quantityValidator = new QuantityParam(
|
||||
$this->adapter,
|
||||
$values[self::PARAM1_QUANTITY]
|
||||
$this->quantityValidator = new RuleValidator(
|
||||
$operators[self::PARAM1_QUANTITY],
|
||||
new QuantityParam(
|
||||
$this->adapter,
|
||||
$values[self::PARAM1_QUANTITY]
|
||||
)
|
||||
);
|
||||
|
||||
$this->validators = array(self::PARAM1_QUANTITY => $this->quantityValidator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -214,6 +222,7 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
public function getSerializableRule()
|
||||
{
|
||||
$serializableRule = new SerializableRule();
|
||||
$serializableRule->ruleServiceId = $this->serviceId;
|
||||
$serializableRule->operators = array(
|
||||
self::PARAM1_QUANTITY => $this->quantityValidator->getOperator()
|
||||
);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
@@ -49,6 +49,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/** Value key in $validators */
|
||||
CONST VALUE = 'value';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = null;
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array();
|
||||
|
||||
@@ -67,11 +70,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translator $translator Service translator
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(Translator $translator)
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->translator($translator);
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,4 +184,16 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
return $this->validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceId()
|
||||
{
|
||||
return $this->serviceId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
@@ -42,9 +42,9 @@ interface CouponRuleInterface
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translator $translator Service translator
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(Translator $translator);
|
||||
function __construct(CouponAdapterInterface $adapter);
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
|
||||
@@ -45,5 +45,37 @@ class SerializableRule
|
||||
/** @var array Values set by Admin for this Rule */
|
||||
public $values = array();
|
||||
|
||||
/**
|
||||
* Get Operators set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOperators()
|
||||
{
|
||||
return $this->operators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRuleServiceId()
|
||||
{
|
||||
return $this->ruleServiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Values set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user