コード例 #1
0
 public function testGetNameFixed()
 {
     $this->productQuantityDiscount->setType(PromotionType::fixed());
     $this->productQuantityDiscount->setQuantity(10);
     $this->productQuantityDiscount->setValue(500);
     $this->assertSame('Buy 10 or more for $5.00 off', $this->productQuantityDiscount->getName());
 }
コード例 #2
0
 public function handle(CreateProductQuantityDiscountCommand $command)
 {
     $product = $this->productService->findOneById($command->getProductId());
     $productQuantityDiscount = new ProductQuantityDiscount($product, $command->getProductQuantityDiscountId());
     $productQuantityDiscount->setType(PromotionType::createById($command->getPromotionTypeId()));
     $productQuantityDiscount->setValue($command->getValue());
     $productQuantityDiscount->setReducesTaxSubtotal($command->getReducesTaxSubtotal());
     $productQuantityDiscount->setMaxRedemptions($command->getMaxRedemptions());
     $productQuantityDiscount->setStart($command->getStartDate());
     $productQuantityDiscount->setEnd($command->getEndDate());
     $productQuantityDiscount->setQuantity($command->getQuantity());
     $productQuantityDiscount->setFlagApplyCatalogPromotions($command->getFlagApplyCatalogPromotions());
     $this->productService->createProductQuantityDiscount($productQuantityDiscount);
 }
コード例 #3
0
 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));
 }
コード例 #4
0
ファイル: DummyData.php プロジェクト: inklabs/kommerce-core
 public function getProductQuantityDiscount(Product $product = null)
 {
     if ($product === null) {
         $product = $this->getProduct();
     }
     $productQuantityDiscount = new ProductQuantityDiscount($product);
     $productQuantityDiscount->setType(PromotionType::percent());
     $productQuantityDiscount->setQuantity(6);
     $productQuantityDiscount->setValue(5);
     $productQuantityDiscount->setCustomerGroup(null);
     $productQuantityDiscount->setQuantity(1);
     $productQuantityDiscount->setFlagApplyCatalogPromotions(true);
     return $productQuantityDiscount;
 }