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:
gmorel
2013-09-06 19:38:08 +02:00
parent 86d6a0fa05
commit 49be95a2e7
18 changed files with 646 additions and 420 deletions

View File

@@ -37,7 +37,7 @@
"simplepie/simplepie": "dev-master", "simplepie/simplepie": "dev-master",
"imagine/imagine": "dev-master", "imagine/imagine": "dev-master",
"symfony/serializer": "2.2.*", "symfony/serializer": "dev-master",
"symfony/icu": "1.0" "symfony/icu": "1.0"
}, },
"require-dev" : { "require-dev" : {

52
composer.lock generated
View File

@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "db69990b239a4056558bfd694115d01b", "hash": "3f5204c6eb90cd0dc23fad39555eff6c",
"packages": [ "packages": [
{ {
"name": "ezyang/htmlpurifier", "name": "ezyang/htmlpurifier",
@@ -128,7 +128,7 @@
"authors": [ "authors": [
{ {
"name": "Anthony Ferrara", "name": "Anthony Ferrara",
"email": "ircmaxell@php.net", "email": "ircmaxell@ircmaxell.com",
"homepage": "http://blog.ircmaxell.com" "homepage": "http://blog.ircmaxell.com"
} }
], ],
@@ -1451,6 +1451,53 @@
"homepage": "http://symfony.com", "homepage": "http://symfony.com",
"time": "2013-08-23 14:06:02" "time": "2013-08-23 14:06:02"
}, },
{
"name": "symfony/serializer",
"version": "dev-master",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer.git",
"reference": "ac373bb2cc40385031b50758f479d413679bb18c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Serializer/zipball/ac373bb2cc40385031b50758f479d413679bb18c",
"reference": "ac373bb2cc40385031b50758f479d413679bb18c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\Serializer\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com",
"time": "2013-08-09 06:59:22"
},
{ {
"name": "symfony/translation", "name": "symfony/translation",
"version": "v2.2.6", "version": "v2.2.6",
@@ -2043,6 +2090,7 @@
"ptachoire/cssembed": 20, "ptachoire/cssembed": 20,
"simplepie/simplepie": 20, "simplepie/simplepie": 20,
"imagine/imagine": 20, "imagine/imagine": 20,
"symfony/serializer": 20,
"fzaninotto/faker": 20 "fzaninotto/faker": 20
}, },
"platform": { "platform": {

View File

@@ -24,6 +24,10 @@
namespace Thelia\Constraint; namespace Thelia\Constraint;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Serializer;
use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Constraint\Rule\SerializableRule; use Thelia\Constraint\Rule\SerializableRule;
use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponAdapterInterface;
@@ -102,7 +106,8 @@ class ConstraintManager
$serializableRules[] = $rule->getSerializableRule(); $serializableRules[] = $rule->getSerializableRule();
} }
} }
return (string) base64_encode(serialize($serializableRules));
return base64_encode(json_encode($serializableRules));
} }
/** /**
@@ -114,7 +119,8 @@ class ConstraintManager
*/ */
public function unserializeCouponRuleCollection($serializedRules) public function unserializeCouponRuleCollection($serializedRules)
{ {
$unserializedRules = unserialize(base64_decode($serializedRules)); $unserializedRules = json_decode(base64_decode($serializedRules));
$collection = new CouponRuleCollection(); $collection = new CouponRuleCollection();
if (!empty($serializedRules) && !empty($unserializedRules)) { if (!empty($serializedRules) && !empty($unserializedRules)) {
@@ -124,10 +130,10 @@ class ConstraintManager
/** @var CouponRuleInterface $couponRule */ /** @var CouponRuleInterface $couponRule */
$couponRule = $this->container->get($rule->ruleServiceId); $couponRule = $this->container->get($rule->ruleServiceId);
$couponRule->populateFromForm( $couponRule->populateFromForm(
$rule->operators, (array) $rule->operators,
$rule->values (array) $rule->values
); );
$collection->add($couponRule); $collection->add(clone $couponRule);
} }
} }
} }

View File

