Exemple #1
0
 public function testCreate()
 {
     $cartItem = $this->dummyData->getCartItem();
     $coupon = $this->dummyData->getCoupon();
     $shipmentRate = $this->dummyData->getShipmentRate();
     $orderAddress = $this->dummyData->getOrderAddress();
     $taxRate = $this->dummyData->getTaxRate();
     $cart = new Cart();
     $cart->setSessionId('6is7ujb3crb5ja85gf91g9en62');
     $cart->setIp4('10.0.0.1');
     $cart->addCartItem($cartItem);
     $cart->addCoupon($coupon);
     $cart->setShipmentRate($shipmentRate);
     $cart->setShippingAddress($orderAddress);
     $cart->setTaxRate($taxRate);
     $this->assertEntityValid($cart);
     $this->assertTrue($cart instanceof Cart);
     $this->assertSame('10.0.0.1', $cart->getIp4());
     $this->assertSame('6is7ujb3crb5ja85gf91g9en62', $cart->getSessionId());
     $this->assertSame($cartItem, $cart->getCartItems()[0]);
     $this->assertSame($coupon, $cart->getCoupons()[0]);
     $this->assertSame($shipmentRate, $cart->getShipmentRate());
     $this->assertSame($orderAddress, $cart->getShippingAddress());
     $this->assertSame($taxRate, $cart->getTaxRate());
 }
 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));
 }