예제 #1
0
 /**
  * @return static
  */
 public function withCoupons()
 {
     foreach ($this->entity->getCoupons() as $key => $coupon) {
         $this->entityDTO->coupons[$key] = $this->dtoBuilderFactory->getCouponDTOBuilder($coupon)->build();
     }
     return $this;
 }
예제 #2
0
 private function calculateTaxes()
 {
     $taxRate = $this->cart->getTaxRate();
     if ($taxRate !== null) {
         $this->cartTotal->tax = $taxRate->getTax($this->cartTotal->taxSubtotal, $this->cartTotal->shipping - $this->cartTotal->shippingDiscount);
         if ($this->cartTotal->tax > 0) {
             $this->cartTotal->taxRate = $taxRate;
         }
     }
 }
예제 #3
0
 /**
  * @param UuidInterface $orderId
  * @param User $user
  * @param Cart $cart
  * @param CartCalculatorInterface $cartCalculator
  * @param string $ip4
  * @return Order
  */
 public static function fromCart(UuidInterface $orderId, User $user, Cart $cart, CartCalculatorInterface $cartCalculator, $ip4)
 {
     $order = new Order($orderId);
     $order->setIp4($ip4);
     foreach ($cart->getCartItems() as $item) {
         $order->addOrderItem($item->getOrderItem($order, $cartCalculator->getPricing()));
     }
     foreach ($cart->getCoupons() as $coupon) {
         $order->addCoupon($coupon);
     }
     $order->setUser($user);
     $order->setTaxRate($cart->getTaxRate());
     $order->setShipmentRate($cart->getShipmentRate());
     $order->setTotal($cart->getTotal($cartCalculator));
     return $order;
 }
예제 #4
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;
 }
예제 #5
0
 private function addUserToCartIfExists(Cart &$cart, UuidInterface $userId = null)
 {
     if (!empty($userId)) {
         $user = $this->userRepository->findOneById($userId);
         $cart->setUser($user);
     }
 }
예제 #6
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));
 }
예제 #7
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);
 }