WIP Coupon

Refactor : creating dedicated reusable module for Constraints
Adding ConstraintManager
Secured :
- Effects : RemoveXPercent + RemoveXAmount
- Validators : all  except ModelParam (need CustomerModelParam, AreaModelParam, CountryModelParam ?)
- Conditions : AvailableForTotalAmount
This commit is contained in:
gmorel
2013-08-28 09:33:33 +02:00
parent c24e82758f
commit 50d50d3b91
19 changed files with 350 additions and 265 deletions

View File

@@ -168,12 +168,9 @@ abstract class CouponAbstract implements CouponInterface
* Return effects generated by the coupon
* A negative value
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @return float Amount removed from the Total Checkout
*/
public function getDiscount(CouponAdapterInterface $adapter)
public function getDiscount()
{
return $this->amount;
}

View File

@@ -88,16 +88,13 @@ interface CouponInterface
* A positive value
*
* Effects could also affect something else than the final Checkout price
* CouponAdapter could be use to directly pass a Session value
* CouponAdapter $adapter could be use to directly pass a Session value
* some would wish to modify
* Hence affecting a wide variety of Thelia elements
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @return float Amount removed from the Total Checkout
*/
public function getDiscount(CouponAdapterInterface $adapter);
public function getDiscount();
/**
* Return condition to validate the Coupon or not

View File

@@ -92,14 +92,11 @@ class RemoveXPercent extends CouponAbstract
* Return effects generated by the coupon
* A negative value
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Thelia\Exception\MissingAdapterException
* @throws \InvalidArgumentException
* @return float
*/
public function getDiscount(CouponAdapterInterface $adapter)
public function getDiscount()
{
if ($this->percent >= 100) {
throw new \InvalidArgumentException(
@@ -107,7 +104,7 @@ class RemoveXPercent extends CouponAbstract
);
}
$basePrice = $adapter->getCartTotalPrice();
$basePrice = $this->adapter->getCartTotalPrice();
return $basePrice * (( $this->percent ) / 100);
}