Proper template override of characteristic display

  • Posts: 128
  • Thank you received: 3
10 years 1 week ago #213346

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

$options = ' '.$type.'="return hikashopUpdateVariant(this);"';

I wanted to add a function so that it reads:
$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 http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.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: 10 years 1 week ago by deuce4884.

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

  • Posts: 84305
  • Thank you received: 13700
  • MODERATOR
10 years 1 week ago #213353

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.

  • Posts: 128
  • Thank you received: 3
10 years 5 days ago #213783

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.055 seconds
Powered by Kunena Forum