Closed lstables closed 9 years ago
What does your cart contents look like and how are you doing the call to remove the item?
array (size=1)
'c42f6beec9c93fd6afea6eb0684aa99a' =>
object(Moltin\Cart\Item)[415]
protected 'identifier' => string 'c42f6beec9c93fd6afea6eb0684aa99a' (length=32)
protected 'store' =>
object(Moltin\Cart\Storage\LaravelSession)[408]
protected 'identifier' => null
public 'id' => string '06b49f57a1a0a8d316484be89e3be147' (length=32)
protected 'tax' =>
object(Moltin\Tax\Tax)[416]
protected 'percentage' => int 0
protected 'deductModifier' => int 1
protected 'addModifier' => int 1
protected 'data' =>
array (size=10)
'id' => string '9' (length=1)
'name' => string 'Test Product' (length=12)
'price' => string '10' (length=2)
'quantity' => string '1' (length=1)
'image' => string '' (length=0)
'path' => string 'category/new-in' (length=15)
'description' => string 'kjhsd' (length=5)
'stock' => string '1' (length=1)
'colour' => string '' (length=0)
'size' => string '' (length=0)
Then i have a route setup like so: Route::get('remove/{id}',['as' => 'remove','uses' => 'CartController@remove']);
Which point to this method on the controller:
public function remove($identifier)
{
Cart::remove($identifier);
return Redirect::back()->with('flash_success', 'Item successfully removed.'); // Want this to redirect back to the page or refresh but just remove a single item
}
Can you dump out the cart contents as an array please
Then if i click the remove button i have it links to http://clothing.app/remove/c42f6beec9c93fd6afea6eb0684aa99a
which is the identifier string.
it is as array is it not? I just did a dd() in Laravel
It's an object. We just need to see the cart contents - Cart::contents(true);
array (size=1)
'c42f6beec9c93fd6afea6eb0684aa99a' =>
array (size=10)
'id' => string '9' (length=1)
'name' => string 'Test Product' (length=12)
'price' => string '10' (length=2)
'quantity' => int 4
'image' => string '' (length=0)
'path' => string 'category/new-in' (length=15)
'description' => string 'kjhsd' (length=5)
'stock' => string '1' (length=1)
'colour' => string '' (length=0)
'size' => string '' (length=0)
So let me make sure I'm correct here, you've got 1 item in the cart 4 times. You're calling remove and the cart is empty on return? If so this is how it should work, it shouldn't however destroy the cart or remove your session. If that is happening I'm not sure it's something in the package causing it.
No if i have 3 different items in the cart and want to remove one item then it clears the session and the cart and shows an error.
Can you dump out the cart contents array before and after the destroy call, before the redirect please
the before is as above after trying to remove item it shows
array (size=1)
'620d670d95f0419e35f9182695918c68' =>
array (size=11)
'id' => string '11' (length=2)
'name' => string 'khf' (length=3)
'price' => string '12.989999771118' (length=15)
'quantity' => string '1' (length=1)
'image' => string 'TJvarSbjui2M.png' (length=16)
'path' => string 'category/new-in' (length=15)
'description' => string 'kjsdhk' (length=6)
'stock' => string '1' (length=1)
'delivery' => string '3.99' (length=4)
'colour' => string '' (length=0)
'size' => string '' (length=0)
With the URL showing as http://clothing.app/remove/c42f6beec9c93fd6afea6eb0684aa99a but the other product currently in the cart also as this:
array (size=1)
'c42f6beec9c93fd6afea6eb0684aa99a' =>
array (size=11)
'id' => string '9' (length=1)
'name' => string 'Test Product' (length=12)
'price' => string '10' (length=2)
'quantity' => string '1' (length=1)
'image' => string '' (length=0)
'path' => string 'category/new-in' (length=15)
'description' => string 'kjhsd' (length=5)
'stock' => string '1' (length=1)
'delivery' => string '3.99' (length=4)
'colour' => string '' (length=0)
with the url showing as http://clothing.app/remove/620d670d95f0419e35f9182695918c68
FYI my add to cart method looks like this too:
public function add() {
$input = Input::all();
// Pass the product ID with the request parameters
$id = Input::get('pid');
// Try to get the cart item by ID
$item = Cart::item($id);
// If the result if false then the items was not found
// in the cart and you need to create a new entry
if ($item === false)
{
$product = array(
'id' => $id,
'name' => $input['product'],
'price' => $input['price'],
'quantity' => $input['qty'],
'image' => $input['image'],
'path' => $input['path'],
'description' => $input['description'],
'stock' => $input['stock'],
'delivery' => $input['delivery'],
'colour' => $input['colour'],
'size' => $input['size']
);
}
else
{
// If it was found you just need to update the quantity
$item->quantity += (int) $input['qty'];
$product = $item;
}
Cart::insert($product);
$items = Cart::contents();
return View::make('cart.bag', compact('items'));
}
We're just trying to figure out if the redirect is the thing destroying the cart. So could you add your multiple products to the cart again and dump a cart contents array from before and after the remove call, exiting your script before the redirect.
You have it all above .
Sorry but from what you posted those are two different items as a before and after so I didn't think they were from the same process as requested.
Yes its from the same process. but the identifier string is different. Would it worth while you sharing my screen to see
We're trying to pin down your issue. We'd like to check this isn't a laravel issue. Have you tried not redirecting after removing the cart item? Does this still destroy the session?
yes i did a simple return 'Done'; message but still destroys the session.
Seems to be even after clearing cache and everything and starting again the identifier is always the same. if i had two items like before I get the same identifier string:
c42f6beec9c93fd6afea6eb0684aa99a
620d670d95f0419e35f9182695918c68
We can't replicate the issue, perhaps you can share your code with us on GH, and we can investigate it further?
Here's the whole repo - https://github.com/lstables/closetqueen
Also added you as Collaborator so you can dig deeper.
The repo make any sense? Do you think you can replicate and tell me where I've gone wrong?
We'll take a look into it shortly. Let us know if you make any progress in the meantime.
On a side note, you could always use Moltin to accomplish your entire e-commerce setup. https://molt.in
I will for sure, using your API i won't because I see you charge for this.
Help on this would be greatly appreciated.
Any progress on this?
?
If i have 3 products in the cart and use remove(); on a Laravel route to remove an item to then redirect back it shows that the session has been destroyed.
Why is this? Or am I doing something wrong?