/** * @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 \Generated\Shared\Transfer\DiscountVoucherTransfer $discountVoucherTransfer * * @return int */ protected function getNextBatchValueForVouchers(DiscountVoucherTransfer $discountVoucherTransfer) { $nextVoucherBatchValue = 0; if ($discountVoucherTransfer->getQuantity() < 2) { return $nextVoucherBatchValue; } $highestBatchValueOnVouchers = $this->queryContainer->queryDiscountVoucher()->filterByFkDiscountVoucherPool($discountVoucherTransfer->getFkDiscountVoucherPool())->orderByVoucherBatch(Criteria::DESC)->findOne(); if ($highestBatchValueOnVouchers === null) { return 1; } return $highestBatchValueOnVouchers->getVoucherBatch() + 1; }