How to pass product's array from my addon into standart block

Hi,



Dear developers, I need some help during developing a my addon “cart_more”



Here is my code to get list of some products in checkout.cart page

I wrote in /addons/cart_more/controllers/customer/checkout.pre.php



list($products) = fn_get_products(...);
foreach ($products as $entry) {
$id = $entry['product_id'];
fn_gather_additional_product_data($entry, true, true, true, true, true);
$products[$id] = $entry;
}
$view->assign('products', $products);
$view->assign('items', $products);





In checkout.cart page I add a standart product-list block (for example /skins/a1/customer/blocks/products2.tpl) but



$view->assign('products', $products);
$view->assign('items', $products);




has no effect, and I see in new block a list of ALL products in my store ))) (not $products elements)



my /addons/cart_more/schemas/block_manager/structure.post.php



$schema['products']['fillings']['cart_more'] = array (
'params' => array (
'sort_by' => 'RAND()',
),
'locations' => array( // applicable to these locations only
'cart'
),
);




Help me please.



I want to get list of some special products in Cart page, and show this Product list in standart block

I would guess that you are doing your assignments when the page is POSTed to. Hence, a redirect occurs and your changes are lost.



Try enclosing your code inside


if( $_SERVER['REQUEST_METHOD'] != 'POST') {
your code here
}


and see if that helps.

[quote name='tbirnseth' timestamp='1330045817' post='131927']

I would guess that you are doing your assignments when the page is POSTed to. Hence, a redirect occurs and your changes are lost.



Try enclosing your code inside


if( $_SERVER['REQUEST_METHOD'] != 'POST') {
your code here
}


and see if that helps.

[/quote]



Thanks for your advice, but checkout.cart don't use $_REQUEST. It's a static page for show cart content.

Actually it's not static and it does do AJAX requests when an option is selected. It also will post any quantity changes that may occur.

However, that's beside the point.



First off, you should probably use a checkout.post.php since the pre is normally used for handling POSTed requests and setting the stage or adjusting things when the standard processing is performed. But since you are adding data it doesn't really matter where you do it. But using a checkout.post.php file will ensure that you are setting things after the standard processing but before the template engine is run. This will help ensure you don't have conflicts (or that you stomp on ones that do exist). And why are you setting two variables to the same data?



I would start by not using such common names as 'product' or 'items' for your template variables. It's is quite possible these are being used elsewhere.



What does the template debugger show you for the variables that are available to the page.

[quote]And why are you setting two variables to the same data[/quote]



In my addon I deside use an exists standart block for view a product list. I try to assign a standart variables in the hope that the block picks up one of these variables, and displays a list of products. So I tried to assing and products and items variables.



I need create a lite, minimal addon without any addon's skins files. only hooks and the use of standart cs-cart product-list-template.



I don't use template debugger. I will use it today.