示例#1
0
 public function getCategories($isTable = false)
 {
     $categories = $isTable ? ProductsCategory::where('parent_id', '=', '0')->get() : ProductsCategory::where('parent_id', '=', '0')->get(array('id', 'title'));
     $outputArr = [0 => 'no category'];
     foreach ($categories as $category) {
         $title = $category->title;
         if ($isTable) {
             $outputArr[$category->id]['title'] = $title;
             $outputArr[$category->id]['tree'] = $title;
         } else {
             $outputArr[$category->id] = $title;
         }
         $childs = $category->childs;
         foreach ($childs as $child) {
             $titleChild = $title . ' > ' . $child->title;
             if ($isTable) {
                 $outputArr[$child->id]['title'] = $child->title;
                 $outputArr[$child->id]['tree'] = $titleChild;
             } else {
                 $outputArr[$child->id] = $titleChild;
             }
             $grandChilds = $child->childs;
             foreach ($grandChilds as $grandChild) {
                 $titleGrandChild = $titleChild . ' > ' . $grandChild->title;
                 if ($isTable) {
                     $outputArr[$grandChild->id]['title'] = $grandChild->title;
                     $outputArr[$grandChild->id]['tree'] = $titleGrandChild;
                 } else {
                     $outputArr[$grandChild->id] = $titleGrandChild;
                 }
             }
         }
     }
     return $outputArr;
 }
示例#2
0
 protected function getPageElements($current, $title, $description, $keywords, $categories = false, $products = false, $promo = false, $currentCategory = null, $perPage = 12)
 {
     $data = ['current' => $current, 'title' => $title, 'description' => $description, 'keywords' => $keywords, 'current_category' => $currentCategory];
     if ($categories) {
         $data['categories'] = App\ProductsCategory::where('parent_id', '=', 0)->get();
     }
     if ($products) {
         $productsResponse = Product::paginate($perPage);
         $products = $productsResponse->getCollection()->all();
         $pages = $productsResponse->render();
         $data['products'] = $products;
         $data['pages'] = $pages;
     }
     if ($promo) {
         $data['promo_products'] = Product::where('on_discount', '<>', 0)->get()->take(3);
     }
     return $data;
 }