예제 #1
0
 public function actionProductItems()
 {
     $this->layout = false;
     $cate_id = Yii::$app->request->post('cate_id');
     if ($cate = ProductCategory::findOne(['id' => $cate_id, 'is_active' => 1])) {
         $offset = Yii::$app->session->get("controllers.product-category.{$cate->id}.detail.offset");
         $offset += static::PRODUCTS_LIMIT;
         Yii::$app->session->set("controllers.product-category.{$cate->id}.detail.offset", $offset);
         $products = $cate->getProducts(['orderBy' => Yii::$app->request->post('orderBy'), 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset]);
         $productsHtml = $this->render('//product/items', ['products' => $products, 'offset' => $offset]);
         $nextProductsNumber = $cate->countProducts(['limit' => static::PRODUCTS_LIMIT, 'offset' => $offset + static::PRODUCTS_LIMIT]);
         return json_encode(['productsHtml' => $productsHtml, 'nextProductsNumber' => $nextProductsNumber]);
     } else {
         throw new NotFoundHttpException();
     }
 }
예제 #2
0
 public function getParent()
 {
     if ($this->_parent == 1) {
         if (!($_parent = ProductCategory::findOne(['id' => $this->parent_id]))) {
             $_parent = null;
         }
         $this->_parent = $_parent;
     }
     return $this->_parent;
 }