/** * Product */ public function onRun() { // Load the product $product = ProductModel::where('slug', $this->property('slug'))->with('discounts')->with('categories.discounts')->with('inventories')->with('images')->isActive()->first(); // Check if the product was found $this->exists = (bool) $product; if (!$this->exists) { return; } // Load product variables $this->name = $product->name; $this->slug = $product->slug; $this->description = $product->description; $this->price = $product->price; $this->fullPrice = $product->fullPrice; $this->isDiscounted = $product->isDiscounted; $this->discount = $product->discount; $this->images = $product->images; $this->inStock = $product->inStock; // Check if the product has multiple inventories $this->hasMultipleInventories = count($product->inventories) > 1; // Load the inventories into their container foreach ($product->inventories as $inventory) { if (Settings::get('show_oos_inventories') || $inventory->quantity > 0) { $this->inventories[] = $inventory; } } }
/** * Loads a product by inventory ID or product slug * @param integer $inventoryId * @param string $slug * @return Bedard\Shop\Models\Inventory */ private function loadInventory($inventoryId, $slug) { // If an inventory ID was passed in, find and return it if ($inventoryId) { return Inventory::inStock()->find($inventoryId); } // Otherwise, check the product and return it's first inventory $product = Product::where('slug', $slug)->with('inventories')->whereHas('inventories', function ($inventory) { $inventory->inStock(); })->isActive()->first(); // Grab the first inventory foreach ($product->inventories as $inventory) { return $inventory; } }