Example #1
0
 public function actionCategory($id)
 {
     //$products = Product::find()->where(['id' => category_id])->all();
     //$products = Product::find()->where(['category_id' => $category_id])->all();
     $category = Category::findOne($id);
     $products = $category->products;
     //var_dump($products);
     return $this->render('category', ['products' => $products]);
 }
 /**
  * @param null|integer $id
  * @return string
  *
  * Shows parent categories and products of this category if category has not children categories.
  */
 public function actionShow($id = null)
 {
     if (is_null($id)) {
         $childCategories = Category::find()->where(['parent_id' => null, 'show' => true])->all();
         $this->registerStaticSeoData();
     } else {
         $category = Category::findOne($id);
         $category->registerMetaData();
         $childCategories = $category->getChildren();
         $descendantCategories = $category->getDescendants($category);
         array_push($descendantCategories, $category);
     }
     if ($this->module->showChildCategoriesProducts || empty($childCategories)) {
         $filters = !empty($category) ? Filter::find()->where(['category_id' => $category->id])->all() : null;
         $cart = new CartForm();
         $searchModel = new ProductSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $descendantCategories ?? null);
     }
     return $this->render('show', ['category' => $category ?? null, 'childCategories' => $childCategories, 'filters' => $filters ?? null, 'cart' => $cart ?? null, 'dataProvider' => $dataProvider ?? null]);
 }
             $add_s = '';
         }
         if (!empty(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_country)) {
             $add_co = Country::findOne(EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd_country)->country_name;
         } else {
             $add_co = '';
         }
         echo "<td>" . EmpAddress::findOne($sd['emp_master_emp_address_id'])->emp_padd . " " . $add_c . " " . $add_s . " " . $add_co . "</td></tr>";
     } else {
         echo "<td>&nbsp;</td></tr>";
     }
 } else {
     if ($s == 'emp_category_name') {
         echo "<tr><td class='label'>Category Name </td>";
         if ($sd['emp_master_category_id'] != 0) {
             echo "<td>" . Category::findOne($sd['emp_master_category_id'])->emp_category_name . "</td></tr>";
         } else {
             echo "<td>&nbsp;</td></tr>";
         }
     } else {
         if ($s == 'city') {
             echo "<tr><td class='label'>City</td>";
             if ($sd['emp_master_emp_address_id'] != 0) {
                 $add = EmpAddress::findOne($sd['emp_master_emp_address_id']);
                 if ($add->emp_cadd_city != null) {
                     echo "<td>" . City::findOne($add->emp_cadd_city)->city_name . "</td></tr>";
                 } else {
                     echo "<td>&nbsp;</td></tr>";
                 }
             } else {
                 echo "<td>&nbsp;</td></tr>";