/** * @param string $displayName * @param string $calculatorPlugin * @param int $amount * @param bool $isActive * @param bool $isExclusive * * @return \Generated\Shared\Transfer\DiscountTransfer */ protected function initializeDiscount($displayName, $calculatorPlugin, $amount, $isActive, $isExclusive = true) { $discountTransfer = new DiscountTransfer(); $discountTransfer->setDisplayName($displayName); $discountTransfer->setAmount($amount); $discountTransfer->setIsActive($isActive); $discountTransfer->setCollectorQueryString('sku = "sku1"'); $discountTransfer->setCalculatorPlugin($calculatorPlugin); $discountTransfer->setIsExclusive($isExclusive); return $discountTransfer; }
/** * @param int $amount * * @return \Generated\Shared\Transfer\DiscountTransfer */ protected function createDiscountTransfer($amount) { $discountTransfer = new DiscountTransfer(); $discountTransfer->setCalculatorPlugin('test'); $discountTransfer->setAmount($amount); return $discountTransfer; }
/** * @return array */ protected function createCollectedDiscounts() { $collectedDiscounts = []; $collectedDiscountTransfer = new CollectedDiscountTransfer(); $discountTransfer = new DiscountTransfer(); $discountTransfer->setAmount(250); $collectedDiscountTransfer->setDiscount($discountTransfer); $collectedDiscounts[] = $collectedDiscountTransfer; return $collectedDiscounts; }
/** * @param \Orm\Zed\Discount\Persistence\SpyDiscount $discountEntity * * @return \Generated\Shared\Transfer\DiscountTransfer */ protected function hydrateDiscountTransfer(SpyDiscount $discountEntity) { $discountTransfer = new DiscountTransfer(); $discountTransfer->fromArray($discountEntity->toArray(), true); return $discountTransfer; }
/** * @param \Generated\Shared\Transfer\DiscountTransfer $discountTransfer * * @throws \Spryker\Zed\Discount\Business\Exception\CalculatorException * * @return \Spryker\Zed\Discount\Dependency\Plugin\DiscountCalculatorPluginInterface */ protected function getCalculatorPlugin(DiscountTransfer $discountTransfer) { if (!isset($this->calculatorPlugins[$discountTransfer->getCalculatorPlugin()])) { throw new CalculatorException(sprintf('Calculator plugin with name "%s" not found. Did you forget to register it in "%s"::getAvailableCalculatorPlugins', $discountTransfer->getCalculatorPlugin(), DiscountDependencyProvider::class)); } return $this->calculatorPlugins[$discountTransfer->getCalculatorPlugin()]; }
/** * @param int $discountAmount * * @return \Generated\Shared\Transfer\DiscountTransfer */ protected function createDiscountTransfer($discountAmount) { $discountTransfer = new DiscountTransfer(); $discountTransfer->setAmount($discountAmount); return $discountTransfer; }
/** * @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()); }
/** * @param \Generated\Shared\Transfer\DiscountTransfer $discountTransfer * * @return \Generated\Shared\Transfer\CalculatedDiscountTransfer */ protected function createBaseCalculatedDiscountTransfer(DiscountTransfer $discountTransfer) { $calculatedDiscountTransfer = new CalculatedDiscountTransfer(); $calculatedDiscountTransfer->fromArray($discountTransfer->toArray(), true); return $calculatedDiscountTransfer; }
/** * @return void */ public function testWhenMultipleVouchersFromSamePoolUsedShouldUseOnlyOnce() { $discountEntity = $this->createDiscountFixtures('', 'sku = "*"', DiscountConstants::TYPE_VOUCHER); $code1 = 'code1'; $code2 = 'code2'; $code3 = 'code3'; $this->createVoucherCode($code1, $discountEntity); $this->createVoucherCode($code2, $discountEntity); $this->createVoucherCode($code3, $discountEntity); $quoteTransfer = $this->createQuoteTransfer(); $discountTransfer = new DiscountTransfer(); $discountTransfer->setVoucherCode($code1); $quoteTransfer->addVoucherDiscount($discountTransfer); $discountTransfer = new DiscountTransfer(); $discountTransfer->setVoucherCode($code2); $quoteTransfer->addVoucherDiscount($discountTransfer); $discountFacade = new DiscountFacade(); $quoteTransfer = $discountFacade->calculateDiscounts($quoteTransfer); $discountTransfer = $quoteTransfer->getVoucherDiscounts()[0]; $this->assertCount(1, $quoteTransfer->getVoucherDiscounts()); $this->assertEquals($code1, $discountTransfer->getVoucherCode()); }