Пример #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
    /**
     * Backend for discount codes / coupons
     */
    public function dispShopToolDiscountCodes() {
        $cRepo = new CouponRepository();
        $params1 = $params2 = array('module_srl' => $this->module_srl);
        if (Context::get('s')) $params1['search'] = $params2['search'] = Context::get('s');

        $params1['type'] = Coupon::TYPE_SINGLE;
        $output1 = $cRepo->getList('getCouponList', Context::get('page1'), $params1);
        Context::set('objects1', $output1->data);
        Context::set('page_navigation1', $output1->page_navigation);

        $params2['type'] = Coupon::TYPE_PARENT;
        $output2 = $cRepo->getList('getCouponList', Context::get('page2'), $params2);
        Context::set('objects2', $output2->data);
        Context::set('page_navigation2', $output2->page_navigation);
    }
Пример #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;
 }