Automatically add an option as selected

  • Posts: 68
  • Thank you received: 1
  • Hikashop Business Hikashop Essential
3 hours 42 minutes ago #372241

-- HikaShop version -- : 6.3.0
-- Joomla version -- : 5.4.6

We have software products which have additional options, one of which is 12 months Support

We have got the "Support" option showing with the peroduct in the frontend (we have linked it an an "Option") but it's a selected option. We need to be able have have the "Support" option be set to "selected" by default. How can this be done please?

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

  • Posts: 85727
  • Thank you received: 14055
  • MODERATOR
32 minutes ago #372242

Hello,

There is no setting for this yet, but we will add one in the next release of HikaShop: you will be able to mark a product as selected by default when it is used as an option, directly on the product edit page.

In the meantime, you can do it with a small override of the "option" view. Go to Display > Views, open the product "option" view and save it once so HikaShop creates the override (your change is then kept on updates).

In that file, find the line that builds the option selector, it passes (int)$value as the selected value and looks like this (the helper may read JHtml or HTMLHelper depending on your version):

$html = JHtml::_('select.'.$select.'list', $option_values, $map, $attribs, 'value', 'text', (int)$value, $id);

Just above that line, add:
if(empty($optionElement->variants) && $optionElement->product_id == 123)
    $value = $optionElement->product_id;

Replace 123 with the id of your "Support" option product. That option will then be pre-selected on the product page, and the customer can still unselect it. To pre-select every option that has no variants, remove the "&& $optionElement->product_id == 123" part.

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

Time to create page: 0.035 seconds
Powered by Kunena Forum