Merge branch 'master' of git://github.com/thelia/thelia into french_translation

* 'master' of git://github.com/thelia/thelia: (23 commits)
  Coupon : Add unit test for coupon removing X Amount & X Percent
  Coupon : Add unit test for coupon removing X Amount & X Percent
  Coupon : Add unit test for coupon removing X Amount & X Percent
  Coupon : Add unit test for coupon removing X Amount & X Percent
  Coupon : Add unit test for coupon removing X Amount & X Percent
  Coupon : Fix namespace issues
  Coupon : Fix namespace issues
  Coupon : Adding unit tests
  Coupon : Adding unit tests
  Coupon : Adding unit tests
  Coupon : Adding unit tests
  Coupon : buildCouponFromModel becomes public
  Coupon : Add ability to know usage left after decremental
  Coupon : Bug fix when coupon max usage was not correctly decremented
  Coupon : spelling
  Coupon : rename
  Coupon : Fix the error if a given coupon leads to an unknown service id
  Coupon not found by the factory now just return false
  Fix generated unit test stub files
  Refactor removing Manager notion
  ...
This commit is contained in:
gmorel
2013-11-28 21:29:22 +01:00
42 changed files with 1594 additions and 1079 deletions

View File

@@ -25,7 +25,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\ConditionManagerInterface;
use Thelia\Condition\Implementation\ConditionInterface;
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -94,6 +94,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
public function consume(CouponConsumeEvent $event)
{
$totalDiscount = 0;
$isValid = false;
/** @var CouponFactory $couponFactory */
$couponFactory = $this->container->get('thelia.coupon.factory');
@@ -104,40 +105,40 @@ class Coupon extends BaseAction implements EventSubscriberInterface
/** @var CouponInterface $coupon */
$coupon = $couponFactory->buildCouponFromCode($event->getCode());
$isValid = $coupon->isMatching();
if ($coupon) {
$isValid = $coupon->isMatching();
if ($isValid) {
/** @var Request $request */
$request = $this->container->get('request');
$consumedCoupons = $request->getSession()->getConsumedCoupons();
if ($isValid) {
/** @var Request $request */
$request = $this->container->get('request');
$consumedCoupons = $request->getSession()->getConsumedCoupons();
if (!isset($consumedCoupons) || !$consumedCoupons) {
$consumedCoupons = array();
}
if (!isset($consumedCoupons) || !$consumedCoupons) {
$consumedCoupons = array();
// Prevent accumulation of the same Coupon on a Checkout
$consumedCoupons[$event->getCode()] = $event->getCode();
$request->getSession()->setConsumedCoupons($consumedCoupons);
$totalDiscount = $couponManager->getDiscount();
// @todo insert false product in cart with the name of the coupon and the discount as negative price
// Decrement coupon quantity
// @todo move this part in after order event
$couponQuery = CouponQuery::create();
$couponModel = $couponQuery->findOneByCode($coupon->getCode());
$couponManager->decrementQuantity($couponModel);
$request
->getSession()
->getCart()
->setDiscount($totalDiscount)
->save();
}
// Prevent accumulation of the same Coupon on a Checkout
$consumedCoupons[$event->getCode()] = $event->getCode();
$request->getSession()->setConsumedCoupons($consumedCoupons);
$totalDiscount = $couponManager->getDiscount();
// @todo insert false product in cart with the name of the coupon and the discount as negative price
// Decrement coupon quantity
// @todo move this part in after order event
$couponQuery = CouponQuery::create();
$couponModel = $couponQuery->findOneByCode($coupon->getCode());
$couponManager->decrementeQuantity($couponModel);
$request
->getSession()
->getCart()
->setDiscount($totalDiscount)
->save()
;
}
$event->setIsValid($isValid);
$event->setDiscount($totalDiscount);
}
@@ -154,7 +155,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$coupon->setDispatcher($this->getDispatcher());
// Set default condition if none found
/** @var ConditionManagerInterface $noConditionRule */
/** @var ConditionInterface $noConditionRule */
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');