Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

CartItems are not correctly stored #675

Closed libertey closed 1 year ago

libertey commented 1 year ago

Hey, im trying to use that package for a shop section on our website. That Shop should be partly seperated from the 'main' website, but its all one source code. Created an controller function to add an item its also working pretty great till i redirect to the page where it should be shown there it seems like the session is not besing updated or something like that.

What i should say aswell we have already an bookingform on that website which also works in combination with that Cart Object. Maybe there is the Problem?

public function add(Request $request, $id)
    {
        $element = ShopElement::where('id', $request->get('element'))->first();

        Cart::instance('test')->add($id, "Product", 1, $request->query('price'), 0,$element->toArray());

// if dd() here the Object is stored inside of Cart::content(), but as soon as the redirect comes its removed

        return redirect()->route('shop');
    }

The code inside the view

@foreach($elements as $element)
        <div>
            <p>{{$element->getTitle()}}</p>
            <form method="post" action="{{route('shop.cart.add', [$element->id, 'element' => $element, 'type' => 'add', 'price' => $element->getSale() ? $element->getSale() : $element->getPrice()])}}">
                @csrf
                <button type="submit">To Basket</button>
            </form>
        </div>
    @endforeach

Any Help is appreciated.

libertey commented 1 year ago

I solved it was just a dumb mistake im using the shop as an Module and so i had forgot to attach the web middleware to my routes so it would not be sent all along.

Route::middleware(['web'])->group(function () {
//Routes write here
});

Si issue can be closed!