Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

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

 
  • rb22
  • Junior Member
  • Members
  • Join Date: 07-Feb 11
  • 10 posts

Posted 23 February 2012 - 05:08 PM #1

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

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11422 posts

Posted 24 February 2012 - 01:10 AM #2

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.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • rb22
  • Junior Member
  • Members
  • Join Date: 07-Feb 11
  • 10 posts

Posted 24 February 2012 - 04:14 AM #3

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.


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

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11422 posts

Posted 24 February 2012 - 05:42 AM #4

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.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • rb22
  • Junior Member
  • Members
  • Join Date: 07-Feb 11
  • 10 posts

Posted 24 February 2012 - 08:00 AM #5

And why are you setting two variables to the same data


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.