Working : coupon creation : add default rule (thelia.constraint.rule.available_for_everyone)

This commit is contained in:
gmorel
2013-09-23 23:04:00 +02:00
parent e4658d2fa2
commit d0f20cca1d
12 changed files with 154 additions and 156 deletions

View File

@@ -32,6 +32,7 @@ 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\Type\CouponInterface;
use Thelia\Model\Coupon as CouponModel;
@@ -137,11 +138,21 @@ 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();
$couponRuleCollection->add($noConditionRule);
$defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection(
$couponRuleCollection
);
$coupon->createOrUpdate(
$event->getCode(),
$event->getTitle(),
$event->getAmount(),
$event->getEffect(),
$event->getType(),
$event->isRemovingPostage(),
$event->getShortDescription(),
$event->getDescription(),
@@ -150,9 +161,12 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$event->isAvailableOnSpecialOffers(),
$event->isCumulative(),
$event->getMaxUsage(),
$defaultSerializedRule,
$event->getLocale()
);
$event->setCoupon($coupon);
}