/** * Query Builder: * * - who: 1 Product * - with: Categories (?) * - to whom: make() | product/{id} */ public function getProduct($id, $siteId = null) { $field = !is_numeric($id) ? "url" : "id"; $product = \Veer\Models\Product::where($field, '=', $id); if (!empty($siteId)) { $product = $product->checked()->sitevalidation($siteId)->with(array('categories' => function ($query) use($siteId) { $query->where('sites_id', '=', $siteId); })); } return $product->first(); }
/** * Make Product available if it's not. * * @helper Model update * @param int|null $id * @param timestamp|null $when * @return \Veer\Services\Administration\Elements\Product */ public function available($id = null, $when = null) { if ($id === false) { return $this; } if (empty($id)) { $id = $this->id; } if (empty($when)) { $when = now(); } if ($this->entity instanceof $this->className && $this->entity->id == $id) { $this->entity->to_show = $when; $this->entity->save(); } else { \Veer\Models\Product::where('id', '=', $id)->update(['to_show' => $when]); } event('veer.message.center', trans('veeradmin.product.show')); return $this; }