Example #1
0
 /**
  * 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;
 }
Example #2
0
 public function dispShopToolAddCouponGroup()
 {
     $coupon = new Coupon();
     $coupon->generateCode(7);
     Context::set('object', $coupon);
 }