jeudi 29 août 2019

adding items with the same product id in the cart

i am trying to add a second product with the same id but different size, but i keeps overwriting the first product.

when i dd the condition it display that it is in fact true but even if it has a different size it just takes the place of the first product.

    if(isset($cart[$id])&&($cart[$id]['size']==$request->productSize)) {
        $cart[$id]['quantity'] += $request->productQuantity;

        session()->put('cart', $cart);

        return redirect()->back()->with('success', 'Product added to cart successfully!');
    ;}


    if(isset($cart[$id])&&($cart[$id]['size']!==$request->productSize)) {
        $cart = [ 
            $id => [
                "name" => $product->productName,
                "price" => $product->productPrice,
                "size" => $request->productSize,
                "quantity" => $request->productQuantity,
                "photo" => $product->productImage
            ]
            ];

        session()->put('cart', $cart);

        return redirect()->back()->with('success', 'Product added to cart successfully!');
    ;}

expected result is displaying 2 or more same product with same id but different sizes in the cart before checkout.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PivJiT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire