Esempio n. 1
0
 /**
  * Returns the category's product arrangement
  * @param   integer     The page to load, zero loads all products
  * @param   boolean     Eager loads thumbnail and thumbnail_alt
  * @param   boolean     Eager loads product discounts
  * @return  Collection  Bedard\Shop\Models\Product
  */
 public function getArrangedProducts($page = 0, $withThumbnails = TRUE, $withDiscounts = TRUE)
 {
     // Load all active and visible products
     if ($this->pseudo == 'all') {
         $products = Product::isVisible();
     } else {
         $products = $this->pseudo == 'sale' ? Product::isDiscounted() : Product::inCategory($this->id);
         // Only show active and visible
         $products->isVisible();
     }
     // Eager load thumbnails
     if ($withThumbnails) {
         $products->with('thumbnail')->with('thumbnail_alt');
     }
     // Eager load discounts
     if ($withDiscounts) {
         $products->with('discounts')->with('categories.discounts');
     }
     // Standard product arrangements
     if ($this->arrangement_method == 'alpha_asc') {
         $products->orderBy('name', 'asc');
     } elseif ($this->arrangement_method == 'alpha_desc') {
         $products->orderBy('name', 'desc');
     } elseif ($this->arrangement_method == 'newest') {
         $products->orderBy('created_at', 'desc');
     } elseif ($this->arrangement_method == 'oldest') {
         $products->orderBy('created_at', 'asc');
     } elseif ($this->arrangement_method == 'custom' && !empty($this->arrangement_order)) {
         foreach ($this->arrangement_order as $id) {
             $products->orderBy(DB::raw("id <> {$id}"));
         }
     }
     // If a page value was passed in, query only products on that page
     if ($page > 0) {
         $products->onPage($page, $this->productsPerPage);
     }
     return $products->get();
 }