Beispiel #1
0
 /**
  * Insert overrides the parent class method because we need for $code unicity
  *
  * @param string $query
  * @return object
  * @throws ShopException
  */
 public function insert($query = 'insert%E')
 {
     if ($this->code) {
         $existentCoupons = $this->repo->getByCode($this->code, $this->module_srl);
         if ($existentCoupons && !empty($existentCoupons)) {
             if ($r = $this->getMeta('random')) {
                 $this->generateCode($r['length'], $r['type'], $r['pattern'], $r['separateEvery'], $r['separator']);
             } else {
                 throw new ShopException('Code already exists');
             }
         }
     } else {
         if ($this->parent_srl) {
             throw new ShopException('Child coupon must have a code at insert');
         }
     }
     return parent::insert($query);
 }