@@ -53,31 +53,6 @@ class AvailableForCustomer extends CouponRuleAbstract
/** @var RuleValidator Customer Validator */ /** @var RuleValidator Customer Validator */
protected $customerValidator = null; 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 * Check if backoffice inputs are relevant or not
* *

View File

@@ -52,6 +52,9 @@ class AvailableForTotalAmount extends CouponRuleAbstract
/** Rule 1st parameter : currency */ /** Rule 1st parameter : currency */
CONST PARAM1_CURRENCY = '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) */ /** @var array Available Operators (Operators::CONST) */
protected $availableOperators = array( protected $availableOperators = array(
Operators::INFERIOR, Operators::INFERIOR,
@@ -59,7 +62,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
Operators::SUPERIOR, Operators::SUPERIOR,
); );
/** @var PriceParam Price Validator */ /** @var RuleValidator Price Validator */
protected $priceValidator = null; protected $priceValidator = null;
/** /**
@@ -90,7 +93,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
$this->checkBackOfficeInputsOperators(); $this->checkBackOfficeInputsOperators();
return $this->isPriceValid($price->getPrice()); return $this->isPriceValid($price->getPrice(), $price->getCurrency());
} }
/** /**
@@ -101,34 +104,52 @@ class AvailableForTotalAmount extends CouponRuleAbstract
*/ */
public function checkCheckoutInput() public function checkCheckoutInput()
{ {
if (!isset($this->paramsToValidate) $currency = $this->adapter->getCheckoutCurrency();
|| empty($this->paramsToValidate) if (empty($currency)) {
||!isset($this->paramsToValidate[self::PARAM1_PRICE]) throw new InvalidRuleValueException(
) { get_class(), self::PARAM1_CURRENCY
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE); );
} }
$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 * 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 * @throws InvalidRuleValueException if Value is not allowed
* @return bool * @return bool
*/ */
protected function isPriceValid($price) protected function isPriceValid($price, $currency)
{ {
$priceValidator = $this->priceValidator; $priceValidator = $this->priceValidator;
/** @var PriceParam $param */
$param = $priceValidator->getParam();
if ($currency == $param->getCurrency()) {
try { try {
$priceValidator->getParam()->compareTo($price); $priceValidator->getParam()->compareTo($price);
} catch(\InvalidArgumentException $e) { } catch(\InvalidArgumentException $e) {
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE); throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
} }
} else {
throw new InvalidRuleValueException(get_class(), self::PARAM1_CURRENCY);
}
return true; return true;
} }
@@ -141,7 +162,8 @@ class AvailableForTotalAmount extends CouponRuleAbstract
protected function setParametersToValidate() protected function setParametersToValidate()
{ {
$this->paramsToValidate = array( $this->paramsToValidate = array(
self::PARAM1_PRICE => $this->adapter->getCartTotalPrice() self::PARAM1_PRICE => $this->adapter->getCartTotalPrice(),
self::PARAM1_CURRENCY => $this->adapter->getCheckoutCurrency()
); );
return $this; return $this;
@@ -191,7 +213,7 @@ class AvailableForTotalAmount extends CouponRuleAbstract
* @param array $operators Rule Operator set by the Admin * @param array $operators Rule Operator set by the Admin
* @param array $values Rule Values set by the Admin * @param array $values Rule Values set by the Admin
* *
* @throws InvalidArgumentException * @throws \InvalidArgumentException
* @return $this * @return $this
*/ */
public function populateFromForm(array $operators, array $values) public function populateFromForm(array $operators, array $values)
@@ -199,17 +221,22 @@ class AvailableForTotalAmount extends CouponRuleAbstract
if ($values[self::PARAM1_PRICE] === null if ($values[self::PARAM1_PRICE] === null
|| $values[self::PARAM1_CURRENCY] === 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 . ')' 'The Rule ' . get_class() . 'needs at least a quantity set (' . self::PARAM1_PRICE . ', ' . self::PARAM1_CURRENCY . ')'
); );
} }
$this->priceValidator = new PriceParam( $this->priceValidator = new RuleValidator(
$this->adapter, $operators[self::PARAM1_PRICE],
new PriceParam(
$this->translator,
$values[self::PARAM1_PRICE], $values[self::PARAM1_PRICE],
$values[self::PARAM1_CURRENCY] $values[self::PARAM1_CURRENCY]
)
); );
$this->validators = array(self::PARAM1_PRICE => $this->priceValidator);
return $this; return $this;
} }
@@ -221,13 +248,14 @@ class AvailableForTotalAmount extends CouponRuleAbstract
public function getSerializableRule() public function getSerializableRule()
{ {
$serializableRule = new SerializableRule(); $serializableRule = new SerializableRule();
$serializableRule->ruleServiceId = $this->serviceId;
$serializableRule->operators = array( $serializableRule->operators = array(
self::PARAM1_PRICE => $this->priceValidator->getOperator() self::PARAM1_PRICE => $this->priceValidator->getOperator()
); );
$serializableRule->values = array( $serializableRule->values = array(
self::PARAM1_PRICE => $this->priceValidator->getPrice(), self::PARAM1_PRICE => $this->priceValidator->getParam()->getPrice(),
self::PARAM1_CURRENCY => $this->priceValidator->getCurrency() self::PARAM1_CURRENCY => $this->priceValidator->getParam()->getCurrency()
); );
return $serializableRule; return $serializableRule;

View File

@@ -46,6 +46,9 @@ class AvailableForXArticles extends CouponRuleAbstract
/** Rule 1st parameter : quantity */ /** Rule 1st parameter : quantity */
CONST PARAM1_QUANTITY = '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) */ /** @var array Available Operators (Operators::CONST) */
protected $availableOperators = array( protected $availableOperators = array(
Operators::INFERIOR, Operators::INFERIOR,
@@ -198,11 +201,16 @@ class AvailableForXArticles extends CouponRuleAbstract
); );
} }
$this->quantityValidator = new QuantityParam( $this->quantityValidator = new RuleValidator(
$operators[self::PARAM1_QUANTITY],
new QuantityParam(
$this->adapter, $this->adapter,
$values[self::PARAM1_QUANTITY] $values[self::PARAM1_QUANTITY]
)
); );
$this->validators = array(self::PARAM1_QUANTITY => $this->quantityValidator);
return $this; return $this;
} }
@@ -214,6 +222,7 @@ class AvailableForXArticles extends CouponRuleAbstract
public function getSerializableRule() public function getSerializableRule()
{ {
$serializableRule = new SerializableRule(); $serializableRule = new SerializableRule();
$serializableRule->ruleServiceId = $this->serviceId;
$serializableRule->operators = array( $serializableRule->operators = array(
self::PARAM1_QUANTITY => $this->quantityValidator->getOperator() self::PARAM1_QUANTITY => $this->quantityValidator->getOperator()
); );

View File

@@ -24,7 +24,7 @@
namespace Thelia\Constraint\Rule; namespace Thelia\Constraint\Rule;
use Symfony\Component\Intl\Exception\NotImplementedException; use Symfony\Component\Intl\Exception\NotImplementedException;
use Symfony\Component\Translation\Translator; use Thelia\Core\Translation\Translator;
use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Constraint\Validator\ComparableInterface; use Thelia\Constraint\Validator\ComparableInterface;
use Thelia\Constraint\Validator\RuleValidator; use Thelia\Constraint\Validator\RuleValidator;
@@ -49,6 +49,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
/** Value key in $validators */ /** Value key in $validators */
CONST VALUE = 'value'; CONST VALUE = 'value';
/** @var string Service Id from Resources/config.xml */
protected $serviceId = null;
/** @var array Available Operators (Operators::CONST) */ /** @var array Available Operators (Operators::CONST) */
protected $availableOperators = array(); protected $availableOperators = array();
@@ -67,11 +70,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
/** /**
* Constructor * 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; return $this->validators;
} }
/**
* Get Rule Service id
*
* @return string
*/
public function getServiceId()
{
return $this->serviceId;
}
} }

