private function findRecommendedProducts($id)
 {
     if (!empty($id)) {
         $product = Product::findOne($id);
         $categoryId = $product->category_id;
         $previous = Product::find()->where(['<', 'id', $id])->andWhere(['category_id' => $categoryId])->orderBy(['id' => SORT_DESC])->limit('2')->all();
         $next = Product::find()->where(['>', 'id', $id])->andWhere(['category_id' => $categoryId])->orderBy(['id' => SORT_ASC])->limit('2')->all();
         $products = ArrayHelper::merge($previous, $next);
         return $products;
     }
     return false;
 }
Beispiel #2
0
 public function run()
 {
     parent::run();
     if (!empty($this->className)) {
         $class = \Yii::createObject($this->className);
         $categories = $class::find()->where(['parent_id' => null, 'show' => 1])->orderBy('position')->all();
         $currentCategoryId = '';
         if (Yii::$app->controller->module->id == 'shop') {
             if (Yii::$app->controller->id == 'category') {
                 $currentCategoryId = \Yii::$app->request->get('id');
             } elseif (Yii::$app->controller->id == 'product') {
                 $product = Product::findOne(\Yii::$app->request->get('id'));
                 $currentCategoryId = $product->category_id;
             }
         }
         return $this->render('tree/tree', ['categories' => $categories, 'currentCategoryId' => $currentCategoryId, 'level' => 0, 'context' => $this]);
     } else {
         return false;
     }
 }
Beispiel #3
0
 /**
  * Creates a URL according to the given route and parameters.
  * @param UrlManager $manager the URL manager
  * @param string $route the route. It should not have slashes at the beginning or the end.
  * @param array $params the parameters
  * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
  */
 public function createUrl($manager, $route, $params)
 {
     $pathInfo = '';
     if ($route == $this->categoryRoute && empty($params['id'])) {
         $pathInfo = $this->prefix;
     } else {
         if (($route == $this->productRoute || $route == $this->categoryRoute) && !empty($params['id'])) {
             $id = $params['id'];
             $parentId = null;
             $language = Language::findOne(['lang_id' => $manager->language]);
             if ($route == $this->productRoute) {
                 $product = Product::findOne($id);
                 if (empty($product)) {
                     return false;
                 }
                 if ($product->getTranslation($language->id) && $product->getTranslation($language->id)->seoUrl) {
                     $pathInfo = $product->getTranslation($language->id)->seoUrl;
                     $parentId = $product->category_id;
                 } else {
                     return false;
                 }
             } else {
                 if ($route == $this->categoryRoute) {
                     $category = Category::findOne($id);
                     if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                         $pathInfo = $category->getTranslation($language->id)->seoUrl;
                         $parentId = $category->parent_id;
                     } else {
                         return false;
                     }
                 }
             }
             while ($parentId != null) {
                 $category = Category::findOne($parentId);
                 if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                     $pathInfo = $category->getTranslation($language->id)->seoUrl . '/' . $pathInfo;
                     $parentId = $category->parent_id;
                 } else {
                     return false;
                 }
             }
             if (!empty($this->prefix)) {
                 $pathInfo = $this->prefix . '/' . $pathInfo;
             }
             unset($params['id']);
         } else {
             return false;
         }
     }
     return $pathInfo . '?' . http_build_query($params);
 }
 /**
  * Changes product status property by ModerationManager
  *
  * Users which have 'moderateProductCreation' permission can change product status.
  *
  * @param integer $id
  * @param integer $status
  * @return mixed
  */
 public function actionChangeProductStatus($id, $status)
 {
     if (!empty($id) && !empty($status)) {
         $product = Product::findOne($id);
         if ($product->status == Product::STATUS_ON_MODERATION) {
             switch ($status) {
                 case Product::STATUS_SUCCESS:
                     $product->status = Product::STATUS_SUCCESS;
                     $product->save();
                     break;
                 case Product::STATUS_DECLINED:
                     $product->status = Product::STATUS_DECLINED;
                     $product->save();
                     break;
             }
         }
     }
     return $this->redirect(Yii::$app->request->referrer);
 }