PHP Controllers - 5 (product details)

Now we’ll bring it all together from the Admin side.

We have created an addon.xml which sets some default settings and describes the addon to the system.

We have registered PHP hooks so that when product info is requested, we return more detailed info as to whether it’s a movie or not

Now all we have to do is get ourselves a special ‘addons’ area entry in the product detail page to set our ‘is_movie’ field to ‘Y’ if the item is in fact a movie.

We do this by adding an template file of var/skins_repository/base/admin/addons/movie/hooks/products/detailed_content.tpl

This file would contain:


{include file="common_templates/subheader.tpl" title=$lang.movies}
{* checkboxes *}



Which as you can see it:
1) creates a subheader using the language variable 'movies' which should equate to 'Movies'
2) Add a label and checkbox for our 'is_movie' field.

Note that in cs-cart all checkboxes are either 'Y' or 'N'. No other values are supported (like true/false or anything else). Common practice is to default a checkbox to 'N' by adding a hidden field.

If/when you uninstall/install the addon, you should now see a Movies section in the product detail page of the admin panel which can be checked or not.

What will happen is this:
1) When the product detail page is loaded, the get_product_data hook will be used to return a 'is_movie' field to the product data with a default value of 'N'.
2) The product data is passed to the admin product detail page and the addon area will see the detailed_content.tpl related to this addon and will include it on the addons page.
3) If you check the box for is_movie and click Save, the value of 'is_movie' for this addon should become 'Y' and be effectively store with the product. This will be done through the update_product hook we added in the last session.

That's it. Archive of stuff built to date is at:

In the next (and maybe final) session we'll identify how to create a block that will just show products whose filling type is 'Movies'.

First of all, this series was incredibly helpful. Thanks for taking the time to share all of this information with the cs-cart community. I haven’t been able to find anything nearly as useful so far.

I followed your series and made a few add-ons that allow me to store additional information about products. I can see them in my admin section and all is well. However, i’m trying to take this a bit further, and i can’t figure out how to make this info available in my templates.


I created an add-on that stores a “product location”, as in, where the product is in our warehouse. I would like to pull this info for each ordered item and display it on our packing slip. ideally, i’d like to do this as part of the add-on, but i use my_changes to make changes, so that is an option as well.

Any tips would be greatly appreciated!

In my_changes/init.php add:


If you already have hooks registered, just add the new string to the argument list.

In func.php add:

function fn_my_changes_get_product_data_more(&$product_data) {
$my_field = db_get_field("SELECT from wherever you have your info stored WHERE product_id=?i AND other_options=?s", $product_data['product_id'], $other_options);
$product_data['my_location'] = $my_field;

Note: none of this is syntax checked, all off top of head.

You should then have a variable availabe as in {$product_data.my_location} in all views where a product is displayed. But this does not work for lists of products. For that you will need to use the get_products hook and that’s more involved than I can type.

[quote name=‘tbirnseth’] But this does not work for lists of products. For that you will need to use the get_products hook and that’s more involved than I can type.[/QUOTE]

I guess this isn’t as easy as i thought it might be, and this question probably shouldn’t be on this thread, but I’m trying to display the product location in this block of code in the packing slip.

{foreach from=$order_info.items item="oi"} {if $oi.amount > 0}

{if $oi.product_options}

{include file="common_templates/options_info.tpl" product_options=$oi.product_options

{/if} {/foreach}

I’ll look into the get_products hook. Thanks.

Thank you Tony for your sharing. It is really much appreciated.