예제 #1
0
 /**
  * @return static
  */
 public function withCartItems(CartCalculator $cartCalculator)
 {
     foreach ($this->entity->getCartItems() as $cartItem) {
         $this->entityDTO->cartItems[] = $this->dtoBuilderFactory->getCartItemDTOBuilder($cartItem)->withAllData($cartCalculator->getPricing())->build();
     }
     return $this;
 }
예제 #2
0
 private function calculateCartPriceRules()
 {
     foreach ($this->pricing->getCartPriceRules() as $cartPriceRule) {
         if ($cartPriceRule->isValid($this->pricing->getDate(), $this->cart->getCartItems())) {
             $numberTimesToApply = $cartPriceRule->numberTimesToApply($this->cart->getCartItems());
             foreach ($cartPriceRule->getCartPriceRuleDiscounts() as $discount) {
                 $price = $this->pricing->getPrice($discount->getProduct(), $discount->getQuantity());
                 $discountValue = $price->quantityPrice;
                 $discountValue *= $numberTimesToApply;
                 $this->cartTotal->discount += $discountValue;
                 if ($cartPriceRule->getReducesTaxSubtotal() and $discount->getProduct()->isTaxable()) {
                     $this->cartTotal->taxSubtotal -= $discountValue;
                 }
                 $this->cartTotal->addCartPriceRule($cartPriceRule);
             }
         }
     }
     // No subtotal below zero!
     $this->cartTotal->subtotal = max(0, $this->cartTotal->subtotal);
 }
예제 #3
0
 public function testCreateDefaults()
 {
     $cart = new Cart();
     $this->assertTrue($cart->getId() instanceof UuidInterface);
     $this->assertTrue($cart->getCreated() instanceof DateTime);
     $this->assertSame(null, $cart->getSessionId());
     $this->assertSame(null, $cart->getUser());
     $this->assertSame(null, $cart->getShippingAddress());
     $this->assertSame(null, $cart->getShipmentRate());
     $this->assertSame(null, $cart->getTaxRate());
     $this->assertSame('0.0.0.0', $cart->getIp4());
     $this->assertSame(0, count($cart->getCartItems()));
     $this->assertSame(0, count($cart->getCoupons()));
 }
예제 #4
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;
 }