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));
 }
Example #2
0
 /**
  * @param Product $product
  * @param int $quantity
  * @return Price
  */
 public function getPrice(Product $product, $quantity)
 {
     $pricingCalculator = new PricingCalculator($this);
     return $pricingCalculator->getPrice($product, $quantity);
 }