Jump to content

[SOLVED] - Get products from shopping cart into array


prestatent

Recommended Posts

Prestashop 1.5.4.1

 

Does anone know of a way to retrieve the item data from the shopping basket, so that I can put them into an array? I been looking at orderController.php, which creates the $products array of items in the shopping cart, but can't seem to work out a way to access this. Anyone have any ideas?

 

Thanks

Edited by prestatent (see edit history)
Link to comment
Share on other sites

  • 2 years later...

 

I tryed $products = $params['cart']->getProducts(true) in the blockcart.tpl

 

But when i print {$products} retur 'Array'

 

$params['cart']->getProducts return an array of products. you have to do foreach loop on $products variable (even if cart contains one product)

Link to comment
Share on other sites

Hi Vekia!
 

Works in order_payment.tpl the foreach.

 

{foreach from=$products item=produtos}

 

{$produtos.name}

 

{/foreach}

 

This code above return correct products names.

 

But i want to put this names inside another array in javascript code like this:

 

{foreach from=$products item=produtos}

 

<script type="text/javascript" src="integration.js"></script>
<script type="text/javascript">{literal}

 

   var data_array=[
     
      { name: 'identificador', value: 'name' },
      { name: 'email', value: '{/literal}{$cookie->email|escape:'htmlall':'UTF-8'}{literal}' },
      { name: 'Produto1', value: '{/literal}{$produtos.name}{literal}' },
      { name: 'Produto2', value: '{/literal}{$produtos.name}{literal}' }
    ];

 

 Integration.post(data_array, function(){
      return false;
    })

}{/literal}
</script>

{/foreach}

 

This code returns:

 

   var data_array=[
      { name: 'identificador', value: 'name' },
      { name: 'email', value: 'email' },
      { name: 'Produto1', value: 'Shampoo Tânagra Néctar da Terra Açaí 320ml' },
      { name: 'Produto2', value: 'Shampoo Tânagra Néctar da Terra Açaí 320ml' }


    ];

 

   var data_array=[
      { name: 'identificador', value: 'name' },
      { name: 'email', value: 'email' },
      { name: 'Produto1', value: 'Condicionador Tânagra Néctar da Terra Açaí 320ml' },
      { name: 'Produto2', value: 'Condicionador Tânagra Néctar da Terra Açaí 320ml' }


    ];

 

 

I want to get de products name like this:

 

 

   var data_array=[
      { name: 'identificador', value: 'name' },
      { name: 'email', value: 'email' },
      { name: 'Produto1', value: 'Shampoo Tânagra Néctar da Terra Açaí 320ml' },
      { name: 'Produto2', value: 'Condicionador Tânagra Néctar da Terra Açaí 320ml' }


    ];

 

UPDATE DONE!

 

{foreach from=$products item=produtos key=k}

 

  { name: 'Produto{/literal}{$k}{literal}', value: '{/literal}{$produtos.name}{literal}' }

 

Thks!!

Edited by FelipeGallo (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

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...