Beispiel #1
0
 /**
  * @group coupon
  */
 public function testCartCouponBogoHalf()
 {
     $term = new Term(1);
     $term->setOld(12.0);
     $term->setPrice(12.0);
     $product = new ProductDomain();
     $product->setId('.com');
     $product->setTitle('.com Registration');
     $product->getBilling()->addTerm($term);
     $catalog = $this->getCatalog();
     $catalog->addProduct($product);
     $item = $catalog->getCartItem($product, null, ['domain' => 'example.com']);
     $item_2 = $catalog->getCartItem($product, null, ['domain' => 'example-2.com']);
     $item_3 = $catalog->getCartItem($product, null, ['domain' => 'example-3.com']);
     $cart = $this->getCart();
     $cart->add($item);
     $cart->add($item_2);
     $cart->add($item_3);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('BUY_ONE_GET_ONE_HALF');
     $coupon->calculateDiscount($cart);
     $items = $cart->all();
     $this->assertEquals(0, $items[0]->getDiscount());
     $this->assertEquals(6, $items[1]->getDiscount());
     $this->assertEquals(0, $items[2]->getDiscount());
 }
Beispiel #2
0
 /**
  * @group coupon
  */
 public function testCartCouponFixedPrice()
 {
     $period = 10;
     $term = new Term($period);
     $term->setOld(12);
     $term->setPrice(10);
     $term->setTrial(1);
     $term2 = new Term($period);
     $term2->setPrice(2);
     $product = new ProductSharedHosting();
     $product->setId(21);
     $product->setTitle('Silver');
     $product->getBilling()->addTerm($term);
     $ssl = new ProductSsl();
     $ssl->setId(22);
     $ssl->getBilling()->addTerm($term2);
     $catalog = $this->getCatalog();
     $item = $catalog->getCartItem($product, null, ['plan' => 'silver']);
     $item_ssl = $catalog->getCartItem($ssl, null, []);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('5_DOLLAR_SALE');
     $cart = $this->getCart();
     $cart->add($item);
     $cart->add($item_ssl);
     $coupon->calculateDiscount($cart);
     $items = $cart->all();
     //price should be 5 * $period because fixed $5 coupon is set
     $this->assertEquals(5 * $period, $items[0]->getPriceWithDiscount());
     //price should not be affected because initial price is lower than $5
     $this->assertEquals(2 * $period, $items[1]->getPriceWithDiscount());
     $this->assertEquals($items[1]->getPrice(), $items[1]->getPriceWithDiscount());
 }
Beispiel #3
0
 public function import(array $array)
 {
     foreach ($array as $id => $p) {
         $billing = new Billing();
         foreach ($p['billing'] as $t) {
             $term = new Term($t['period']);
             $term->setOld($t['old']);
             $term->setTrial($t['trial']);
             $term->setPrice($t['price']);
             $billing->addTerm($term);
         }
         $product = new $p['__class']();
         $product->setId($p['id']);
         $product->setTitle($p['title']);
         $product->setDescription($p['description']);
         $product->setBilling($billing);
         $this->addProduct($product);
     }
 }
 /**
  * @group coupon
  */
 public function testCartCouponPercent()
 {
     $term = new Term(1);
     $term->setOld(12);
     $term->setPrice(10);
     $product = new ProductSharedHosting();
     $product->setId(21);
     $product->setTitle('Silver');
     $product->getBilling()->addTerm($term);
     $catalog = $this->getCatalog();
     $item = $catalog->getCartItem($product, null, ['plan' => 'silver']);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('CYBER');
     $cart = $this->getCart();
     $cart->add($item);
     $coupon->calculateDiscount($cart);
     $items = $cart->all();
     $this->assertEquals(2.5, $items[0]->getDiscount());
 }
Beispiel #5
0
 /**
  * @dataProvider testCartCouponFreeAddonAddedFirstProvicer
  * @group coupon
  */
 public function testCartCouponFreeAddonAddedFirst($termDomain, $termSSL, $isDomainFree, $isSSLFree)
 {
     $term = new Term($termDomain);
     $term->setOld(14.99);
     $term->setPrice(12.99);
     $term_ssl = new Term($termSSL);
     $term_ssl->setTrial(15);
     $term_ssl->setOld(0);
     $term_ssl->setPrice(49.0);
     $product = new ProductDomain();
     $product->setId('.com');
     $product->setTitle('.com Registration');
     $product->getBilling()->addTerm($term);
     $hosting = new ProductSharedHosting();
     $hosting->setId(24);
     $hosting->setTitle('Premium');
     $hosting->getBilling()->addTerm($term);
     $ssl = new ProductSsl();
     $ssl->setId(21);
     $ssl->setTitle('SSL Certificate');
     $ssl->getBilling()->addTerm($term_ssl);
     $catalog = $this->getCatalog();
     $item = $catalog->getCartItem($product, null, ['domain' => 'example.com']);
     $item_hosting = $catalog->getCartItem($hosting);
     $item_3 = $catalog->getCartItem($product, null, ['domain' => 'example-3.com']);
     $item_ssl = $catalog->getCartItem($ssl);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('BUY_HOSTING_GET_DOMAIN_AND_SSL_FREE');
     $cart = $this->getCart();
     $cart->add($item);
     $cart->add($item_hosting);
     $cart->add($item_3);
     $cart->add($item_ssl);
     $coupon->calculateDiscount($cart);
     $items = $cart->all();
     $expectedDomainDiscount = $isDomainFree ? $items[0]->getPrice() : 0;
     $expectedSSLDiscount = $isSSLFree ? $items[3]->getPrice() : 0;
     $this->assertEquals($expectedDomainDiscount, $items[0]->getDiscount());
     $this->assertEquals(0, $items[1]->getDiscount());
     $this->assertEquals(0, $items[2]->getDiscount());
     $this->assertEquals($expectedSSLDiscount, $items[3]->getDiscount());
 }