Пример #1
0
 public function procShopToolDeleteCoupons()
 {
     $repository = new CouponRepository();
     $srls = explode(',', Context::get('srls'));
     //check if there are groups among those srls
     foreach ($srls as $i=>$srl) {
         /** @var $coupon Coupon */
         if (is_numeric($srl) && $coupon = $repository->get($srl)) {
             if (!$coupon->parent_srl) {
                 $repository->query('deleteCoupons', array('parent_srl'=>$coupon->srl));
                 unset($srls[$i]);
             }
         }
         else unset($srls[$i]);
     }
     $repository->delete($srls);
     $this->setMessage("success_deleted");
     $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopToolDiscountCodes'));
 }
Пример #2
0
    /**
     * display shop tool edit coupon group
     * @return Object
     * @throws ShopException
     */
    public function dispShopToolEditCouponGroup()
    {
        $repo = new CouponRepository();
        $srl = Context::get('srl');
        try {
            /** @var $coupon Coupon */
            if (!is_numeric($srl) || (!$coupon = $repo->get($srl))) throw new ShopException("No such coupon group");
            if ($coupon->type != Coupon::TYPE_PARENT) throw new ShopException("Invalid group");
        }
        catch (ShopException $e) {
            $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopToolDiscountCodes'));
            return new Object(-1, $e->getMessage());
        }
        Context::set('object', $coupon);

        $children = $coupon->getChildren($this->module_srl);
        Context::set('childCoupons', $children);

        $codes = array();
        /** @var $c Coupon */
        foreach ($children as $c) $codes[] = $c->code;
        Context::set('codesForCopy', implode("\n", $codes));

        $this->setTemplateFile('AddCouponGroup');
    }
Пример #3
0
 /**
  * Return parent
  *
  * @return Coupon|null
  * @throws ShopException
  */
 public function getParent()
 {
     return $this->isChild() ? $this->repo->get($this->parent_srl) : null;
 }
Пример #4
0
 /**
  * @return Coupon|null
  */
 public function getCoupon()
 {
     /** @var $coupon Coupon */
     if (($coupon = self::$cache->get('coupon')) instanceof Coupon && $coupon->isPersisted()) {
         return $coupon;
     }
     if (is_numeric($id = $this->getExtra('coupon_srl'))) {
         $repository = new CouponRepository();
         if ($coupon = $repository->get($id)) {
             //check validity of coupon daterange
             $date1 = strtotime($coupon->valid_from && $coupon->valid_from != 'null' ? $coupon->valid_from : 'now');
             $date2 = strtotime($coupon->valid_to && $coupon->valid_to != 'null' ? $coupon->valid_to : 'now');
             if (time() < $date1 || time() > $date2) {
                 return null;
             }
             //check active
             if (!$coupon->active) {
                 return null;
             }
             //check uses
             if ($coupon->max_uses <= $coupon->uses) {
                 return null;
             }
             return self::$cache->set('coupon', $coupon);
         }
     }
     return null;
 }