Improved and simplified coupon form management

This commit is contained in:
Franck Allimant
2014-05-30 19:58:02 +02:00
parent a018102572
commit 0683d20d2c
15 changed files with 317 additions and 142 deletions

View File

@@ -184,7 +184,8 @@ class Coupon extends BaseCoupon
*/
public function getAmount()
{
$amount = $this->getEffects()['amount'];
// Amount is now optional
$amount = isset($this->getEffects()['amount']) ? $this->getEffects()['amount'] : 0;
return floatval($amount);
}
@@ -199,10 +200,6 @@ class Coupon extends BaseCoupon
{
$effects = $this->unserializeEffects($this->getSerializedEffects());
if (null === $effects['amount']) {
throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect coming from database');
}
return $effects;
}
@@ -210,18 +207,12 @@ class Coupon extends BaseCoupon
* Get the Coupon effects
*
* @param array $effects Effect ready to be serialized
* Needs at least the key 'amount'
* with the amount removed from the cart
*
* @throws Exception\InvalidArgumentException
* @return $this
*/
public function setEffects(array $effects)
{
if (null === $effects['amount']) {
throw new InvalidArgumentException('Missing key \'amount\' in Coupon effect ready to be serialized array');
}
$this->setSerializedEffects($this->serializeEffects($effects));
return $this;