prestatent Posted October 6, 2013 Share Posted October 6, 2013 (edited) 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 October 10, 2013 by prestatent (see edit history) Link to comment Share on other sites More sharing options...
prestatent Posted October 7, 2013 Author Share Posted October 7, 2013 Anyone? Link to comment Share on other sites More sharing options...
vekia Posted October 7, 2013 Share Posted October 7, 2013 you want to get all products in cart via php code? this is what you expect? for example variable $array with information about cart ? Link to comment Share on other sites More sharing options...
prestatent Posted October 7, 2013 Author Share Posted October 7, 2013 This is correct. I want to get certain values from the cart to load into another array. Thanks Link to comment Share on other sites More sharing options...
vekia Posted October 7, 2013 Share Posted October 7, 2013 in module hook you can use this: $products = $params['cart']->getProducts(true); Link to comment Share on other sites More sharing options...
prestatent Posted October 7, 2013 Author Share Posted October 7, 2013 Thanks Vekia. I'll have a look at this now. Link to comment Share on other sites More sharing options...
FelipeGallo Posted September 26, 2016 Share Posted September 26, 2016 I tryed $products = $params['cart']->getProducts(true) in the blockcart.tpl But when i print {$products} retur 'Array' I wawnt to print the name of the products in this cart Link to comment Share on other sites More sharing options...
vekia Posted September 26, 2016 Share Posted September 26, 2016 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 More sharing options...
FelipeGallo Posted September 29, 2016 Share Posted September 29, 2016 (edited) 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 September 29, 2016 by FelipeGallo (see edit history) Link to comment Share on other sites More sharing options...
FelipeGallo Posted October 11, 2016 Share Posted October 11, 2016 Hello! Back to my previous post, works fine in order_payment.tpl but didn't works in order_carrier.tpl or order_adress.tpl. Why is that? I put $products = $params['cart']->getProducts(true) in the shopping_cart.tpl. Regards, Felipe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now