本文整理汇总了PHP中Coupon::generateCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Coupon::generateCode方法的具体用法?PHP Coupon::generateCode怎么用?PHP Coupon::generateCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coupon
的用法示例。
在下文中一共展示了Coupon::generateCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateBulk
/**
* Generates child coupons with the $code property generated by the RandomGenerator input settings
*
* @param $number
* @param int $length
* @param string $type
* @param string $pattern
* @param int $separateEvery
* @param string $separator
* @return array
* @throws ShopException
*/
public function generateBulk($number, $length = 10, $type = RandomGenerator::TYPE_ALPHANUM, $pattern = 'X', $separateEvery = 0, $separator = '-')
{
if (!$this->isPersisted()) {
throw new ShopException('Current coupon is not persisted, can\'t be used as parent');
}
$bulk = array();
$i = 0;
while ($i < $number) {
$c = new Coupon();
//$c->copy($this);
$c->generateCode($length, $type, $pattern, $separateEvery, $separator);
$c->module_srl = $this->module_srl;
$c->parent_srl = $this->srl;
$c->type = self::TYPE_CHILD;
//save will throw ShopException if code is not unique
try {
$c->save();
} catch (ShopException $e) {
continue;
}
$i++;
$bulk[] = $c;
}
return $bulk;
}
示例2: dispShopToolAddCouponGroup
public function dispShopToolAddCouponGroup()
{
$coupon = new Coupon();
$coupon->generateCode(7);
Context::set('object', $coupon);
}