public function listProducts() { $products = ShopProduct::available()->with(['images' => function ($query) { $query->orderBy('sort_order', 'asc'); }]); if (!is_null($this->category)) { $products = $products->whereHas('categories', function ($q) { $q->where('category_id', '=', $this->category->id); }); } $products = $products->get()->each(function ($product) { $product->setUrl($this->productPage, $this->controller); }); return $products; }
public function loadProduct() { $product = ShopProduct::whereSlug($this->slug)->with(['images' => function ($query) { $query->orderBy('sort_order', 'asc'); }])->first(); if (!$product || empty($this->category)) { return $product; } // check category foreach ($product->categories as $category) { if (strcasecmp($category->slug, $this->category) == 0) { return $product; } } return null; }
protected function processItem($item) { // If the product doesn't exist, or it does exist but is out // of stock, we remove it from the cart and return early if (!($p = ShopProduct::find($item->id)) || isset($p) && !$p->inStock()) { $this->removeCartRow($item->rowid); return; } if (!$p->is_stockable) { return; } $p->stock -= $item->qty; $p->save(); }
public function loadProduct() { return ShopProduct::whereSlug($this->slug)->with(['images' => function ($query) { $query->orderBy('sort_order', 'asc'); }])->first(); }