John Davidson

php - how to get cart content of second shop in prestashop

0 comments
Message:


I have a multistore enable in my Prestashop, I would like to access the cart of the second shop in the first shop. How can I achieve this?


I can get the content of the cart in the current shop using the code below:


$this->context->cart

but how to access the cart of the second shop which is not in the current context



My Answer:
To access the cart of the second shop in Prestashop, you can use the following code:

php
// Get the context of the second shop
$context = Context::getContext();
$context->shop = new Shop(2); // Replace 2 with the ID of the second shop

// Get the cart of the second shop
$cart = $context->cart;

// Now you can access the cart content of the second shop using $cart


By setting the shop ID in the context, you can access the cart of the second shop in Prestashop.

Rate this post

4 of 5 based on 8607 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us