Inheritance: extends Illuminate\Database\Eloquent\Model
Example #1
0
 public function getProduct($id = null)
 {
     $cart = $this->userCart();
     $product = Store\Product::with('masterProduct')->findOrFail($id);
     if (!$product->enabled) {
         abort(404);
     }
     return view('store.product', compact('cart', 'product'));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Store\Product::whereNotNull('custom_class')->delete();
     Schema::connection('mysql-store')->table('products', function ($table) {
         $table->dropColumn(['custom_class']);
         $table->integer('weight')->change();
         $table->decimal('cost', 10, 2)->change();
     });
     Schema::connection('mysql-store')->table('order_items', function ($table) {
         $table->dropColumn('extra_info');
     });
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Store\Product::whereNotNull('custom_class')->delete();
     Schema::connection("mysql-store")->table("products", function ($table) {
         $table->dropColumn(["custom_class"]);
         $table->integer("weight")->change();
         $table->decimal("cost", 10, 2)->change();
     });
     Schema::connection("mysql-store")->table("order_items", function ($table) {
         $table->dropColumn("extra_info");
     });
 }
Example #4
0
 public function getProduct($id = null)
 {
     $cart = $this->userCart();
     $product = Store\Product::with("masterProduct")->findOrFail($id);
     return view("store.product", compact("cart", "product"));
 }
Example #5
0
 public function updateItem($item_form, $add_new = false)
 {
     $quantity = intval(array_get($item_form, 'quantity'));
     $product = Product::find(array_get($item_form, 'product_id'));
     $extraInfo = array_get($item_form, 'extra_info');
     $result = [true, ''];
     if ($product) {
         if ($quantity <= 0) {
             $item = $this->items()->where('product_id', $product->product_id)->get()->first();
             if ($item) {
                 $item->delete();
             }
             if ($this->items()->count() === 0) {
                 $this->delete();
             }
         } else {
             $item = $this->items()->where('product_id', $product->product_id)->get()->first();
             if ($item) {
                 if ($add_new) {
                     $item->quantity += $quantity;
                 } else {
                     $item->quantity = $quantity;
                 }
             } else {
                 $item = new OrderItem();
                 $item->quantity = $quantity;
                 $item->extra_info = $extraInfo;
                 $item->product()->associate($product);
                 if ($product->cost === null) {
                     $item->cost = intval($item_form['cost']);
                 }
             }
             if (!$product->inStock($item->quantity)) {
                 $result = [false, 'not enough stock'];
             } elseif (!$product->enabled) {
                 $result = [false, 'invalid item'];
             } elseif ($item->quantity > $product->max_quantity) {
                 $result = [false, "you can only order {$product->max_quantity} of this item per order. visit your <a href='/store/cart'>shopping cart</a> to confirm your current order"];
             } else {
                 $this->save();
                 $this->items()->save($item);
             }
         }
     } else {
         $result = [false, 'no product'];
     }
     return $result;
 }
Example #6
0
 public function putRequestNotification($product_id, $action)
 {
     $user = Auth::user();
     $product = Store\Product::findOrFail($product_id);
     if ($product->inStock()) {
         return error_popup(trans('store.product.notification_in_stock'));
     }
     $request = $product->notificationRequests()->where('user_id', $user->user_id)->first();
     if ($request && $action === 'create') {
         return error_popup(trans('store.product.notification_exists'));
     } elseif ($request) {
         $request->delete();
     }
     if (!$request && $action === 'delete') {
         return error_popup(trans('store.product.notification_doesnt_exist'));
     } elseif (!$request) {
         $request = Store\NotificationRequest::create(['user_id' => $user->user_id, 'product_id' => $product_id]);
     }
     return js_view('layout.ujs-reload');
 }
Example #7
0
 public function updateItem($item_form, $add_new = false)
 {
     $quantity = intval($item_form["quantity"]);
     $product = Product::find($item_form["product_id"]);
     $extraInfo = array_key_exists("extra_info", $item_form) ? $item_form["extra_info"] : null;
     $result = [true, ""];
     if ($product) {
         if ($quantity <= 0) {
             $item = $this->items()->where("product_id", $product->product_id)->get()->first();
             if ($item) {
                 $item->delete();
             }
             if ($this->items()->count() === 0) {
                 $this->delete();
             }
         } else {
             $item = $this->items()->where("product_id", $product->product_id)->get()->first();
             if ($item) {
                 if ($add_new) {
                     $item->quantity += $quantity;
                 } else {
                     $item->quantity = $quantity;
                 }
             } else {
                 $item = new OrderItem();
                 $item->quantity = $quantity;
                 $item->extra_info = $extraInfo;
                 $item->product()->associate($product);
                 if ($product->cost === null) {
                     $item->cost = intval($item_form["cost"]);
                 }
             }
             if (!$product->inStock($item->quantity)) {
                 $result = [false, "not enough stock"];
             } elseif ($item->quantity > $product->max_quantity) {
                 $result = [false, "you can only order {$product->max_quantity} of this item per order. visit your <a href='/store/cart'>shopping cart</a> to confirm your current order"];
             } else {
                 $this->save();
                 $this->items()->save($item);
             }
         }
     } else {
         $result = [false, "no product"];
     }
     return $result;
 }