WIP : Refactor contraint/rule becomes conditions (more generic)
This commit is contained in:
@@ -23,16 +23,16 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Coupon\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
|
||||
@@ -78,11 +78,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule
|
||||
*/
|
||||
public function updateRule(CouponCreateOrUpdateEvent $event)
|
||||
public function updateCondition(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdateRule($coupon, $event);
|
||||
$this->createOrUpdateCondition($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +139,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
// Set default rule if none found
|
||||
$noConditionRule = $this->container->get('thelia.constraint.rule.available_for_everyone');
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$couponRuleCollection = new CouponRuleCollection();
|
||||
/** @var ConditionManagerInterface $noConditionRule */
|
||||
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
|
||||
$constraintFactory = $this->container->get('thelia.condition.factory');
|
||||
$couponRuleCollection = new ConditionCollection();
|
||||
$couponRuleCollection->add($noConditionRule);
|
||||
$defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection(
|
||||
$couponRuleCollection
|
||||
);
|
||||
|
||||
|
||||
$coupon->createOrUpdate(
|
||||
$event->getCode(),
|
||||
$event->getTitle(),
|
||||
@@ -165,8 +165,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
|
||||
|
||||
$event->setCoupon($coupon);
|
||||
}
|
||||
|
||||
@@ -177,15 +175,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
* @param CouponModel $coupon Model to save
|
||||
* @param CouponCreateOrUpdateEvent $event Event containing data
|
||||
*/
|
||||
protected function createOrUpdateRule(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
protected function createOrUpdateCondition(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
/** @var ConditionFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.condition.factory');
|
||||
|
||||
$coupon->createOrUpdateRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($event->getRules()),
|
||||
$coupon->createOrUpdateConditions(
|
||||
$constraintFactory->serializeConditionCollection($event->getConditions()),
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
@@ -218,7 +216,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::COUPON_CREATE => array("create", 128),
|
||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128)
|
||||
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user