diff --git a/src/modules/Cart/Service.php b/src/modules/Cart/Service.php index c7b7794f7..a1f31760a 100644 --- a/src/modules/Cart/Service.php +++ b/src/modules/Cart/Service.php @@ -424,6 +424,14 @@ class Service implements InjectionAwareInterface if (!$this->isClientAbleToUsePromo($client, $promo)) { throw new \Box_Exception('You have already used this promo code. Please remove promo code and checkout again.', null, 9874); } + + if (!$promo instanceof \Model_Promo) { + throw new \Box_Exception('Promo code is expired or does not exist'); + } + + if (!$this->isPromoAvailableForClientGroup($promo)) { + throw new \Box_Exception('Promo can not be applied to your account'); + } } $this->di['events_manager']->fire( diff --git a/tests/modules/Cart/ServiceTest.php b/tests/modules/Cart/ServiceTest.php index 17b93b7f3..7db4d7ed3 100644 --- a/tests/modules/Cart/ServiceTest.php +++ b/tests/modules/Cart/ServiceTest.php @@ -654,13 +654,15 @@ class ServiceTest extends \BBTestCase $order->loadBean(new \DummyBean()); $serviceMock = $this->getMockBuilder('\Box\Mod\Cart\Service') - ->setMethods(array('createFromCart', 'isClientAbleToUsePromo', 'rm'))->getMock(); + ->setMethods(array('createFromCart', 'isClientAbleToUsePromo', 'rm', 'isPromoAvailableForClientGroup'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('createFromCart') ->will($this->returnValue(array($order, rand(1, 100), array(rand(1, 100))))); $serviceMock->expects($this->atLeastOnce())->method('isClientAbleToUsePromo') ->will($this->returnValue(true)); $serviceMock->expects($this->atLeastOnce())->method('rm') ->will($this->returnValue(true)); + $serviceMock->expects($this->atLeastOnce())->method('isPromoAvailableForClientGroup') + ->will($this->returnValue(true)); $eventMock = $this->getMockBuilder('\Box_EventManager')->getMock(); $eventMock->expects($this->atLeastOnce())->method('fire'); @@ -671,7 +673,6 @@ class ServiceTest extends \BBTestCase ->method('getClientAddress') ->will($this->returnValue('1.1.1.1')); - $invoice = new \Model_Invoice(); $invoice->loadBean(new \DummyBean()); $invoice->hash = sha1('str');