Jump to content

New Hook In Product-List.tpl (Each Product In Category)


Ronaldo Perez

Recommended Posts

I feel like an idiot, send me in the right direction. :D

 

- Added a new hook,

- created in module method for this hook,

- using the data (linked to the price of goods)

Tools:: getValue ('id_product')

- On the product page everything is OK, of course.

 

I'm trying to use the same hook in product-list.tpl ie applied to each product on category page, but id_product not used here .. trying to think in the direction of Smarty (not clever - I know :) ), but templates are compiled after the php ...

 

I cannot figure out how to get ID each item and pass it on "hook" in my head is spinning or JS or spit on it all and do this directly without using hooks

 

I will be grateful for any of your thoughts:)

Link to comment
Share on other sites

why not just update the price in the catalog? if you make a change in the template, it is only going to effect the price shown in the template list. if a customer actually adds the product to the cart, the price will be the old price.

 

if you want the product id within that template, the variable is {$product.id_product}. if you want the products price, the variable is {$product.price}.

 

i would not recommend doing what you are doing, instead you should just update the products price in the back office catalog. if that is not an option for some reason, then I would suggest doing the calculation in the CategoryController,

 

the following code in CategoryController sets the product array for use in the template.

'products' => (isset($this->cat_products) AND $this->cat_products) ? $this->cat_products : NULL,

what i would suggest is to override the CategoryController, iterate through the $this->cat_products prior to adding it to the smarty array, and alter the product price accordingly. the template would not have to change then.

 

again doing this will only effect the display on the product listing, it will have no bearing on the actual price of the item.

Link to comment
Share on other sites

You probably do not understand me.

 

1. There is a module that calculates the price and other data using (based on) the product ID

2. The resulting data are displayed in a new hook - myHook

3. on the product page everything is OK, I get id_product - no problems

4. On category page - problem - I can not get id_product each product on category and pass out this id_product in "myHook"

 

I can override CategoryController and get my desired result. But then I have to move all logic of module in the controller, and lost the whole point of using the module

Link to comment
Share on other sites

The product-list loops each product in the $products array.

 

You would have to pass your hook the current product id as it executes the foreach. Not sure you can pass the current product as it loops from smarty.

 

From http://www.prestasho...by_julien_breux

 

As a guess, you would do something like below within your CategoryController method productListAssign.

 

foreach($this->cat_products as &$cat_product) $productIDs[] = $cat_product['id_product'];

Module::hookExec('NameOfHook', $productIDs);

 

You would then have to loop through the array in your module to access the product id.

 

Or I may be completely wrong.

  • Like 1
Link to comment
Share on other sites

damonsizzle, do not even know how to thank you! ;)

You made ​​me the right idea, I think ... I can do all the calculations for all the products on the page, and pass this array into a Smarty, then compare product ID and ID from array and display data in hook

 

Thank you very much

Link to comment
Share on other sites

  • 5 months 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...