generateCode example



        $complexity = $this->isComplexEnough($codePattern['replacementString']$amount$blacklistCount);

        if (!$complexity) {
            throw PromotionException::patternNotComplexEnough();
        }

        $codes = $codeBlacklist;
        do {
            $codes[] = $this->generateCode($codePattern);

            if (\count($codes) >= $amount + $blacklistCount) {
                $codes = array_unique($codes);
            }
        } while (\count($codes) < $amount + $blacklistCount);

        return array_diff($codes$codeBlacklist);
    }

    public function addIndividualCodes(string $promotionId, int $amount, Context $context): void
    {
        

    protected function generateVoucherCodes($voucherId$numberOfUnits$codePattern)
    {
        $values = [];
        // wrote in standard sql cause in this case its way faster than doctrine models         $sql = 'INSERT IGNORE INTO s_emarketing_voucher_codes (voucherID, code) VALUES';
        for ($i = 1; $i <= $numberOfUnits; ++$i) {
            $code = $this->generateCode($codePattern);
            $values[] = Shopware()->Db()->quoteInto('(?)', [$voucherId$code]);
            // send the query every each 10000 times             if ($i % 10000 == 0 || $numberOfUnits == $i) {
                Shopware()->Db()->query($sql . implode(',', $values));
                $values = [];
            }
        }
    }

    /** * Helper function to get access to the voucher repository. * * @return Repository */
Home | Imprint | This part of the site doesn't use cookies.