Exemple #1
0
 /**
  * Products Index
  */
 public function index()
 {
     // Scoreboard queries
     $products['total'] = Product::all()->count();
     $products['isActive'] = Product::isActive()->count();
     $products['isInactive'] = $products['total'] - $products['isActive'];
     $products['inStock'] = Product::inStock()->count();
     $products['outOfStock'] = $products['isActive'] - $products['inStock'];
     $products['isDiscounted'] = Product::isDiscounted()->isActive()->count();
     $products['isFullPrice'] = $products['isActive'] - $products['isDiscounted'];
     $this->vars['products'] = $products;
     // Extend list controller
     $this->asExtension('ListController')->index();
 }
Exemple #2
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();
 }