Ejemplo n.º 1
0
 public function testGetTotalWithZip5TaxAndCouponNoReduceSubtotal()
 {
     $product = new Product();
     $product->setUnitPrice(2000);
     $product->setIsTaxable(true);
     $taxRate = new TaxRate();
     $taxRate->setZip5(92606);
     $taxRate->setRate(8.0);
     $taxRate->setApplyToShipping(false);
     $coupon = $this->dummyData->getCoupon();
     $coupon->setName('20% Off orders under $100');
     $coupon->setType(PromotionType::percent());
     $coupon->setValue(20);
     $coupon->setMinOrderValue(1000);
     $coupon->setMaxOrderValue(10000);
     $coupon->setReducesTaxSubtotal(false);
     $cartItem = new CartItem();
     $cartItem->setProduct($product);
     $cartItem->setQuantity(1);
     $cart = new Cart();
     $cart->addCoupon($coupon);
     $cart->addCartItem($cartItem);
     $cart->setTaxRate($taxRate);
     $expectedCartTotal = new CartTotal();
     $expectedCartTotal->origSubtotal = 2000;
     $expectedCartTotal->subtotal = 2000;
     $expectedCartTotal->taxSubtotal = 2000;
     $expectedCartTotal->shipping = 0;
     $expectedCartTotal->discount = 400;
     $expectedCartTotal->tax = 160;
     $expectedCartTotal->total = 1760;
     $expectedCartTotal->savings = 400;
     $expectedCartTotal->coupons = [$coupon];
     $expectedCartTotal->taxRate = $taxRate;
     $cartCalculator = new CartCalculator(new Pricing());
     $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart));
 }
Ejemplo n.º 2
0
 /**
  * @param CartItem[] $cartItems
  * @return Cart
  */
 public function getCart(array $cartItems = [])
 {
     $cart = new Cart();
     $cart->setIp4('10.0.0.1');
     $cart->setShippingAddress($this->getOrderAddress());
     foreach ($cartItems as $cartItem) {
         $cart->addCartItem($cartItem);
     }
     return $cart;
 }
Ejemplo n.º 3
0
 public function testGetTotal()
 {
     $cartItem = $this->dummyData->getCartItem(null, 2);
     $cartItem->getProduct()->setUnitPrice(500);
     $cart = new Cart();
     $cart->addCartItem($cartItem);
     $cartCalculator = $this->getCartCalculator();
     $this->assertTrue($cart->getTotal($cartCalculator) instanceof CartTotal);
 }