public function testRemoveProductQuantityDiscount() { $productQuantityDiscount1 = $this->dummyData->getProductQuantityDiscount(); $productQuantityDiscount2 = $this->dummyData->getProductQuantityDiscount(); $product = new Product(); $product->addProductQuantityDiscount($productQuantityDiscount1); $product->addProductQuantityDiscount($productQuantityDiscount2); $this->assertSame(2, count($product->getProductQuantityDiscounts())); $product->removeProductQuantityDiscount($productQuantityDiscount2); $this->assertSame(1, count($product->getProductQuantityDiscounts())); }
/** * @param Pricing $pricing * @return static */ public function withProductQuantityDiscounts(Pricing $pricing) { $productQuantityDiscounts = $this->entity->getProductQuantityDiscounts(); $pricing->setProductQuantityDiscounts($productQuantityDiscounts); foreach ($productQuantityDiscounts as $productQuantityDiscount) { $this->entityDTO->productQuantityDiscounts[] = $this->dtoBuilderFactory->getProductQuantityDiscountDTOBuilder($productQuantityDiscount)->withPrice($pricing)->build(); } return $this; }
public function testGetPriceWithProductQuantityDiscountPercent() { $product = new Product(); $product->setUnitPrice(500); $productQuantityDiscount6 = new ProductQuantityDiscount($product); $productQuantityDiscount6->setType(PromotionType::percent()); $productQuantityDiscount6->setQuantity(6); $productQuantityDiscount6->setValue(5); $productQuantityDiscount12 = new ProductQuantityDiscount($product); $productQuantityDiscount12->setType(PromotionType::percent()); $productQuantityDiscount12->setQuantity(12); $productQuantityDiscount12->setValue(30); $productQuantityDiscount24 = new ProductQuantityDiscount($product); $productQuantityDiscount24->setType(PromotionType::percent()); $productQuantityDiscount24->setQuantity(24); $productQuantityDiscount24->setValue(35); $productQuantityDiscounts = $product->getProductQuantityDiscounts(); $this->pricing->setProductQuantityDiscounts($productQuantityDiscounts); $expectedPrice = new Price(); $expectedPrice->unitPrice = 500; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 500; $expectedPrice->origQuantityPrice = 500; $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 1)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 475; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 2850; $expectedPrice->origQuantityPrice = 3000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount6); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 6)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 350; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 4200; $expectedPrice->origQuantityPrice = 6000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount12); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 12)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 325; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 7800; $expectedPrice->origQuantityPrice = 12000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount24); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 24)); }