Skip to content
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

All item from different carts shown as user's cart #10

Closed
Romik90 opened this issue Jun 10, 2019 · 10 comments
Closed

All item from different carts shown as user's cart #10

Romik90 opened this issue Jun 10, 2019 · 10 comments
Assignees
Labels

Comments

@Romik90
Copy link

Romik90 commented Jun 10, 2019

If I open /shop uri or product page, Cart::getItems() return all items from database that belongs to different carts and users. On other pages everything works fine.

dd(Cart::model()) on /shop uri show this
#relations: array:2 [▼
"user" => User {#722 ▶}
"items" => Collection {#713 ▼
#items: array:4 [▶]
}
]

on any other page:
#relations: []

And ideas why?

@fulopattila122
Copy link
Member

What does your controller code on /shop URI do? What does it do on other pages?

@Romik90
Copy link
Author

Romik90 commented Jun 12, 2019

@fulopattila122 it does nothing special
`class ProductController extends Controller
{
/** @var ProductSearcher */
private $productSearcher;

public function __construct(ProductSearcher $productSearcher)
{
    $this->productSearcher = $productSearcher;
}

public function index(ProductIndexRequest $request, string $taxonomyName = null, Taxon $taxon = null)
{
    $properties = PropertyProxy::get();

    if ($taxon) {
        $this->productSearcher->withinTaxon($taxon);
    }

    return view('pages.categories', [
        'products'   => $this->productSearcher->popular()->paginate(30),
        'taxon'      => $taxon,
        'properties' => $properties,
        'filters'    => $request->filters($properties)
    ]);
}`

If I dd(\Cart::getItems()) inside index method, it shows correct cart items, but if I do the same in the template, it shows me everythins that exists in cart_items table

@fulopattila122
Copy link
Member

Can you show the code you're using in the template?

@Romik90
Copy link
Author

Romik90 commented Jun 13, 2019

{{ dd(Cart::model()) }} at the very beginning

@fulopattila122
Copy link
Member

Never use the Cart::model().

Here's a good example how to use the Cart facade in views: https://github.com/vanilophp/demo/blob/0.5/resources/views/cart/show.blade.php

@fulopattila122
Copy link
Member

Did that solve the problem?

@Romik90
Copy link
Author

Romik90 commented Jun 14, 2019

No. I actually use cart facade as in your demo. So I did {{ dd(Cart::getItems()) }} and result is the same, I see cart items from different carts which belongs to defferent users
Collection {#714 ▼
#items: array:4 [▼
0 => CartItem {#720 ▶}
1 => CartItem {#719 ▶}
2 => CartItem {#718 ▶}
3 => CartItem {#717 ▶}
]
}
In database
image
image

config/vanilo.php
'cart' => [
'extra_product_attributes' => ['weight', 'size', 'partner_id'],
'preserve_for_user' => true,
]

@Romik90
Copy link
Author

Romik90 commented Jun 14, 2019

And again, if I output cart items on main page, I see correct cart with only mine items
Collection {#646 ▼
#items: array:2 [▶]
}

@fulopattila122
Copy link
Member

Does that route have the web middleware? Looks like you have no session.

@Romik90
Copy link
Author

Romik90 commented Jun 15, 2019

I found out that in the web middleware group \Illuminate\Session\Middleware\AuthenticateSession::class was commented. After uncommenting everything works correct. Thank you so much, you saved my life!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants