How to create 'No' option for optionals with variants

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313428

-- HikaShop version -- : 4.2.2
-- Joomla version -- : 3.8.11

Hi, I'm configuring optionals for a product and there is a problem with optionals that have variants. I'll try to explane, when I bind an optional with an only value to a main product, automatically hikashop adds an option 'No' to the select (image in attachment optional_1.png), when I bind to the main product an optional with variants hikashop doesn't add 'No' option, so I created a variant to simulate it (image optional_2.png), but when I add the main product to cart, optionals with variants are added too, even if variants values have not been selected. Can you help me?
Many thanks

Attachments:

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

  • Posts: 4508
  • Thank you received: 610
  • MODERATOR
4 years 4 months ago #313441

Hello,

Thanks for your return, it seems that you're right, there is something to correct on this point.
Can you try to process some test after a little modification in one of your file ?
Follow me step by step :
1. Edit your option.php file in your "YourWebsite\components\com_hikashop\views\product\tmpl" folder
2. Around line 70, your can see this :

...
    $option_values[] = JHTML::_('select.option', $optionElement->product_id, $text);
} else {
    if($this->config->get('add_no_to_options', 0) && $selectionMethod != 'check') {
        $option_values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
    }
...
3. Remove the part "$this->config->get('add_no_to_options', 0) && ", to have this :
...
    $option_values[] = JHTML::_('select.option', $optionElement->product_id, $text);
} else {
    if($selectionMethod != 'check') {
        $option_values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
    }
...

Make your return to see if in your case this work, we process some tests on our side, but before add this fix to our file we will wait your returns.

Regards

Last edit: 4 years 4 months ago by Philip.
The following user(s) said Thank You: lpeyotel

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313445

Thank you very much for your reply, now the 'No' option is listed in all optionals with variants, but I have another question. How can I set it like default option? Opening the main product page the default option in every optional select is the first variant value, I can see the 'No' option only if I click on the list.
Thank you again,
regards

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

  • Posts: 81504
  • Thank you received: 13063
  • MODERATOR
4 years 4 months ago #313450

Hi,

Similarily, you can change the line:
if($this->config->get('select_option_default_value', 1) && $selectionMethod != 'check') {
to:
if($selectionMethod != 'check') {
in the same file and it will select the "no" by default.

The following user(s) said Thank You: lpeyotel

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313458

Ok, it works. Thank you a lot,
regards

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313468

Hi, I'm sorry, but I made a mistake. I made a more careful test and the change does not configure the 'No' option as default. Probably because in the configuration process of the variants you need to configure a default option between those displayed in the drop-down menu and the 'No' option is not visible. My main product has many optionals with variants and if the user does not want to add them to the cart he must remove them all manually choosing the 'No' option. Do you have any suggestions on how to optimize this behavior?

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

  • Posts: 81504
  • Thank you received: 13063
  • MODERATOR
4 years 4 months ago #313469

Hi,

I tested the modifications on my end and the "no" value does get selected by default.
So I don't know why that wouldn't be the case on your end.
Could you please double check ?

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313499

Hi, I'm happy that your test indicates that the change is working correctly but it also means that I'm certainly doing something wrong in the configuration, so I am going back to the steps I followed for my test with images so you can see what or where I'm wrong:
step_1.creation of the feature with its multiple values
step_2.creation of the optional product and configuration of the feature with the default value
step_3.variants configuration in the optional product
step_4.addition of optional product to the main product
step_5.display of the optional product on the main product page, the 'No' option exists but is not displayed as default.

Please, can you tell me where i'm wrong?
Thank you a lot

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

  • Posts: 81504
  • Thank you received: 13063
  • MODERATOR
4 years 4 months ago #313502

Hi,

Could you provide a link to that product page and a screenshot of the page of the view override area where you did the code modifications so that we can better check on the situation on your website ?

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313532

Hi, line changed are 77/78 and 81/82 (

). I can't give you a link because site is on a test server with internal ip and it is not visible without vpn. Hoping that it could be useful, there is the html code analized with firefox tool of one of the optional product select component ( ). However to speed up the resolution times I am trying to modify the behavior through a custom plugin that uses hikashop cart api. Sorry if I wasted your time.
Regards

Attachments:

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

  • Posts: 10
  • Thank you received: 2
4 years 4 months ago #313565

Hi, I found a solution that works for me, in case it could be useful to someone else I explain what I did. I returned the file option.php to its original version, I added in characteristics and variants an option with text 'No' and then I modified the file option.php on line 94 (or near it) replacing this line

$option_values[] = JHTML::_('select.option', $variant->product_id, $text);

with the following block of code

if($text==JText::_('HIKASHOP_NO')){
$option_values[] = JHTML::_('select.option', 0, $text);
}else{
$option_values[] = JHTML::_('select.option', $variant->product_id, $text);
}



This gives me the possibility to manage also optional products that do not need 'No' option as for the laptop product in hikashop demo

Regards

The following user(s) said Thank You: Philip

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

  • Posts: 4508
  • Thank you received: 610
  • MODERATOR
4 years 4 months ago #313561

Hello,

I can see your error, I don't why but you have make 2 lines modifications, there is only 1 line to modify, in your screenshot it's the first line.
...
$option_values[] = JHTML::_('select.option', $optionElement->product_id, $text);
} else {
if($this->config->get('add_no_to_options', 0) && $selectionMethod != 'check') {
$option_values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
}
...

3. Remove only the part "$this->config->get('add_no_to_options', 0) && ", to have this :
...
$option_values[] = JHTML::_('select.option', $optionElement->product_id, $text);
} else {
if($selectionMethod != 'check') {
$option_values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
}
...

Hope this will be more clear, like this.

Regards

Last edit: 4 years 4 months ago by Philip.

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

Time to create page: 0.095 seconds
Powered by Kunena Forum