WIP : Refactor contraint/rule becomes conditions (more generic)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\Rule\MatchForEveryoneManager;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\Implementation\MatchForEveryoneManager;
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
|
||||
use Thelia\Condition\Implementation\MatchForXArticlesManager;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
|
||||
@@ -637,9 +639,11 @@ function setI18n($faker, &$object, $fields = array('Title' => 20, 'Description'
|
||||
/**
|
||||
* Generate Coupon fixtures
|
||||
*/
|
||||
function generateCouponFixtures($thelia)
|
||||
function generateCouponFixtures(\Thelia\Core\Thelia $thelia)
|
||||
{
|
||||
/** @var $container ContainerInterface Service Container */
|
||||
$container = $thelia->getContainer();
|
||||
/** @var AdapterInterface $adapter */
|
||||
$adapter = $container->get('thelia.adapter');
|
||||
|
||||
// Coupons
|
||||
@@ -663,36 +667,36 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$date = new \DateTime();
|
||||
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months")));
|
||||
|
||||
$rule1 = new AvailableForTotalAmountManager($adapter);
|
||||
$condition1 = new MatchForTotalAmountManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 40.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR'
|
||||
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rule2 = new AvailableForTotalAmountManager($adapter);
|
||||
$condition2 = new MatchForTotalAmountManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR,
|
||||
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR'
|
||||
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$rule2->setValidatorsFromForm($operators, $values);
|
||||
$condition2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new ConditionCollection();
|
||||
$rules->add($rule1);
|
||||
$rules->add($rule2);
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $container->get('thelia.condition.factory');
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
$conditions->add($condition2);
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $container->get('thelia.condition.factory');
|
||||
|
||||
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
|
||||
$coupon1->setSerializedRules($serializedRules);
|
||||
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
||||
$coupon1->setSerializedRules($serializedConditions);
|
||||
$coupon1->setMaxUsage(40);
|
||||
$coupon1->setIsCumulative(1);
|
||||
$coupon1->setIsRemovingPostage(0);
|
||||
@@ -721,22 +725,22 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$date = new \DateTime();
|
||||
$coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months")));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($adapter);
|
||||
$condition1 = new MatchForXArticlesManager($adapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR,
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4,
|
||||
MatchForXArticlesManager::INPUT1 => 4,
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
$rules = new ConditionCollection();
|
||||
$rules->add($rule1);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $container->get('thelia.condition.factory');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $container->get('thelia.condition.factory');
|
||||
|
||||
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
|
||||
$coupon2->setSerializedRules($serializedRules);
|
||||
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
||||
$coupon2->setSerializedRules($serializedConditions);
|
||||
$coupon2->setMaxUsage(-1);
|
||||
$coupon2->setIsCumulative(0);
|
||||
$coupon2->setIsRemovingPostage(1);
|
||||
@@ -765,18 +769,18 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$date = new \DateTime();
|
||||
$coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
|
||||
|
||||
$rule1 = new MatchForEveryoneManager($adapter);
|
||||
$condition1 = new MatchForEveryoneManager($adapter);
|
||||
$operators = array();
|
||||
$values = array();
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
$rules = new ConditionCollection();
|
||||
$rules->add($rule1);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $container->get('thelia.condition.factory');
|
||||
/** @var ConditionFactory $constraintCondition */
|
||||
$constraintCondition = $container->get('thelia.condition.factory');
|
||||
|
||||
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
|
||||
$coupon3->setSerializedRules($serializedRules);
|
||||
$serializedConditions = $constraintCondition->serializeConditionCollection($conditions);
|
||||
$coupon3->setSerializedRules($serializedConditions);
|
||||
$coupon3->setMaxUsage(-1);
|
||||
$coupon3->setIsCumulative(1);
|
||||
$coupon3->setIsRemovingPostage(0);
|
||||
|
||||
@@ -21,11 +21,8 @@
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
|
||||
use Thelia\Condition\Implementation\MatchForXArticlesManager;
|
||||
|
||||
|
||||
require __DIR__ . '/../core/bootstrap.php';
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
<?php
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Model\ProductImage;
|
||||
use Thelia\Model\CategoryImage;
|
||||
use Thelia\Model\FolderImage;
|
||||
use Thelia\Model\ContentImage;
|
||||
use Imagine\Image\Color;
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
|
||||
use Thelia\Condition\Implementation\MatchForXArticlesManager;
|
||||
use Imagine\Image\Point;
|
||||
|
||||
require __DIR__ . '/../core/bootstrap.php';
|
||||
|
||||
Reference in New Issue
Block a user