コード例 #1
0
 /**
  * @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');
 }
コード例 #2
0
ファイル: CouponBogoHalfTest.php プロジェクト: falkbizz/cart
 /**
  * @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());
 }
コード例 #3
0
 /**
  * @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());
 }
コード例 #4
0
ファイル: CouponTest.php プロジェクト: falkbizz/cart
 /**
  * @dataProvider testApplicableProvider
  * @group coupon
  */
 public function testApplicable($period, $products, $applied)
 {
     $term = new Term($period);
     $term->setPrice(12.0);
     $product = new \Cart\Catalog\Product();
     $product->setId(24);
     $product->getBilling()->addTerm($term);
     $catalog = new Catalog();
     $item = $catalog->getCartItem($product);
     $cart = $this->getCart();
     $cart->add($item);
     $total = $cart->total();
     $coupon = new Coupon('COUPON');
     $coupon->setProducts($products);
     $coupon->setType('PercentDiscount');
     $coupon->setConfig(['percent' => 50]);
     $coupon->calculateDiscount($cart);
     $this->assertEquals($total != $cart->total(), $applied);
 }
コード例 #5
0
ファイル: Catalog.php プロジェクト: falkbizz/cart
 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);
     }
 }
コード例 #6
0
 /**
  * @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());
 }
コード例 #7
0
ファイル: CouponFreeAddonTest.php プロジェクト: falkbizz/cart
 /**
  * @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());
 }
コード例 #8
0
ファイル: TermTest.php プロジェクト: falkbizz/cart
 public function testString()
 {
     $term = new Term('1');
     $this->assertEquals(1, $term->getPeriod());
 }
コード例 #9
0
ファイル: Billing.php プロジェクト: falkbizz/cart
 public function getPriceForTerm(Term $term)
 {
     return $this->getTerm($term->getPeriod())->getTotalPrice();
 }