/**
  * @return static
  */
 public function withCartPriceRuleDiscounts()
 {
     foreach ($this->entity->getCartPriceRuleDiscounts() as $cartPriceRuleDiscount) {
         $this->entityDTO->cartPriceRuleDiscounts[] = $this->dtoBuilderFactory->getCartPriceRuleDiscountDTOBuilder($cartPriceRuleDiscount)->build();
     }
     return $this;
 }
 public function testIsValid()
 {
     $product1 = $this->dummyData->getProduct();
     $cartPriceRuleProductItem1 = $this->dummyData->getCartPriceRuleProductItem($product1, 1);
     $cartItems = new ArrayCollection([$this->dummyData->getCartItem($product1, 1)]);
     $cartPriceRule = new CartPriceRule();
     $cartPriceRule->addItem($cartPriceRuleProductItem1);
     $this->assertTrue($cartPriceRule->isValid(new DateTime(), $cartItems));
 }
Beispiel #3
0
 public function getCartPriceRule()
 {
     $cartPriceRule = new CartPriceRule();
     $cartPriceRule->setName('Test Cart Price Rule');
     return $cartPriceRule;
 }
 public function testGetTotalWithCartPriceRulesAndReducesTaxSubtotal()
 {
     $productShirt = new Product();
     $productShirt->setSku('TS-NAVY-LG');
     $productShirt->setName('Navy T-shirt (large)');
     $productShirt->setUnitPrice(1200);
     $productShirt->setIsTaxable(true);
     $productPoster = new Product();
     $productPoster->setSku('PST-CKN');
     $productPoster->setName('Citizen Kane (1941) Poster');
     $productPoster->setUnitPrice(500);
     $productPoster->setIsTaxable(true);
     $cartPriceRule = new CartPriceRule();
     $cartPriceRule->setName('Buy a Shirt get a FREE poster');
     $cartPriceRule->addItem(new CartPriceRuleProductItem($productShirt, 1));
     $cartPriceRule->addItem(new CartPriceRuleProductItem($productPoster, 1));
     $cartPriceRule->addDiscount(new CartPriceRuleDiscount($productPoster, 1));
     $cartPriceRule->setReducesTaxSubtotal(true);
     $pricing = new Pricing();
     $pricing->setCartPriceRules([$cartPriceRule]);
     $cartItem1 = new CartItem();
     $cartItem1->setProduct($productShirt);
     $cartItem1->setQuantity(1);
     $cartItem2 = new CartItem();
     $cartItem2->setProduct($productPoster);
     $cartItem2->setQuantity(1);
     $taxRate = new TaxRate();
     $taxRate->setZip5(92606);
     $taxRate->setRate(8.0);
     $taxRate->setApplyToShipping(false);
     $cart = new Cart();
     $cart->addCartItem($cartItem1);
     $cart->addCartItem($cartItem2);
     $cart->setTaxRate($taxRate);
     $expectedCartTotal = new CartTotal();
     $expectedCartTotal->origSubtotal = 1700;
     $expectedCartTotal->subtotal = 1700;
     $expectedCartTotal->taxSubtotal = 1200;
     $expectedCartTotal->shipping = 0;
     $expectedCartTotal->discount = 500;
     $expectedCartTotal->tax = 96;
     $expectedCartTotal->total = 1296;
     $expectedCartTotal->savings = 500;
     $expectedCartTotal->addCartPriceRule($cartPriceRule);
     $expectedCartTotal->taxRate = $taxRate;
     $cartCalculator = new CartCalculator($pricing);
     $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart));
 }