src/ShopBundle/objects/db/TShopVoucherSeries.class.php
public function CreateNewVoucher($sCode = null)
    {
        if (is_null($sCode)) {
            $bCodeUnique = false;
            $dMaxTry = 15;
            $sCode = '';
            while (!$bCodeUnique && $dMaxTry > 0) {
                --$dMaxTry;
                $sCode = TdbShopVoucher::GenerateVoucherCode();
                $query = "SELECT * FROM `shop_voucher` WHERE `code` = '".MySqlLegacySupport::getInstance()->real_escape_string($sCode)."'";
                $tRes = MySqlLegacySupport::getInstance()->query($query);
                if (0 == MySqlLegacySupport::getInstance()->num_rows($tRes)) {
                    $bCodeUnique = true;
                }
            }
        }
        $aData = array('shop_voucher_series_id' => $this->id, 'code' => $sCode, 'datecreated' => date('Y-m-d H:i:s'));
        $oVoucher = TdbShopVoucher::GetNewInstance();
        $oVoucher->LoadFromRow($aData);
        $oVoucher->AllowEditByAll();
        $oVoucher->Save();

        return $oVoucher;
    }
public function CreateNewVoucher($sCode = null)
    {
        if (is_null($sCode)) {
            $bCodeUnique = false;
            $dMaxTry = 15;
            $sCode = '';
            while (!$bCodeUnique && $dMaxTry > 0) {
                --$dMaxTry;
                $sCode = TdbShopVoucher::GenerateVoucherCode();
                $query = "SELECT * FROM `shop_voucher` WHERE `code` = '".MySqlLegacySupport::getInstance()->real_escape_string($sCode)."'";
                $tRes = MySqlLegacySupport::getInstance()->query($query);
                if (0 == MySqlLegacySupport::getInstance()->num_rows($tRes)) {
                    $bCodeUnique = true;
                }
            }
        }
        $aData = array('shop_voucher_series_id' => $this->id, 'code' => $sCode, 'datecreated' => date('Y-m-d H:i:s'));
        $oVoucher = TdbShopVoucher::GetNewInstance();
        $oVoucher->LoadFromRow($aData);
        $oVoucher->AllowEditByAll();
        $oVoucher->Save();

        return $oVoucher;
    }
public function CreateNewVoucher ( $ sCode = null ) { if ( is_null ( $ sCode ) ) { $ bCodeUnique = false ; $ dMaxTry = 15 ; $ sCode = '' ; while ( ! $ bCodeUnique && $ dMaxTry > 0 ) { -- $ dMaxTry ; $ sCode = TdbShopVoucher :: GenerateVoucherCode ( ) ; $ query = "SELECT * FROM `shop_voucher` WHERE `code` = '" . MySqlLegacySupport :: getInstance ( ) -> real_escape_string ( $ sCode ) . "'" ; $ tRes = MySqlLegacySupport :: getInstance ( ) -> query ( $ query ) ; if ( 0 == MySqlLegacySupport :: getInstance ( ) -> num_rows ( $ tRes ) ) { $ bCodeUnique = true ; } } } $ aData = array ( 'shop_voucher_series_id' => $ this -> id , 'code' => $ sCode , 'datecreated' => date ( 'Y-m-d H:i:s' ) ) ; $ oVoucher = TdbShopVoucher :: GetNewInstance ( ) ; $ oVoucher -> LoadFromRow ( $ aData ) ; $ oVoucher -> AllowEditByAll ( ) ; $ oVoucher -> Save ( ) ; return $ oVoucher ; }
create a new voucher.

@param string $sCode - code to create

@return TdbShopVoucher
create a new voucher .