Jump to content

access smarty variables


Recommended Posts


I'm trying to design a back office module to add personalized data to the $products in an order.

So far i was able to hookAdminOrder, to display custom data, quite easily.

But i also want to add a new variable to each product, lets say its "comment".

Later i would call it in the tpl to display it. Is this possible?


I can get the products, something like:



but i just wasn't able to add the field comment to each product...




Link to comment
Share on other sites

I'm not 100% sure what you're trying to do as I don't know where you're accessing the products from that you would need to use the above code (if you have the id of an order then you should be able to instantiate the object and access the products directly from there).


It sounds like you want to add a field ( e.g. comment ) to the product objects contained in an order object though? I assume AFTER the order has been placed (otherwise it would be the products in the Cart object you would manipulate). To do this you could override the Product object and add support for your field, and then add the corresponding field in the database table. This way any changes to the "comment" member variable of the product would be persistent (if you just try setting the variable on the object it will work within the current scope of the object but be lost when the object is recreated at the next page view).


Another way of doing this is to create your own independent object that maps your customisation to either the order or a combination of order and product id. This would store its data in a separate table. This is better since you're not making any changes to the basic functionality (or underlying database structure) but instead extending it.


I'm wondering though if maybe you should be using the "customisation" feature.... unless I'm misunderstanding what you're trying to achieve.

Link to comment
Share on other sites

FIrst of all, thanks for the quick reply.

The comment i was refering is a field i would fill, when creating the product, or after the creation.

I have tried the customization, but i thought it was used to get data from the customer, which is not what i want.


I thought it was possible to "intercept" the 'products' using some hook to add fields or change current ones.


I don't quite like using overrides, because i'm worried about future updates. I have used them, but as i learn more and more, i try to do something that would be compatible with future updates. At least more compatible.


I found a work around, using the override features to create new class, for example a getComment for a product. Then i can call it from the tpl file using something like {Product::getComment($variables)}.

This way i don't mess using current functions, and maybe this way i can upgrade more easily.


But if any knows how to "intercept" $products in adminOrderController using a hook instead of overrides, i would appreciate telling me how to do it. :)


Thanks again.


Link to comment
Share on other sites

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