Refactor rule => condition
adapter => facade
This commit is contained in:
@@ -35,7 +35,7 @@ use Thelia\Type\FloatType;
|
|||||||
* Date: 8/19/13
|
* Date: 8/19/13
|
||||||
* Time: 3:24 PM
|
* Time: 3:24 PM
|
||||||
*
|
*
|
||||||
* Assist in writing a condition of whether the Rule is applied or not
|
* Assist in writing a condition of whether the Condition is applied or not
|
||||||
*
|
*
|
||||||
* @package Constraint
|
* @package Constraint
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ interface ConditionManagerInterface
|
|||||||
function __construct(FacadeInterface $adapter);
|
function __construct(FacadeInterface $adapter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Rule Service id
|
* Get Condition Service id
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class CouponFactory
|
|||||||
protected $container = null;
|
protected $container = null;
|
||||||
|
|
||||||
/** @var FacadeInterface Provide necessary value from Thelia*/
|
/** @var FacadeInterface Provide necessary value from Thelia*/
|
||||||
protected $adapter;
|
protected $facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -58,7 +58,7 @@ class CouponFactory
|
|||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->adapter = $container->get('thelia.facade');
|
$this->facade = $container->get('thelia.facade');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +74,7 @@ class CouponFactory
|
|||||||
public function buildCouponFromCode($couponCode)
|
public function buildCouponFromCode($couponCode)
|
||||||
{
|
{
|
||||||
/** @var Coupon $couponModel */
|
/** @var Coupon $couponModel */
|
||||||
$couponModel = $this->adapter->findOneCouponByCode($couponCode);
|
$couponModel = $this->facade->findOneCouponByCode($couponCode);
|
||||||
if ($couponModel === null) {
|
if ($couponModel === null) {
|
||||||
throw new NotFoundResourceException(
|
throw new NotFoundResourceException(
|
||||||
'Coupon ' . $couponCode . ' not found in Database'
|
'Coupon ' . $couponCode . ' not found in Database'
|
||||||
@@ -115,7 +115,7 @@ class CouponFactory
|
|||||||
/** @var CouponInterface $couponManager*/
|
/** @var CouponInterface $couponManager*/
|
||||||
$couponManager = $this->container->get($model->getType());
|
$couponManager = $this->container->get($model->getType());
|
||||||
$couponManager->set(
|
$couponManager->set(
|
||||||
$this->adapter,
|
$this->facade,
|
||||||
$model->getCode(),
|
$model->getCode(),
|
||||||
$model->getTitle(),
|
$model->getTitle(),
|
||||||
$model->getShortDescription(),
|
$model->getShortDescription(),
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ use Thelia\Model\Coupon;
|
|||||||
class CouponManager
|
class CouponManager
|
||||||
{
|
{
|
||||||
/** @var FacadeInterface Provides necessary value from Thelia */
|
/** @var FacadeInterface Provides necessary value from Thelia */
|
||||||
protected $adapter = null;
|
protected $facade = null;
|
||||||
|
|
||||||
/** @var ContainerInterface Service Container */
|
/** @var ContainerInterface Service Container */
|
||||||
protected $container = null;
|
protected $container = null;
|
||||||
@@ -64,8 +64,8 @@ class CouponManager
|
|||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->adapter = $container->get('thelia.facade');
|
$this->facade = $container->get('thelia.facade');
|
||||||
$this->coupons = $this->adapter->getCurrentCoupons();
|
$this->coupons = $this->facade->getCurrentCoupons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,12 +87,12 @@ class CouponManager
|
|||||||
$discount = $this->getEffect($couponsKept);
|
$discount = $this->getEffect($couponsKept);
|
||||||
|
|
||||||
if ($isRemovingPostage) {
|
if ($isRemovingPostage) {
|
||||||
$postage = $this->adapter->getCheckoutPostagePrice();
|
$postage = $this->facade->getCheckoutPostagePrice();
|
||||||
$discount += $postage;
|
$discount += $postage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just In Case test
|
// Just In Case test
|
||||||
$checkoutTotalPrice = $this->adapter->getCartTotalPrice();
|
$checkoutTotalPrice = $this->facade->getCartTotalPrice();
|
||||||
if ($discount >= $checkoutTotalPrice) {
|
if ($discount >= $checkoutTotalPrice) {
|
||||||
$discount = $checkoutTotalPrice;
|
$discount = $checkoutTotalPrice;
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ class CouponManager
|
|||||||
|
|
||||||
/** @var CouponInterface $coupon */
|
/** @var CouponInterface $coupon */
|
||||||
foreach ($coupons as $coupon) {
|
foreach ($coupons as $coupon) {
|
||||||
if ($coupon->isMatching($this->adapter)) {
|
if ($coupon->isMatching($this->facade)) {
|
||||||
$couponsKept[] = $coupon;
|
$couponsKept[] = $coupon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ class CouponManager
|
|||||||
$discount = 0.00;
|
$discount = 0.00;
|
||||||
/** @var CouponInterface $coupon */
|
/** @var CouponInterface $coupon */
|
||||||
foreach ($coupons as $coupon) {
|
foreach ($coupons as $coupon) {
|
||||||
$discount += $coupon->exec($this->adapter);
|
$discount += $coupon->exec($this->facade);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $discount;
|
return $discount;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ use Thelia\Exception\InvalidConditionException;
|
|||||||
abstract class CouponAbstract implements CouponInterface
|
abstract class CouponAbstract implements CouponInterface
|
||||||
{
|
{
|
||||||
/** @var FacadeInterface Provide necessary value from Thelia */
|
/** @var FacadeInterface Provide necessary value from Thelia */
|
||||||
protected $adapter = null;
|
protected $facade = null;
|
||||||
|
|
||||||
/** @var Translator Service Translator */
|
/** @var Translator Service Translator */
|
||||||
protected $translator = null;
|
protected $translator = null;
|
||||||
@@ -104,13 +104,13 @@ abstract class CouponAbstract implements CouponInterface
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param FacadeInterface $adapter Service adapter
|
* @param FacadeInterface $facade Service facade
|
||||||
*/
|
*/
|
||||||
public function __construct(FacadeInterface $adapter)
|
public function __construct(FacadeInterface $facade)
|
||||||
{
|
{
|
||||||
$this->adapter = $adapter;
|
$this->facade = $facade;
|
||||||
$this->translator = $adapter->getTranslator();
|
$this->translator = $facade->getTranslator();
|
||||||
$this->conditionEvaluator = $adapter->getConditionEvaluator();
|
$this->conditionEvaluator = $facade->getConditionEvaluator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
namespace Thelia\Coupon\Type;
|
namespace Thelia\Coupon\Type;
|
||||||
|
|
||||||
use Thelia\Condition\ConditionCollection;
|
use Thelia\Condition\ConditionCollection;
|
||||||
|
use Thelia\Coupon\FacadeInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
@@ -62,7 +63,7 @@ interface CouponInterface
|
|||||||
/**
|
/**
|
||||||
* Set Coupon
|
* Set Coupon
|
||||||
*
|
*
|
||||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
* @param FacadeInterface $facade Provides necessary value from Thelia
|
||||||
* @param string $code Coupon code (ex: XMAS)
|
* @param string $code Coupon code (ex: XMAS)
|
||||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
@@ -77,7 +78,7 @@ interface CouponInterface
|
|||||||
* @param \Datetime $expirationDate When the Code is expiring
|
* @param \Datetime $expirationDate When the Code is expiring
|
||||||
*/
|
*/
|
||||||
public function set(
|
public function set(
|
||||||
$adapter,
|
FacadeInterface $facade,
|
||||||
$code,
|
$code,
|
||||||
$title,
|
$title,
|
||||||
$shortDescription,
|
$shortDescription,
|
||||||
@@ -144,15 +145,15 @@ interface CouponInterface
|
|||||||
public function getConditions();
|
public function getConditions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the existing Rules by those given in parameter
|
* Replace the existing Conditions by those given in parameter
|
||||||
* If one Rule is badly implemented, no Rule will be added
|
* If one Condition is badly implemented, no Condition will be added
|
||||||
*
|
*
|
||||||
* @param ConditionCollection $rules ConditionManagerInterface to add
|
* @param ConditionCollection $conditions ConditionManagerInterface to add
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws \Thelia\Exception\InvalidConditionException
|
* @throws \Thelia\Exception\InvalidConditionException
|
||||||
*/
|
*/
|
||||||
public function setConditions(ConditionCollection $rules);
|
public function setConditions(ConditionCollection $conditions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Coupon expiration date
|
* Return Coupon expiration date
|
||||||
@@ -198,7 +199,7 @@ interface CouponInterface
|
|||||||
* A positive value
|
* A positive value
|
||||||
*
|
*
|
||||||
* Effects could also affect something else than the final Checkout price
|
* Effects could also affect something else than the final Checkout price
|
||||||
* CouponAdapter $adapter could be use to directly pass a Session value
|
* FacadeInterface $facade could be used to directly pass a Session value
|
||||||
* some would wish to modify
|
* some would wish to modify
|
||||||
* Hence affecting a wide variety of Thelia elements
|
* Hence affecting a wide variety of Thelia elements
|
||||||
*
|
*
|
||||||
@@ -207,7 +208,7 @@ interface CouponInterface
|
|||||||
public function exec();
|
public function exec();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the current Coupon is matching its conditions (Rules)
|
* Check if the current Coupon is matching its conditions
|
||||||
* Thelia variables are given by the FacadeInterface
|
* Thelia variables are given by the FacadeInterface
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Coupon\Type;
|
namespace Thelia\Coupon\Type;
|
||||||
|
|
||||||
|
use Thelia\Coupon\FacadeInterface;
|
||||||
use Thelia\Coupon\Type\CouponAbstract;
|
use Thelia\Coupon\Type\CouponAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +45,7 @@ class RemoveXAmountManager extends CouponAbstract
|
|||||||
/**
|
/**
|
||||||
* Set Coupon
|
* Set Coupon
|
||||||
*
|
*
|
||||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
* @param FacadeInterface $facade Provides necessary value from Thelia
|
||||||
* @param string $code Coupon code (ex: XMAS)
|
* @param string $code Coupon code (ex: XMAS)
|
||||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
@@ -59,7 +60,7 @@ class RemoveXAmountManager extends CouponAbstract
|
|||||||
* @param \Datetime $expirationDate When the Code is expiring
|
* @param \Datetime $expirationDate When the Code is expiring
|
||||||
*/
|
*/
|
||||||
public function set(
|
public function set(
|
||||||
$adapter,
|
FacadeInterface $facade,
|
||||||
$code,
|
$code,
|
||||||
$title,
|
$title,
|
||||||
$shortDescription,
|
$shortDescription,
|
||||||
@@ -87,7 +88,7 @@ class RemoveXAmountManager extends CouponAbstract
|
|||||||
$this->isEnabled = $isEnabled;
|
$this->isEnabled = $isEnabled;
|
||||||
$this->maxUsage = $maxUsage;
|
$this->maxUsage = $maxUsage;
|
||||||
$this->expirationDate = $expirationDate;
|
$this->expirationDate = $expirationDate;
|
||||||
$this->adapter = $adapter;
|
$this->facade = $facade;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +98,7 @@ class RemoveXAmountManager extends CouponAbstract
|
|||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->adapter
|
return $this->facade
|
||||||
->getTranslator()
|
->getTranslator()
|
||||||
->trans('Remove X amount to total cart', array(), 'constraint');
|
->trans('Remove X amount to total cart', array(), 'constraint');
|
||||||
}
|
}
|
||||||
@@ -109,7 +110,7 @@ class RemoveXAmountManager extends CouponAbstract
|
|||||||
*/
|
*/
|
||||||
public function getToolTip()
|
public function getToolTip()
|
||||||
{
|
{
|
||||||
$toolTip = $this->adapter
|
$toolTip = $this->facade
|
||||||
->getTranslator()
|
->getTranslator()
|
||||||
->trans(
|
->trans(
|
||||||
'This coupon will remove the entered amount to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
'This coupon will remove the entered amount to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||||
|
|||||||
@@ -23,8 +23,9 @@
|
|||||||
|
|
||||||
namespace Thelia\Coupon\Type;
|
namespace Thelia\Coupon\Type;
|
||||||
|
|
||||||
|
use Thelia\Coupon\FacadeInterface;
|
||||||
use Thelia\Coupon\Type\CouponAbstract;
|
use Thelia\Coupon\Type\CouponAbstract;
|
||||||
use Thelia\Exception\MissingAdapterException;
|
use Thelia\Exception\MissingFacadeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
@@ -45,7 +46,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
/**
|
/**
|
||||||
* Set Coupon
|
* Set Coupon
|
||||||
*
|
*
|
||||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
* @param FacadeInterface $facade Provides necessary value from Thelia
|
||||||
* @param string $code Coupon code (ex: XMAS)
|
* @param string $code Coupon code (ex: XMAS)
|
||||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||||
* @param string $shortDescription Coupon short description
|
* @param string $shortDescription Coupon short description
|
||||||
@@ -60,7 +61,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
* @param \Datetime $expirationDate When the Code is expiring
|
* @param \Datetime $expirationDate When the Code is expiring
|
||||||
*/
|
*/
|
||||||
public function set(
|
public function set(
|
||||||
$adapter,
|
FacadeInterface $facade,
|
||||||
$code,
|
$code,
|
||||||
$title,
|
$title,
|
||||||
$shortDescription,
|
$shortDescription,
|
||||||
@@ -87,14 +88,14 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
$this->isEnabled = $isEnabled;
|
$this->isEnabled = $isEnabled;
|
||||||
$this->maxUsage = $maxUsage;
|
$this->maxUsage = $maxUsage;
|
||||||
$this->expirationDate = $expirationDate;
|
$this->expirationDate = $expirationDate;
|
||||||
$this->adapter = $adapter;
|
$this->facade = $facade;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return effects generated by the coupon
|
* Return effects generated by the coupon
|
||||||
* A negative value
|
* A negative value
|
||||||
*
|
*
|
||||||
* @throws \Thelia\Exception\MissingAdapterException
|
* @throws \Thelia\Exception\MissingFacadeException
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
@@ -106,7 +107,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$basePrice = $this->adapter->getCartTotalPrice();
|
$basePrice = $this->facade->getCartTotalPrice();
|
||||||
|
|
||||||
return $basePrice * (( $this->percent ) / 100);
|
return $basePrice * (( $this->percent ) / 100);
|
||||||
}
|
}
|
||||||
@@ -119,7 +120,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->adapter
|
return $this->facade
|
||||||
->getTranslator()
|
->getTranslator()
|
||||||
->trans('Remove X percent to total cart', array(), 'constraint');
|
->trans('Remove X percent to total cart', array(), 'constraint');
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ class RemoveXPercentManager extends CouponAbstract
|
|||||||
*/
|
*/
|
||||||
public function getToolTip()
|
public function getToolTip()
|
||||||
{
|
{
|
||||||
$toolTip = $this->adapter
|
$toolTip = $this->facade
|
||||||
->getTranslator()
|
->getTranslator()
|
||||||
->trans(
|
->trans(
|
||||||
'This coupon will remove the entered percentage to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
'This coupon will remove the entered percentage to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ use Thelia\Log\Tlog;
|
|||||||
* Date: 8/19/13
|
* Date: 8/19/13
|
||||||
* Time: 3:24 PM
|
* Time: 3:24 PM
|
||||||
*
|
*
|
||||||
* Thrown when the Adapter is not set
|
* Thrown when the Facade is not set
|
||||||
*
|
*
|
||||||
* @package Coupon
|
* @package Coupon
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class MissingAdapterException extends \RuntimeException
|
class MissingFacadeException extends \RuntimeException
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -38,27 +38,6 @@ use Thelia\Condition\ConditionOrganizer;
|
|||||||
*/
|
*/
|
||||||
class ConditionOrganizerTest extends \PHPUnit_Framework_TestCase
|
class ConditionOrganizerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var ConditionOrganizer
|
|
||||||
*/
|
|
||||||
protected $object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
|
||||||
* This method is called before a test is executed.
|
|
||||||
*/
|
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
$this->object = new ConditionOrganizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tears down the fixture, for example, closes a network connection.
|
|
||||||
* This method is called after a test is executed.
|
|
||||||
*/
|
|
||||||
protected function tearDown()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Thelia\Coupon\RuleOrganizer::organize
|
* @covers Thelia\Coupon\RuleOrganizer::organize
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ use Thelia\Condition\ConditionEvaluator;
|
|||||||
use Thelia\Condition\ConditionFactory;
|
use Thelia\Condition\ConditionFactory;
|
||||||
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
|
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
|
||||||
use Thelia\Condition\Operators;
|
use Thelia\Condition\Operators;
|
||||||
|
use Thelia\Coupon\Type\RemoveXAmountManager;
|
||||||
use Thelia\Model\Coupon;
|
use Thelia\Model\Coupon;
|
||||||
use Thelia\Model\CurrencyQuery;
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
|
||||||
@@ -192,9 +193,14 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
|||||||
$stubFacade->expects($this->any())
|
$stubFacade->expects($this->any())
|
||||||
->method('findOneCouponByCode')
|
->method('findOneCouponByCode')
|
||||||
->will($this->returnValue($expected));
|
->will($this->returnValue($expected));
|
||||||
$stubContainer->expects($this->any())
|
$stubContainer->expects($this->at(0))
|
||||||
->method('get')
|
->method('get')
|
||||||
->will($this->returnValue($stubFacade));
|
->will($this->returnValue($stubFacade));
|
||||||
|
|
||||||
|
$couponManager = new RemoveXAmountManager();
|
||||||
|
$stubContainer->expects($this->at(1))
|
||||||
|
->method('get')
|
||||||
|
->will($this->returnValue($couponManager));
|
||||||
$stubContainer->expects($this->any())
|
$stubContainer->expects($this->any())
|
||||||
->method('has')
|
->method('has')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|||||||
Reference in New Issue
Block a user