Skip to main content

Proper template override of characteristic display

More
11 years 1 month ago - 11 years 1 month ago #213346 by deuce4884
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.24

I want to add an onchange function to the select that changes the variant. I looked into the file /administrator/com_hikashop/types/characteristic.php. On line 257 where it reads:
Code:
$options = ' '.$type.'="return hikashopUpdateVariant(this);"';

I wanted to add a function so that it reads:
Code:
$options = ' '.$type.'="return hikashopUpdateVariant(this);hikashopNoStockNoPrice();"';

I've created the function in a view file and it is present in the page source code. I read the documentation at www.hikashop.com/support/support/documen...tation.html#override . I copied the file at /administrator/com_hikashop/types/characteristic.php and pasted it into /templates/MY_TEMPLATE/html/hikashop_characteristics.php and made the change I mentioned above, but it's not working. I'm sure there's more involved that I'm not doing. Any help would be appreciated.
Last edit: 11 years 1 month ago by deuce4884.

Please Log in or Create an account to join the conversation.

More
11 years 1 month ago #213353 by nicolas
The documentation doesn't say that you should copy/paste that file.
It says that you need to create a hikashop_characteristics.php file and in it develop a function hikashop_characteristics_html(&$element,&$params,&$obj) and that to understand what you need to put in it, you'll want to look at the code in administrator/com_hikashop/types/characteristic.php
It actually won't be that easy.

In your case, I would do something different and not use the characteristic display override.
Instead, edit the file "show_block_characteristic" via the menu Display>Views, and change the line:
echo $this->characteristic->displayFE($this->element, $this->params) . '</div>';

to:
echo str_replace('return hikashopUpdateVariant(this);','return hikashopUpdateVariant(this);hikashopNoStockNoPrice();',$this->characteristic->displayFE($this->element, $this->params)) . '</div>';

That way, it's still done as an override, and even if you update HikaShop, you still use the standard characteristic system with just that JS function call added.
The following user(s) said Thank You: deuce4884

Please Log in or Create an account to join the conversation.

More
11 years 3 weeks ago #213783 by deuce4884
Thanks nicolas,
I saw the line of code you mentioned, but just did not think anything about a str_replace. Very simple fix. Worked perfect

Please Log in or Create an account to join the conversation.

Time to create page: 0.184 seconds
Powered by Kunena Forum