Working adding decrementation when coupon is consumed

This commit is contained in:
gmorel
2013-10-22 23:04:08 +02:00
parent b45fbef2ad
commit 52e471ab1b
4 changed files with 37 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ namespace Thelia\Coupon;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Condition\ConditionManagerInterface;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Coupon;
/**
* Created by JetBrains PhpStorm.
@@ -228,4 +229,34 @@ class CouponManager
{
return $this->availableConditions;
}
/**
* Decrement this coupon quantity
*
* To call when a coupon is consumed
*
* @param \Thelia\Model\Coupon $coupon Coupon consumed
*
* @return bool
*/
public function decrementeQuantity(Coupon $coupon)
{
$ret = true;
try {
$oldMaxUsage = $coupon->getMaxUsage();
if ($oldMaxUsage > 0) {
$oldMaxUsage--;
$coupon->setMaxUsage($$oldMaxUsage);
$coupon->save();
}
} catch(\Exception $e) {
$ret = false;
}
return $ret;
}
}

View File

@@ -307,5 +307,4 @@ abstract class CouponAbstract implements CouponInterface
return $this->conditionEvaluator->isMatching($this->conditions);
}
}