Added isInUse() method to the CouponInterface

This commit is contained in:
Franck Allimant
2014-07-22 18:59:58 +02:00
parent bc57c879c0
commit bfd9a6ac7d
2 changed files with 24 additions and 12 deletions

View File

@@ -183,6 +183,7 @@ abstract class CouponAbstract implements CouponInterface
/**
* @param true $perCustomerUsageCount
* @return $this
*/
public function setPerCustomerUsageCount($perCustomerUsageCount)
{
@@ -425,14 +426,14 @@ abstract class CouponAbstract implements CouponInterface
* This methods checks a field value. If the field has a correct value, this value is returned
* Otherwise, an InvalidArgumentException describing the problem should be thrown.
*
* This method should be ovveriden to be useful.
* This method should be overriden to be useful.
*
* @param $fieldName
* @param $fieldValue
* @param string $fieldName
* @param string $fieldValue
* @return mixed
* @throws \InvalidArgumentException if the field valiue is not valid.
* @throws \InvalidArgumentException if the field value is not valid.
*/
protected function checkCouponFieldValue($fieldName, $fieldValue)
protected function checkCouponFieldValue(/** @noinspection PhpUnusedParameterInspection */ $fieldName, $fieldValue)
{
return $fieldValue;
}
@@ -507,4 +508,11 @@ abstract class CouponAbstract implements CouponInterface
{
// Does nothing. Override this function as needed.
}
public function isInUse() {
return in_array(
$this->code,
$this->facade->getRequest()->getSession()->getConsumedCoupons()
);
}
}

View File

@@ -192,15 +192,15 @@ interface CouponInterface
public function isExpired();
/**
* Return effects generated by the coupon
* A positive value
* Return an amount thant will be subtracted to the cart total, or zero.
*
* Effects could also affect something else than the final Checkout price
* FacadeInterface $facade could be used to directly pass a Session value
* some would wish to modify
* Hence affecting a wide variety of Thelia elements
* This method could also perform something else than the calculating an amount to subtract from the cart. It may
* add a product to the cart, for example. In this case, an amount of 0 will be returned.
*
* @return float Amount removed from the Total Checkout
* WARNING: this method could be called several times, so perform suitable checks before performing cart
* manipulations, so that the coupon effect will not be applied several times.
*
* @return float Amount removed from the cart total
*/
public function exec();
@@ -244,4 +244,8 @@ interface CouponInterface
*/
public function clear();
/**
* @return bool true if the coupon is currently in use in the current order process, false otherwise
*/
public function isInUse();
}