public function actionProductItems() { $this->layout = false; if ($q = Yii::$app->request->post('q')) { $offset = Yii::$app->session->get("controllers.search.index.{$q}.offset"); $offset += static::PRODUCTS_LIMIT; Yii::$app->session->set("controllers.search.index.{$q}.offset", $offset); $q_utf8 = StringUtils::utf8convert($q); $translations = ProductTranslation::find()->orFilterWhere(['like', 'name', $q])->orFilterWhere(['like', 'meta_title', $q])->orFilterWhere(['like', 'meta_description', $q])->orFilterWhere(['like', 'meta_keywords', $q])->orFilterWhere(['like', 'h1', $q])->orFilterWhere(['like', 'page_title', $q])->orFilterWhere(['like', 'description', $q])->orFilterWhere(['like', 'detail', $q])->orFilterWhere(['like', 'name', $q_utf8])->orFilterWhere(['like', 'meta_title', $q_utf8])->orFilterWhere(['like', 'meta_description', $q_utf8])->orFilterWhere(['like', 'meta_keywords', $q_utf8])->orFilterWhere(['like', 'h1', $q_utf8])->orFilterWhere(['like', 'page_title', $q_utf8])->orFilterWhere(['like', 'description', $q_utf8])->orFilterWhere(['like', 'detail', $q_utf8])->all(); $pids = ArrayHelper::getColumn($translations, 'product_id'); $products = Product::getProducts(['id_in' => $pids, 'orderBy' => Yii::$app->request->post('orderBy'), 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset]); $nextProductsNumber = count(Product::getProducts(['id_in' => $pids, 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset + static::PRODUCTS_LIMIT])); $productsHtml = $this->render('//product/items', ['products' => $products, 'offset' => $offset]); return json_encode(['productsHtml' => $productsHtml, 'nextProductsNumber' => $nextProductsNumber]); } }
public function getProducts($params = []) { $cate_ids = ArrayHelper::merge([$this->id], ArrayHelper::getColumn($this->getChildren(), 'id')); $id_in = ArrayHelper::getColumn(ProductCategoryToProduct::find()->where(['in', 'product_category_id', $cate_ids])->all(), 'product_id'); $result = Product::getProducts(['id_in' => $id_in, 'orderBy' => !empty($params['orderBy']) ? $params['orderBy'] : null, 'limit' => !empty($params['limit']) ? $params['limit'] : null, 'offset' => !empty($params['offset']) ? $params['offset'] : null]); return $result; }
public function getProducts($params = []) { $id_in = ArrayHelper::getColumn(ProductCollectionToProduct::find()->where(['product_collection_id' => $this->id])->all(), 'product_id'); $result = Product::getProducts(['id_in' => $id_in, 'orderBy' => !empty($params['orderBy']) ? $params['orderBy'] : null, 'limit' => !empty($params['limit']) ? $params['limit'] : null, 'offset' => !empty($params['offset']) ? $params['offset'] : null]); return $result; }