/** * @param string $code * * @return bool */ public function isUsable($code) { $discountVoucherEntity = $this->discountQueryContainer->queryVoucher($code)->findOne(); if (!$discountVoucherEntity) { $this->addMessage(self::REASON_VOUCHER_CODE_NOT_FOUND); return false; } return $this->validateDiscountVoucher($discountVoucherEntity); }
/** * @param int $idDiscount * * @return \Generated\Shared\Transfer\DiscountConfiguratorTransfer */ public function getByIdDiscount($idDiscount) { $discountEntity = $this->discountQueryContainer->queryDiscount()->findOneByIdDiscount($idDiscount); $discountConfigurator = $this->createDiscountConfiguratorTransfer(); $discountGeneralTransfer = $this->hydrateGeneralDiscount($discountEntity); $discountConfigurator->setDiscountGeneral($discountGeneralTransfer); $discountCalculatorTransfer = $this->hydrateDiscountCalculator($discountEntity); $discountConfigurator->setDiscountCalculator($discountCalculatorTransfer); $discountConditionTransfer = $this->hydrateDiscountCondition($discountEntity); $discountConfigurator->setDiscountCondition($discountConditionTransfer); $this->hydrateDiscountVoucher($idDiscount, $discountEntity, $discountConfigurator); return $discountConfigurator; }
/** * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config * * @return array */ protected function prepareData(TableConfiguration $config) { $generatedVoucherCodesQuery = $this->discountQueryContainer->queryDiscountVoucher()->filterByFkDiscountVoucherPool($this->idPool); if ($this->batchValue) { $generatedVoucherCodesQuery->filterByVoucherBatch($this->batchValue); } $collectionObject = $this->runQuery($generatedVoucherCodesQuery, $config, true); $result = []; /** @var \Orm\Zed\Discount\Persistence\SpyDiscountVoucher $discountVoucherEntity */ foreach ($collectionObject as $discountVoucherEntity) { $result[] = [SpyDiscountVoucherTableMap::COL_CODE => $discountVoucherEntity->getCode(), SpyDiscountVoucherTableMap::COL_NUMBER_OF_USES => (int) $discountVoucherEntity->getNumberOfUses(), SpyDiscountVoucherTableMap::COL_MAX_NUMBER_OF_USES => (int) $discountVoucherEntity->getMaxNumberOfUses(), SpyDiscountVoucherTableMap::COL_CREATED_AT => $discountVoucherEntity->getCreatedAt('Y-m-d'), SpyDiscountVoucherTableMap::COL_VOUCHER_BATCH => $discountVoucherEntity->getVoucherBatch(), self::HEADER_COL_ACTIONS => $this->buildLinks($discountVoucherEntity)]; } return $result; }
/** * @param int $idDiscount * @param bool $isActive * * @throws \Spryker\Zed\Discount\Business\Exception\PersistenceException * * @return bool */ public function toggleDiscountVisibility($idDiscount, $isActive = false) { $discountEntity = $this->discountQueryContainer->queryDiscount()->findOneByIdDiscount($idDiscount); if (!$discountEntity) { throw new PersistenceException(sprintf('Discount with id "%d" not found in database.', $idDiscount)); } $discountEntity->setIsActive($isActive); $affectedRows = $discountEntity->save(); return $affectedRows > 0; }
/** * @param string[] $codes * * @return int */ public function useCodes(array $codes) { $voucherEntityList = $this->discountQueryContainer->queryVoucherPoolByVoucherCodes($codes)->find(); if (count($voucherEntityList) === 0) { return 0; } $updatedCodes = 0; foreach ($voucherEntityList as $discountVoucherEntity) { if (!$discountVoucherEntity->getIsActive()) { continue; } if (!$this->isVoucherWithCounter($discountVoucherEntity)) { continue; } $this->incrementNumberOfUses($discountVoucherEntity); $affectedRows = $this->saveDiscountVoucherEntity($discountVoucherEntity); if ($affectedRows > 0) { $updatedCodes++; } } return $updatedCodes; }
/** * @param string[] $voucherCodes * * @return \Orm\Zed\Discount\Persistence\SpyDiscount[] */ protected function retrieveActiveCartAndVoucherDiscounts(array $voucherCodes = []) { $discounts = $this->queryContainer->queryActiveCartRules()->find(); if (count($voucherCodes) > 0) { $voucherDiscounts = $this->queryContainer->queryDiscountsBySpecifiedVouchers($voucherCodes)->find(); $voucherDiscounts = $this->filterUniqueVoucherDiscounts($voucherDiscounts); if (count($discounts) == 0) { return $voucherDiscounts; } foreach ($voucherDiscounts as $discountEntity) { $discounts->append($discountEntity); } } return $discounts; }
/** * @param string $code * * @return \Orm\Zed\Discount\Persistence\SpyDiscountVoucher */ protected function getDiscountVoucherEntityByCode($code) { return $this->discountQueryContainer->queryVoucher($code)->findOne(); }
/** * @return \Propel\Runtime\Connection\ConnectionInterface */ protected function getConnection() { return $this->queryContainer->getConnection(); }