Improved and simplified coupon form management
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user