-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty cart after page refresh. #8
Comments
Can you please post some code examples? |
use Illuminate\Http\Request;
use Vanilo\Cart\Facades\Cart;
use Vanilo\Cart\Contracts\CartItem;
//Add to Cart -- This works and returns quantity
$product = \App\Product::findBySlug($request->slug);
Cart::addItem($product, $request->qty);
return response()->json(['message' => 'Added to cart', 'cart_count' => Cart::itemCount()]); //Returns zero after refresh
if(Cart::exists()){
$cart_count = Cart::itemCount();
$cart = Cart::model()->items;
}else{
$cart_count = 0;
$cart = [];
}
return view('pages.front.cart', compact('cart', 'cart_count')); //Product model
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Vanilo\Contracts\Buyable;
use Vanilo\Product\Models\Product as BaseProduct;
use Vanilo\Support\Traits\BuyableModel;
use Vanilo\Support\Traits\BuyableImageSpatieV7;
use willvincent\Rateable\Rateable;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Vanilo\Category\Models\TaxonProxy;
use BrianFaust\Commentable\Traits\HasComments;
class Product extends BaseProduct implements Buyable, HasMedia
{
use
Rateable,
BuyableModel,
BuyableImageSpatieV7,
HasComments,
HasMediaTrait;
public function taxons(): MorphToMany
{
return $this->morphToMany(
TaxonProxy::modelClass(), 'model', 'model_taxons', 'model_id', 'taxon_id'
);
}
} |
Can you please also include the |
I've updated the code example |
Few tips:
return view('pages.front.cart', ['cart' => Cart::getItems(), 'cart_count' => Cart::itemCount()]); Regarding the bug: do you use the |
Thanks I have used the HasTaxons trait on my product model. I've updated the code to use Cart::getItems() instead, and yes, I use the Web middlleware in my controllers. I noticed the user_id field in the cart table is null, could that be one of the problems? |
No, the user <-> cart assignment is completely optional. Is the session working properly in your application? Eg. if you store some value, can you get the value back after page refresh? //store some data in controller
session()->put('hey', 'yo');
// ... refresh the page ...
session()->get('hey');
// Do you get 'yo' here?
|
Yes. Session works fine. I can store and retrieve the value. |
What's the value of |
when adding to cart
after adding to cart
after second refresh
|
Can you post the contents of |
My config/concrd.php file
I also don't have a config/vanilo.php file |
That's strange, because it looks as it should. What's the output of |
Null |
Prevents problems like issue #8 from silently happening.
What do |
config('session') returns
config('concord')
|
Please how can I fix this? |
Your complete vanilo config is gone. Somehow you overwrote it. |
|
Can you maybe zip your entire project along with the |
https://drive.google.com/file/d/1IffV0zfohUhfYvHb7lMRoZmGxKPJB6UX/view?usp=sharing |
My OS says it's not a zip file. Please either fix it or send .tar.gz |
Fixed https://drive.google.com/file/d/1f_J89IUUR5_iLmD8r2fCYifhd4iH0DCi/view?usp=sharing |
I've checked your code. Here's what to do: Move these 3 routes from Route::post('/cart/add', 'CartController@add')->name('add_to_cart');
Route::post('/cart/update/{cart_item?}', 'CartController@update')->name('update_cart');
Route::post('/cart/destroy/{cart_item?}', 'CartController@destroy')->name('destroy_cart'); Remove protected $except = [
'api/cart/*' // <- remove
]; In general, Vanilo could do much more for you. |
Thanks so much. It works now. |
I'll do that in the coming days. |
I'm implementing a custom Buyable Model but after successfully adding to Cart, cart count returns the correct values but after page refresh cart count goes back to zero.
The text was updated successfully, but these errors were encountered: