Exemplo n.º 1
0
 public function testGetCoupon()
 {
     $collection = new CouponCollection();
     $coupon = new Coupon();
     $coupon->setCode('BLACK');
     $collection->addCoupon($coupon);
     $coupon = new Coupon();
     $coupon->setCode('CYBER');
     $collection->addCoupon($coupon);
     $coupon = new Coupon();
     $coupon->setCode('HANUKA');
     $collection->addCoupon($coupon);
     $this->assertInstanceOf('\\Cart\\Coupon\\Coupon', $collection->getCoupon('BLACK'));
     $this->assertInstanceOf('\\Cart\\Coupon\\Coupon', $collection->getCoupon('CYBER'));
     $this->assertInstanceOf('\\Cart\\Coupon\\Coupon', $collection->getCoupon('HANUKA'));
 }
Exemplo n.º 2
0
 public function import(array $array)
 {
     foreach ($array as $p) {
         $coupon = new Coupon();
         $coupon->setCode($p['code']);
         $coupon->setType($p['type']);
         if (isset($p['products']) && !empty($p['products'])) {
             $coupon->setProducts($p['products']);
         }
         if (isset($p['config']) && !empty($p['config'])) {
             $coupon->setConfig($p['config']);
         }
         if (isset($p['valid_from']) && !empty($p['valid_from'])) {
             $coupon->setValidFrom($p['valid_from']);
         }
         if (isset($p['valid_until']) && !empty($p['valid_until'])) {
             $coupon->setValidUntil($p['valid_until']);
         }
         $this->addCoupon($coupon);
     }
 }