Exemple #1
0
 /**
  * @param \Generated\Shared\Transfer\CollectedDiscountTransfer $collectedDiscountTransfer
  *
  * @return int
  */
 protected function getTotalGrossAmountOfDiscountableObjects(CollectedDiscountTransfer $collectedDiscountTransfer)
 {
     $totalGrossAmount = 0;
     foreach ($collectedDiscountTransfer->getDiscountableItems() as $discountableItemTransfer) {
         $totalGrossAmount += $discountableItemTransfer->getUnitGrossPrice() * $this->getDiscountableItemQuantity($discountableItemTransfer);
     }
     return $totalGrossAmount;
 }
Exemple #2
0
 /**
  * @return array
  */
 protected function createCollectedDiscounts()
 {
     $collectedDiscounts = [];
     $collectedDiscountTransfer = new CollectedDiscountTransfer();
     $discountTransfer = new DiscountTransfer();
     $discountTransfer->setAmount(250);
     $collectedDiscountTransfer->setDiscount($discountTransfer);
     $collectedDiscounts[] = $collectedDiscountTransfer;
     return $collectedDiscounts;
 }
Exemple #3
0
 /**
  * @param \Generated\Shared\Transfer\DiscountTransfer $discountTransfer
  * @param \Generated\Shared\Transfer\DiscountableItemTransfer[] $discountableItems
  *
  * @return \Generated\Shared\Transfer\CollectedDiscountTransfer
  */
 protected function createCollectedDiscountTransfer(DiscountTransfer $discountTransfer, array $discountableItems)
 {
     $calculatedDiscounts = new CollectedDiscountTransfer();
     $calculatedDiscounts->setDiscount($discountTransfer);
     $calculatedDiscounts->setDiscountableItems(new \ArrayObject($discountableItems));
     return $calculatedDiscounts;
 }
Exemple #4
0
 /**
  * @return void
  */
 public function testDistributeWithRoundingErrorShouldMoveCentToNextItem()
 {
     $distributor = $this->createDistributor();
     $discountableObjects = $this->createDiscountableObjects([['unit_gross_price' => 50], ['unit_gross_price' => 50], ['unit_gross_price' => 50]]);
     $collectedDiscountTransfer = new CollectedDiscountTransfer();
     $discountTransfer = $this->createDiscountTransfer(100);
     $collectedDiscountTransfer->setDiscount($discountTransfer);
     $collectedDiscountTransfer->setDiscountableItems($discountableObjects);
     $distributor->distributeDiscountAmountToDiscountableItems($collectedDiscountTransfer);
     $totalAmount = 0;
     foreach ($discountableObjects as $discountableObject) {
         if (count($discountableObject->getOriginalItemCalculatedDiscounts()) === 0) {
             continue;
         }
         $totalAmount += $discountableObject->getOriginalItemCalculatedDiscounts()[0]->getUnitGrossAmount();
     }
     $discountableItemTransfer = $discountableObjects[0];
     $unitGrossPrice = $discountableItemTransfer->getOriginalItemCalculatedDiscounts()[0]->getUnitGrossAmount();
     $this->assertSame(33, $unitGrossPrice);
     $discountableItemTransfer = $discountableObjects[1];
     $unitGrossPrice = $discountableItemTransfer->getOriginalItemCalculatedDiscounts()[0]->getUnitGrossAmount();
     $this->assertSame(34, $unitGrossPrice);
     $discountableItemTransfer = $discountableObjects[2];
     $unitGrossPrice = $discountableItemTransfer->getOriginalItemCalculatedDiscounts()[0]->getUnitGrossAmount();
     $this->assertSame(33, $unitGrossPrice);
     $this->assertEquals(100, $totalAmount);
 }
Exemple #5
0
 /**
  * @return void
  */
 public function testDistributeShouldNotDistributeDiscountsForObjectsWithZeroGrossPrices()
 {
     $items = $this->getItems([self::ITEM_GROSS_PRICE_ZERO, self::ITEM_GROSS_PRICE_ZERO, self::ITEM_GROSS_PRICE_ZERO]);
     $discountTransfer = new DiscountTransfer();
     $discountTransfer->setAmount(self::DISCOUNT_AMOUNT_100);
     $collectedDiscountTransfer = new CollectedDiscountTransfer();
     $collectedDiscountTransfer->setDiscount($discountTransfer);
     $collectedDiscountTransfer->setDiscountableItems($items);
     $this->discountFacade->distributeAmount($collectedDiscountTransfer);
     $this->assertEquals(0, $items[0]->getOriginalItemCalculatedDiscounts()->count());
     $this->assertEquals(0, $items[1]->getOriginalItemCalculatedDiscounts()->count());
     $this->assertEquals(0, $items[2]->getOriginalItemCalculatedDiscounts()->count());
 }