private function calculateCatalogPromotions()
 {
     foreach ($this->pricing->getCatalogPromotions() as $catalogPromotion) {
         if ($catalogPromotion->isValid($this->pricing->getDate(), $this->product)) {
             $this->price->unitPrice = $catalogPromotion->getUnitPrice($this->price->unitPrice);
             $this->price->addCatalogPromotion($catalogPromotion);
         }
     }
     // No prices below zero!
     $this->price->unitPrice = max(0, $this->price->unitPrice);
 }
 public function testGetPriceWithCatalogPromotion()
 {
     $catalogPromotion = new CatalogPromotion();
     $catalogPromotion->setName('20% Off');
     $catalogPromotion->setType(PromotionType::percent());
     $catalogPromotion->setValue(20);
     $this->pricing->setCatalogPromotions([$catalogPromotion]);
     $product = new Product();
     $product->setUnitPrice(1500);
     $expectedPrice = new Price();
     $expectedPrice->unitPrice = 1200;
     $expectedPrice->origUnitPrice = 1500;
     $expectedPrice->addCatalogPromotion($catalogPromotion);
     $expectedPrice->quantityPrice = 1200;
     $expectedPrice->origQuantityPrice = 1500;
     $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 1));
 }
Example #3
0
 public function testAddPreventsDuplicates()
 {
     $catalogPromotion = $this->dummyData->getCatalogPromotion();
     $productQuantityDiscount = $this->dummyData->getProductQuantityDiscount();
     $one = new Price();
     $one->addCatalogPromotion($catalogPromotion);
     $one->addProductQuantityDiscount($productQuantityDiscount);
     $two = new Price();
     $two->addCatalogPromotion($catalogPromotion);
     $two->addProductQuantityDiscount($productQuantityDiscount);
     $three = new Price();
     $three->unitPrice = 0;
     $three->origUnitPrice = 0;
     $three->quantityPrice = 0;
     $three->origQuantityPrice = 0;
     $three->addCatalogPromotion($catalogPromotion);
     $three->addProductQuantityDiscount($productQuantityDiscount);
     $this->assertEquals($three, Price::add($one, $two));
 }