/**
  * @group coupon
  */
 public function testCartOverAmountCouppon()
 {
     $term = new Term(1);
     $term->setPrice(100);
     $product = new ProductSharedHosting();
     $product->setTitle('Silver');
     $product->getBilling()->addTerm($term);
     $catalog = $this->getCatalog();
     $item = $catalog->getCartItem($product, null, ['plan' => 'silver']);
     $cart = $this->getCart();
     $cart->add($item);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('15_PERCENT_OFF_OVER_30');
     $coupon->calculateDiscount($cart);
     $this->assertEquals(15, $cart->getDiscount());
 }
 /**
  * @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());
 }
 /**
  * @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());
 }
 /**
  * @group coupon
  */
 public function testFixedPriceForTerm()
 {
     $term = new Term(12);
     $term->setPrice(6);
     $term_2 = new Term(36);
     $term_2->setPrice(5);
     $product = new ProductSharedHosting();
     $product->setId(21);
     $product->setTitle('Silver');
     $product->getBilling()->addTerm($term);
     $product->getBilling()->addTerm($term_2);
     $catalog = $this->getCatalog();
     $item_1 = $catalog->getCartItem($product, $term, ['plan' => 'silver']);
     $item_2 = $catalog->getCartItem($product, $term_2, ['plan' => 'gold']);
     $cart = $this->getCart();
     $cart->add($item_1);
     $cart->add($item_2);
     $coupons = $this->getCouponsCollection();
     $coupon = $coupons->getCoupon('1_DOLLAR_HOSTING');
     $coupon->calculateDiscount($cart);
     $items = $cart->all();
     $this->assertEquals(2, $cart->totalItems());
     // only 12 months term has 1 dollar price
     $this->assertEquals(1 * $term->getPeriod(), $items[0]->getPriceWithDiscount());
     //other term does not have discount
     $this->assertEquals(5 * $term_2->getPeriod(), $items[1]->getPriceWithDiscount(), 'other item in cart failed');
 }
Exemple #5
0
 public function testGetCartItem()
 {
     $term = new Term(1);
     $product = new Product();
     $product->getBilling()->addTerm($term);
     $productDomain = new ProductDomain();
     $productDomain->getBilling()->addTerm($term);
     $productSharedHosting = new ProductSharedHosting();
     $productSharedHosting->getBilling()->addTerm($term);
     $productCpanelHosting = new ProductCpanelHosting();
     $productCpanelHosting->getBilling()->addTerm($term);
     $productVps = new ProductVps();
     $productVps->getBilling()->addTerm($term);
     $productSsl = new ProductSsl();
     $productSsl->getBilling()->addTerm($term);
     $catalog = new Catalog();
     $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($productCpanelHosting));
     $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($productSsl));
     $this->assertInstanceOf('\\Cart\\CartItemVps', $catalog->getCartItem($productVps));
     $this->assertInstanceOf('\\Cart\\CartItemSharedHosting', $catalog->getCartItem($productSharedHosting));
     $this->assertInstanceOf('\\Cart\\CartItemDomain', $catalog->getCartItem($productDomain));
     $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($product));
 }