Can you show the addItem() method please ?
How to insert data into session with Item details
Hello guys, I managed to store item [product details ] to session. I would like to add some extra data to my item details. which are dynamic based on customer choice.
for example. Customer visit product 1 which has multiple Skus that contains details like size , color etc.
When customer add a specific product to cart. I store the item details and I would like to store the extra stuff too. like color size, SKU number etc.
I tried like below, but the dump data function is not showing the size, color and sku number.
public function addProductToCart(Request $request,$id){
$prevCart = $request->session()->get('cart');
$cart = new Cart($prevCart);
$sku_number = "DO-12345";
$size = "L";
$color = "Mauve";
$product = Product::find($id);
$cart->addItem($id,$product,$color,$size,$sku_number);
$request->session()->put('cart', $cart);
dump($cart);
// return back();
}
@MahmoudMonem You have declared your method with only 2 parameters $id and $product and you try to pass to it 5 parameters.
$cart->addItem($id,$product,$color,$size,$sku_number);
You have to change your declaration like this.
public function addItem($id,$product,$color,$size,$sku_number)
{
...
}
Please or to participate in this conversation.