private function calculateShippingPrice() { $shipmentRate = $this->cart->getShipmentRate(); if ($shipmentRate !== null) { $this->cartTotal->shipping = $shipmentRate->getRate()->getAmount(); } }
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())); }
public function __construct(Cart $cart, DTOBuilderFactoryInterface $dtoBuilderFactory) { $this->entity = $cart; $this->dtoBuilderFactory = $dtoBuilderFactory; $this->entityDTO = new CartDTO(); $this->setId(); $this->setTime(); $this->entityDTO->totalItems = $this->entity->totalItems(); $this->entityDTO->totalQuantity = $this->entity->totalQuantity(); $this->entityDTO->shippingWeight = $this->entity->getShippingWeight(); $this->entityDTO->shippingWeightInPounds = $this->entity->getShippingWeightInPounds(); if ($cart->getShipmentRate() !== null) { $this->entityDTO->shipmentRate = $this->dtoBuilderFactory->getShipmentRateDTOBuilder($cart->getShipmentRate())->build(); } if ($cart->getShippingAddress() !== null) { $this->entityDTO->shippingAddress = $this->dtoBuilderFactory->getOrderAddressDTOBuilder($cart->getShippingAddress())->build(); } if ($cart->getTaxRate() !== null) { $this->entityDTO->taxRate = $this->dtoBuilderFactory->getTaxRateDTOBuilder($cart->getTaxRate())->build(); } if ($cart->getUser() !== null) { $this->entityDTO->user = $this->dtoBuilderFactory->getUserDTOBuilder($cart->getUser())->build(); } }
/** * @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; }