bumbummen99 / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
505 stars 234 forks source link

Update an existing option delete all other options #189

Closed beuzathor closed 1 year ago

beuzathor commented 1 year ago

Hi, I try to update one option but when i did it, all other option are deleted. I have many option like that

 'options' => [
                'sejour' => $sejour->id,
                'centre' => $sejour->centre->id,
                'semaine' => $options,
                'transport' => [
                    'aller' => [
                        'id' => ,
                        'date' => ,
                        'ville' =>,
                        'tarif' => ,

                    ],
                    'retour' => [
                        'id' => ,
                        'date' => ,
                        'ville' => ,
                        'tarif' => ,

                    ]
                ]

And when i try to update id do that 👍

 Cart::update($request->rowid,
            [
                'options' => [
                'transport' => [
                    'aller' => [
                        'id' => $request->transporta,
                        'ville' => 'ma ville',
                    ],

                ]
            ],
            ]);

But with that all the content in options is deleted and remplaced by new option. Is this normal behavior? Or is there another way to update some options without affecting others?

beuzathor commented 1 year ago

Chatgpt give me this solution 👍 $item = Cart::get($request->rowid); $options = $item->options->toArray(); $options['transport']['aller']['id'] = $transportaller->id; Cart::update($request->rowid, ['price' => $request->tarif_total, 'options' => $options, ]);

don't know if it is very efficient but this solution work....

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days