Пример #1
0
 public function resetProductsSku()
 {
     $products = Product::all();
     foreach ($products as $prod => $value) {
         $categories = ProdCat::where('product_id', $value->id)->first();
         if ($categories) {
             $category = $categories->category_id;
         } else {
             $category = '0';
         }
         $product = Product::find($value->id);
         $product->sku = str_pad($category, 5, "0", STR_PAD_LEFT) . '-' . str_pad($value->id, 5, "0", STR_PAD_LEFT);
         $product->save();
     }
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * [setStock description]
  * Descontar producto del stock Models\Product
  */
 public function setStock()
 {
     $items = $this->getItems();
     foreach ($items as $item => $attr) {
         $Product = Product::find($attr['product_id']);
         $Product->stock = Calc::resta([$Product->stock], [$attr['qty']]);
         $Product->save();
     }
 }
Пример #4
0
 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();
 }
Пример #5
0
 /**
  * ------------------------------------------------
  * getTopItemSales
  * ------------------------------------------------
  * - Muestra las categorias de producto mas vendidos.
  *
  * - Obtiene lista de items vendidos.
  * - Obtiene las categorias de los productos
  * @return [type] [description]
  */
 public function getTopItemSales()
 {
     $ItemSales = ItemSale::all()->toArray();
     $TopItemSales = [];
     foreach ($ItemSales as $item => $attr) {
         $Product = Product::find($attr['product_id']);
         $TopItemSales[$item] = @$Product->categories->first()->name;
     }
     /**
      * Cuenta los valores
      * @var array
      */
     $Sales = @array_count_values($TopItemSales);
     /**
      * Ordena el array > to <
      */
     arsort($Sales);
     return array_slice($Sales, 0, 3);
 }
Пример #6
0
 public function loadProduct()
 {
     return ShopProduct::whereSlug($this->slug)->with(['images' => function ($query) {
         $query->orderBy('sort_order', 'asc');
     }])->first();
 }