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 testGetTotalWithZip5TaxAppliedToShipping()
 {
     $product = new Product();
     $product->setUnitPrice(500);
     $product->setIsTaxable(true);
     $taxRate = new TaxRate();
     $taxRate->setZip5(92606);
     $taxRate->setRate(8.0);
     $taxRate->setApplyToShipping(true);
     $cartItem = new CartItem();
     $cartItem->setProduct($product);
     $cartItem->setQuantity(2);
     $cart = new Cart();
     $cart->addCartItem($cartItem);
     $cart->setShipmentRate(new ShipmentRate(new Money(1000, 'USD')));
     $cart->setTaxRate($taxRate);
     $expectedCartTotal = new CartTotal();
     $expectedCartTotal->origSubtotal = 1000;
     $expectedCartTotal->subtotal = 1000;
     $expectedCartTotal->taxSubtotal = 1000;
     $expectedCartTotal->shipping = 1000;
     $expectedCartTotal->discount = 0;
     $expectedCartTotal->tax = 160;
     $expectedCartTotal->total = 2160;
     $expectedCartTotal->savings = 0;
     $expectedCartTotal->taxRate = $taxRate;
     $cartCalculator = new CartCalculator(new Pricing());
     $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart));
 }