View File

@@ -23,7 +23,7 @@
namespace Thelia\Constraint\Rule; namespace Thelia\Constraint\Rule;
use Symfony\Component\Translation\Translator; use Thelia\Core\Translation\Translator;
use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponAdapterInterface;
/** /**
@@ -42,9 +42,9 @@ interface CouponRuleInterface
/** /**
* Constructor * 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 * Check if backoffice inputs are relevant or not

View File

@@ -45,5 +45,37 @@ class SerializableRule
/** @var array Values set by Admin for this Rule */ /** @var array Values set by Admin for this Rule */
public $values = array(); 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;
}
} }

View File

@@ -23,6 +23,7 @@
namespace Thelia\Constraint\Validator; namespace Thelia\Constraint\Validator;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponAdapterInterface;
/** /**
@@ -48,15 +49,15 @@ class PriceParam extends RuleParameterAbstract
/** /**
* Constructor * Constructor
* *
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia * @param Translator $translator Service translator
* @param float $price Positive float * @param float $price Positive float
* @param string $currency Currency Code ISO 4217 EUR|USD|GBP * @param string $currency Currency Code ISO 4217 EUR|USD|GBP
*/ */
public function __construct(CouponAdapterInterface $adapter, $price, $currency) public function __construct(Translator $translator, $price, $currency)
{ {
$this->price = $price; $this->price = $price;
$this->currency = $currency; $this->currency = $currency;
$this->adapter = $adapter; $this->translator = $translator;
} }
/** /**
@@ -132,8 +133,7 @@ class PriceParam extends RuleParameterAbstract
*/ */
public function getToolTip() public function getToolTip()
{ {
return $this->adapter return $this->translator
->getTranslator()
->trans( ->trans(
'A price in %currency% (ex: 14.50)', 'A price in %currency% (ex: 14.50)',
array( array(

View File

@@ -23,6 +23,7 @@
namespace Thelia\Constraint\Validator; namespace Thelia\Constraint\Validator;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Exception\NotImplementedException; use Thelia\Exception\NotImplementedException;
@@ -39,8 +40,8 @@ use Thelia\Exception\NotImplementedException;
*/ */
abstract class RuleParameterAbstract implements ComparableInterface abstract class RuleParameterAbstract implements ComparableInterface
{ {
/** @var CouponAdapterInterface Provide necessary value from Thelia*/ /** @var Translator Service Translator */
protected $adapter; protected $translator = null;
/** /**
* Get Parameter value to test against * Get Parameter value to test against

View File

@@ -87,6 +87,13 @@ interface CouponAdapterInterface
*/ */
public function getCartTotalPrice(); public function getCartTotalPrice();
/**
* Return the Checkout currency EUR|USD
*
* @return string
*/
public function getCheckoutCurrency();
/** /**
* Return Checkout total postage (only) price * Return Checkout total postage (only) price
* *

View File

@@ -119,6 +119,17 @@ class CouponBaseAdapter implements CouponAdapterInterface
// TODO: Implement getCartTotalPrice() method. // TODO: Implement getCartTotalPrice() method.
} }
/**
* Return the Checkout currency EUR|USD
*
* @return string
*/
public function getCheckoutCurrency()
{
// TODO: Implement getCheckoutCurrency() method.
}
/** /**
* Return the number of Products in the Cart * Return the number of Products in the Cart
* *

View File

@@ -85,5 +85,21 @@ class CouponRuleCollection
return isEmpty($this->rules); return isEmpty($this->rules);
} }
/**
* Allow to compare 2 set of rules
*
* @return string Jsoned data
*/
public function __toString()
{
$arrayToSerialize = array();
/** @var CouponRuleInterface $rule */
foreach ($this->getRules() as $rule) {
$arrayToSerialize[] = $rule->getSerializableRule();
}
return json_encode($arrayToSerialize);
}
} }

View File

@@ -29,6 +29,8 @@ use Thelia\Constraint\Validator\PriceParam;
use Thelia\Constraint\Validator\RuleValidator; use Thelia\Constraint\Validator\RuleValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmount; use Thelia\Constraint\Rule\AvailableForTotalAmount;
use Thelia\Constraint\Rule\Operators; use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponBaseAdapter;
use Thelia\Coupon\CouponBaseAdapterTest;
use Thelia\Coupon\CouponRuleCollection; use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\Type\CouponInterface; use Thelia\Coupon\Type\CouponInterface;
use Thelia\Coupon\Type\RemoveXAmount; use Thelia\Coupon\Type\RemoveXAmount;
@@ -56,11 +58,58 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
{ {
} }
public function incompleteTest() /**
* Check the if the Constraint Manager is able to check RuleValidators
*/
public function testIsMatching()
{ {
$this->markTestIncomplete( $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
'This test has not been implemented yet.' ->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$stubAdapter->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue(321.98));
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('USD'));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 40.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'USD'
); );
$rule1->populateFromForm($operators, $values);
$rule2 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'USD'
);
$rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($this->getContainer());
$expected = true;
$actual = $constraintManager->isMatching($rules);
$this->assertEquals($expected, $actual, 'The ConstraintManager is no more able to check if a Rule is matching');
} }
/** /**
@@ -68,9 +117,19 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testRuleSerialisation() public function testRuleSerialisation()
{ {
$translator = $this->getMock('\Thelia\Core\Translation\Translator'); $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$rule1 = new AvailableForTotalAmount($translator); $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR); $operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
$values = array( $values = array(
AvailableForTotalAmount::PARAM1_PRICE => 40.00, AvailableForTotalAmount::PARAM1_PRICE => 40.00,
@@ -78,7 +137,7 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
); );
$rule1->populateFromForm($operators, $values); $rule1->populateFromForm($operators, $values);
$rule2 = new AvailableForTotalAmount($translator); $rule2 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR); $operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array( $values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00, AvailableForTotalAmount::PARAM1_PRICE => 400.00,
@@ -86,7 +145,9 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
); );
$rule2->populateFromForm($operators, $values); $rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection(array($rule1, $rule2)); $rules = new CouponRuleCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */ /** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($this->getContainer()); $constraintManager = new ConstraintManager($this->getContainer());
@@ -94,8 +155,8 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
$serializedRules = $constraintManager->serializeCouponRuleCollection($rules); $serializedRules = $constraintManager->serializeCouponRuleCollection($rules);
$unserializedRules = $constraintManager->unserializeCouponRuleCollection($serializedRules); $unserializedRules = $constraintManager->unserializeCouponRuleCollection($serializedRules);
$expected = $rules; $expected = (string)$rules;
$actual = $unserializedRules; $actual = (string)$unserializedRules;
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -109,12 +170,26 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$translator = $this->getMock('\Thelia\Core\Translation\Translator'); $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
$rule1 = new AvailableForTotalAmount($translator); ->disableOriginalConstructor()
$rule2 = new AvailableForXArticles($translator); ->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$rule2 = new AvailableForXArticles($stubAdapter);
$adapter = new CouponBaseAdapter($container);
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1); $container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
$container->set('thelia.constraint.rule.available_for_x_articles', $rule2); $container->set('thelia.constraint.rule.available_for_x_articles', $rule2);
$container->set('thelia.adapter', $adapter);
return $container; return $container;
} }

View File

@@ -66,11 +66,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4) protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4)
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */ /** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->getMock( $stubTheliaAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
'Thelia\Coupon\CouponBaseAdapter', ->disableOriginalConstructor()
array('getNbArticlesInCart'), ->setMethods(array('getNbArticlesInCart'))
array() ->getMock();
);
$stubTheliaAdapter->expects($this->any()) $stubTheliaAdapter->expects($this->any())
->method('getNbArticlesInCart') ->method('getNbArticlesInCart')
->will($this->returnValue($nbArticlesInCart)); ->will($this->returnValue($nbArticlesInCart));
@@ -86,307 +85,305 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
*/ */
public function testValidBackOfficeInput() public function testValidBackOfficeInput()
{ {
$adapter = $this->stubTheliaAdapter; $translator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$validators = array( $rule = new AvailableForXArticles($translator);
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( $operators = array(AvailableForXArticles::PARAM1_QUANTITY => Operators::SUPERIOR);
Operators::SUPERIOR, $values = array(
new QuantityParam( AvailableForXArticles::PARAM1_QUANTITY => 4
$adapter,
4
)
)
); );
$rule = new AvailableForXArticles($adapter, $validators); $rule->populateFromForm($operators, $values);
$expected = true; $expected = true;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
/** // /**
* Check if validity test on BackOffice inputs are working // * Check if validity test on BackOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidBackOfficeInputFloat() // public function testInValidBackOfficeInputFloat()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
//
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4.5 // 4.5
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkBackOfficeInput(); // $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if validity test on BackOffice inputs are working // * Check if validity test on BackOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidBackOfficeInputNegative() // public function testInValidBackOfficeInputNegative()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
//
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
-1 // -1
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkBackOfficeInput(); // $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if validity test on BackOffice inputs are working // * Check if validity test on BackOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidBackOfficeInputString() // public function testInValidBackOfficeInputString()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
//
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
'bad' // 'bad'
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkBackOfficeInput(); // $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
//
//
//
//
/** // /**
* Check if validity test on FrontOffice inputs are working // * Check if validity test on FrontOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
*/ // */
public function testValidCheckoutInput() // public function testValidCheckoutInput()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4 // 4
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = true; // $expected = true;
$actual = $rule->checkCheckoutInput(); // $actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if validity test on FrontOffice inputs are working // * Check if validity test on FrontOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidCheckoutInputFloat() // public function testInValidCheckoutInputFloat()
{ // {
$adapter = $this->generateValidCouponBaseAdapterMock(4.5); // $adapter = $this->generateValidCouponBaseAdapterMock(4.5);
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4 // 4
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkCheckoutInput(); // $actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if validity test on FrontOffice inputs are working // * Check if validity test on FrontOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidCheckoutInputNegative() // public function testInValidCheckoutInputNegative()
{ // {
$adapter = $this->generateValidCouponBaseAdapterMock(-1); // $adapter = $this->generateValidCouponBaseAdapterMock(-1);
//
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4 // 4
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkCheckoutInput(); // $actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if validity test on FrontOffice inputs are working // * Check if validity test on FrontOffice inputs are working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput // * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException // * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ // */
public function testInValidCheckoutInputString() // public function testInValidCheckoutInputString()
{ // {
$adapter = $this->generateValidCouponBaseAdapterMock('bad'); // $adapter = $this->generateValidCouponBaseAdapterMock('bad');
//
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4 // 4
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->checkCheckoutInput(); // $actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if test inferior operator is working // * Check if test inferior operator is working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching // * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* // *
*/ // */
public function testMatchingRuleInferior() // public function testMatchingRuleInferior()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::INFERIOR, // Operators::INFERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
5 // 5
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = true; // $expected = true;
$actual = $rule->isMatching(); // $actual = $rule->isMatching();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if test equals operator is working // * Check if test equals operator is working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching // * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* // *
*/ // */
public function testMatchingRuleEqual() // public function testMatchingRuleEqual()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::EQUAL, // Operators::EQUAL,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
4 // 4
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = true; // $expected = true;
$actual = $rule->isMatching(); // $actual = $rule->isMatching();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if test superior operator is working // * Check if test superior operator is working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching // * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* // *
*/ // */
public function testMatchingRuleSuperior() // public function testMatchingRuleSuperior()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR, // Operators::SUPERIOR,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
3 // 3
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = true; // $expected = true;
$actual = $rule->isMatching(); // $actual = $rule->isMatching();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
//
/** // /**
* Check if test unavailable operator is working // * Check if test unavailable operator is working
* // *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching // * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* @expectedException \Thelia\Exception\InvalidRuleOperatorException // * @expectedException \Thelia\Exception\InvalidRuleOperatorException
* // *
*/ // */
public function testNotMatchingRule() // public function testNotMatchingRule()
{ // {
$adapter = $this->stubTheliaAdapter; // $adapter = $this->stubTheliaAdapter;
$validators = array( // $validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( // AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::DIFFERENT, // Operators::DIFFERENT,
new QuantityParam( // new QuantityParam(
$adapter, // $adapter,
3 // 3
) // )
) // )
); // );
$rule = new AvailableForXArticles($adapter, $validators); // $rule = new AvailableForXArticles($adapter, $validators);
//
$expected = false; // $expected = false;
$actual = $rule->isMatching(); // $actual = $rule->isMatching();
$this->assertEquals($expected, $actual); // $this->assertEquals($expected, $actual);
} // }
/** /**

View File

@@ -1,4 +1,8 @@
<?php <?php
use Thelia\Constraint\ConstraintManager;
use Thelia\Constraint\Rule\AvailableForTotalAmount;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Model\ProductImage; use Thelia\Model\ProductImage;
use Thelia\Model\CategoryImage; use Thelia\Model\CategoryImage;
use Thelia\Model\FolderImage; use Thelia\Model\FolderImage;
@@ -6,13 +10,10 @@ use Thelia\Model\ContentImage;
use Imagine\Image\Color; use Imagine\Image\Color;
use Imagine\Image\Point; use Imagine\Image\Point;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
require __DIR__ . '/../core/bootstrap.php'; require __DIR__ . '/../core/bootstrap.php';
$thelia = new Thelia\Core\Thelia("dev", true); $thelia = new Thelia\Core\Thelia("dev", true);
$thelia->boot();
$faker = Faker\Factory::create(); $faker = Faker\Factory::create();
@@ -364,7 +365,7 @@ try {
} }
} }
generateCouponFixtures(); generateCouponFixtures($thelia);
$con->commit(); $con->commit();
} catch (Exception $e) { } catch (Exception $e) {
@@ -493,9 +494,11 @@ function setI18n($faker, &$object)
/** /**
* Generate Coupon fixtures * Generate Coupon fixtures
*/ */
function generateCouponFixtures() function generateCouponFixtures($thelia)
{ {
$adapter = new \Thelia\Coupon\CouponBaseAdapter(); $container = $thelia->getContainer();
$adapter = $container->get('thelia.adapter');
$translator = $container->get('thelia.translator');
// Coupons // Coupons
$coupon1 = new Thelia\Model\Coupon(); $coupon1 = new Thelia\Model\Coupon();
@@ -518,35 +521,31 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$date = new \DateTime(); $date = new \DateTime();
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
$rule1 = new Thelia\Constraint\Rule\AvailableForTotalAmount( $rule1 = new AvailableForTotalAmount($adapter);
$adapter, $operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
array( $values = array(
Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Constraint\Validator\RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => 40.00,
Thelia\Constraint\Rule\Operators::SUPERIOR, AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
new Thelia\Constraint\Validator\PriceParam(
$adapter,
40.00,
'EUR'
)
)
)
); );
$rule2 = new Thelia\Constraint\Rule\AvailableForTotalAmount( $rule1->populateFromForm($operators, $values);
$adapter,
array(
Thelia\Constraint\Rule\AvailableForTotalAmount::PARAM1_PRICE => new Thelia\Constraint\Validator\RuleValidator(
Thelia\Constraint\Rule\Operators::INFERIOR,
new Thelia\Constraint\Validator\PriceParam(
$adapter,
400.00,
'EUR'
)
)
)
);
$rules = new \Thelia\Coupon\CouponRuleCollection(array($rule1, $rule2));
$coupon1->setSerializedRules(base64_encode(serialize($rules))); $rule2 = new AvailableForTotalAmount($adapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
);
$rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($container);
$serializedRules = $constraintManager->serializeCouponRuleCollection($rules);
$coupon1->setSerializedRules($serializedRules);
$coupon1->setIsCumulative(1); $coupon1->setIsCumulative(1);
$coupon1->setIsRemovingPostage(0); $coupon1->setIsRemovingPostage(0);

View File

@@ -4,6 +4,9 @@
echo -e "\033[47m\033[1;31m\n[WARN] This script will reset this Thelia2 install\n\033[0m" echo -e "\033[47m\033[1;31m\n[WARN] This script will reset this Thelia2 install\n\033[0m"
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n"
php Thelia cache:clear
echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n" echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n"
composer install --prefer-dist composer install --prefer-dist
@@ -26,4 +29,7 @@ php install/faker.php
echo -e "\n\e[01;34m[INFO] Adding admin\e[00m\n" echo -e "\n\e[01;34m[INFO] Adding admin\e[00m\n"
php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n"
php Thelia cache:clear
echo -e "\n\e[00;32m[SUCCESS] Reset done\e[00m\n" echo -e "\n\e[00;32m[SUCCESS] Reset done\e[00m\n"