Пример #1
0
 /**
  * @return static
  */
 public function withCartItemTextOptionValues()
 {
     foreach ($this->entity->getCartItemTextOptionValues() as $cartItemTextOptionValue) {
         $this->entityDTO->cartItemTextOptionValues[] = $this->dtoBuilderFactory->getCartItemTextOptionValueDTOBuilder($cartItemTextOptionValue)->withTextOption()->build();
     }
     return $this;
 }
 public function matches(CartItem $cartItem)
 {
     if ($cartItem->getProduct()->getId() == $this->product->getId() and $cartItem->getQuantity() >= $this->quantity) {
         return true;
     }
     return false;
 }
 public function matches(CartItem $cartItem)
 {
     foreach ($cartItem->getProduct()->getTags() as $tag) {
         if ($tag->getId() === $this->tag->getId() and $cartItem->getQuantity() >= $this->quantity) {
             return true;
         }
     }
     return false;
 }
Пример #4
0
 public function testCreate()
 {
     $pricing = $this->dummyData->getPricing();
     $cart = $this->dummyData->getCart();
     $cartItemOptionProduct = $this->dummyData->getCartItemOptionProduct();
     $cartItemOptionValue = $this->dummyData->getCartItemOptionValue();
     $cartItemTextOptionValue = $this->dummyData->getCartItemTextOptionValue();
     $product = $this->dummyData->getProduct();
     $product->setShippingWeight(1);
     $product->setSku('P1');
     $cartItemOptionProduct->getOptionProduct()->getProduct()->setSku('OP1');
     $cartItemOptionProduct->getOptionProduct()->getProduct()->setShippingWeight(3);
     $cartItemOptionValue->getOptionValue()->setSku('OV1');
     $cartItemOptionValue->getOptionValue()->setShippingWeight(5);
     $cartItem = new CartItem();
     $cartItem->setProduct($product);
     $cartItem->setQuantity(2);
     $cartItem->setCart($cart);
     $cartItem->addCartItemOptionProduct($cartItemOptionProduct);
     $cartItem->addCartItemOptionValue($cartItemOptionValue);
     $cartItem->addCartItemTextOptionValue($cartItemTextOptionValue);
     $this->assertEntityValid($cartItem);
     $this->assertTrue($cartItem instanceof CartItem);
     $this->assertTrue($cartItem->getPrice($pricing) instanceof Price);
     $this->assertSame(2, $cartItem->getQuantity());
     $this->assertSame('P1-OP1-OV1', $cartItem->getFullSku());
     $this->assertSame(18, $cartItem->getShippingWeight());
     $this->assertSame($cart, $cartItem->getCart());
     $this->assertSame($cartItemOptionProduct, $cartItem->getCartItemOptionProducts()[0]);
     $this->assertSame($cartItemOptionValue, $cartItem->getCartItemOptionValues()[0]);
     $this->assertSame($cartItemTextOptionValue, $cartItem->getCartItemTextOptionValues()[0]);
 }
Пример #5
0
 public function addCartItem(CartItem $cartItem)
 {
     $cartItem->setCart($this);
     $this->cartItems->add($cartItem);
 }
Пример #6
0
 public function getCartItemFull()
 {
     $tag = $this->getTag();
     $tag->addImage($this->getImage());
     $product = $this->getProduct();
     $product->setSku('P1');
     $product->setUnitPrice(100);
     $product->setShippingWeight(10);
     $product->addTag($tag);
     $product->addProductQuantityDiscount($this->getProductQuantityDiscount());
     $product2 = $this->getProduct();
     $product2->setSku('OP1');
     $product2->setUnitPrice(100);
     $product2->setShippingWeight(10);
     $option1 = $this->getOption();
     $option1->setName('Option 1');
     $optionProduct = $this->getOptionProduct($option1, $product2);
     $option2 = $this->getOption();
     $option2->setName('Option 2');
     $optionValue = $this->getOptionValue($option2);
     $optionValue->setSku('OV1');
     $optionValue->setUnitPrice(100);
     $optionValue->setShippingWeight(10);
     $textOption = $this->getTextOption();
     $cartItemOptionProduct = $this->getCartItemOptionProduct($optionProduct);
     $cartItemOptionValue = new CartItemOptionValue();
     $cartItemOptionValue->setOptionValue($optionValue);
     $cartItemTextOptionValue = new CartItemTextOptionValue();
     $cartItemTextOptionValue->setTextOption($textOption);
     $cartItemTextOptionValue->setTextOptionValue('Happy Birthday');
     $cartItem = new CartItem();
     $cartItem->setProduct($product);
     $cartItem->setQuantity(2);
     $cartItem->setCart(new Cart());
     $cartItem->addCartItemOptionProduct($cartItemOptionProduct);
     $cartItem->addCartItemOptionValue($cartItemOptionValue);
     $cartItem->addCartItemTextOptionValue($cartItemTextOptionValue);
     return $cartItem;
 }
Пример #7
0
 /**
  * @param UuidInterface $cartItemId
  * @param UuidInterface $cartId
  * @param UuidInterface $productId
  * @param int $quantity
  * @return CartItem
  */
 public function addItem(UuidInterface $cartItemId, UuidInterface $cartId, UuidInterface $productId, $quantity = 1)
 {
     $product = $this->productRepository->findOneById($productId);
     $cart = $this->cartRepository->findOneById($cartId);
     $cart->setShipmentRate(null);
     $cartItem = new CartItem($cartItemId);
     $cartItem->setProduct($product);
     $cartItem->setQuantity($quantity);
     $cart->addCartItem($cartItem);
     $this->cartRepository->update($cart);
     return $cartItem;
 }
Пример #8
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));
 }