public function actionProductItems() { $this->layout = false; $coll_id = Yii::$app->request->post('coll_id'); if ($coll = ProductCollection::findOne(['id' => $coll_id, 'is_active' => 1])) { $offset = Yii::$app->session->get("controllers.product-collection.{$coll->id}.detail.offset"); $offset += static::PRODUCTS_LIMIT; Yii::$app->session->set("controllers.product-collection.{$coll->id}.detail.offset", $offset); $products = $coll->getProducts(['orderBy' => Yii::$app->request->post('orderBy'), 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset]); $productsHtml = $this->render('//product/items', ['products' => $products, 'offset' => $offset]); $nextProductsNumber = $coll->countProducts(['limit' => static::PRODUCTS_LIMIT, 'offset' => $offset + static::PRODUCTS_LIMIT]); return json_encode(['productsHtml' => $productsHtml, 'nextProductsNumber' => $nextProductsNumber]); } else { throw new NotFoundHttpException(); } }
/** * @return \yii\db\ActiveQuery */ public function getProductCollection() { return $this->hasOne(ProductCollection::className(), ['id' => 'product_collection_id']); }