Jump to content

Products list in cart


polaije

Recommended Posts

Hi,

 

I have to override the ordercontroller to filter the products that are online only (used for another purpose).

 

I manage first to select the country of the client (needed to do the filter) but I cannot list the products.

My code is :

 

public function postProcess()
    {
        parent::postProcess();
  
  $address =new Address($this -> context -> cart ->id_address_delivery, $this->context->language->id);
 
  // =0 si pas address
  $idCountry =(int)$address->id_country;
  if($idCountry !=3 && $idCountry  !=0) {
   //Check cart for online_only products
   
   $products= ($this->cart_presenter->present($this->context->cart));
   
   foreach ($products as $p) {
       $id_product =$p['id_product'];
 
The last line report an error : Trying to get property of non-object
 
I can dump $products but I cannot retreive fields in it.
 
I am newbie in php, can anyone help me for this.
 
Regards,
Jean

 

Link to comment
Share on other sites

I have to say first that I am in Prestashop 1.7.

I have found a part of the solution geting the values of the cart but unfortunately the online_only field is not in.

 

To get this field I need to retrieve all the fields from product with the id_product in the cart.

I use this code :

$product = new Product((int)Tools::getValue($product_ids[$x]));

where $product_ids[$x] is the id_product for each product.

 

But the $product is filled with initial value, null for the name, etc...

 

How can I retreinve the values of product ?

 

Thanks in advance for help.

Jean

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...