Problem with product options and "no" choice

  • Posts: 209
  • Thank you received: 18
10 years 6 months ago #183742

-- HikaShop version -- : 2.2.0
-- Joomla version -- : 2.5.28

Hi, I have a problem with product options.
My site is for an historic mansion that has a restaurant, gardens and activities as well as tours of the house.

Here is my scenario:

  • My main product is "High Tea for two people" - it has a base price of $100.
  • My first product option is for "Verandah with views" and can be added to the main product for an additional $10. This product has no charateristics so when I add it as a product option to the main product it gives me the choice of "No" or "Yes (+ $10)". That's fine, works perfectly.
  • My second product option can be added to the main product but it has charateristics called "Tour choices". First chracteristic is "Self-Guided tour @ $20" and second characteristic is "Tour guide @ $40".
My problem....

When I add the Tour Choices as an option to the main product it automatically includes the "Self-Guided tour @ $20". I don't have a choice to exclude the Tour choices. ie: there isn't a "No" variant.

I added a "--None--" variant to the characteristics of the second product option with no price and minimum quantity set to 0. I then set this as the default for the characteristic. BUT, when I accept this default and try to add the main product to the cart I get an error message that says "The product Tour choices: --None-- is not available".

How can I get the Tour choices option to accept "None" without giving an error?

(I am upgrading the site to Joomla 3 / Hikashop 2.3.4 in a few months so I don't really want to make changes to the underlying code if possible.)

Many thanks

Last edit: 10 years 6 months ago by JIK.

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

  • Posts: 83995
  • Thank you received: 13605
  • MODERATOR
10 years 6 months ago #183866

Hi,

This means that you must have the option "Display 'add to cart' button for free products" turned off in the Hikashop configuration and thus the system doesn't allow you to add products without prices. Turn that option off and it should work like you want.

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

  • Posts: 209
  • Thank you received: 18
10 years 6 months ago #183877

Hi Nicolas, thanks for replying.

Yes, turning off the "Display 'add to cart' button for free products" removes the error message, however then in my case if the Tour Choice is left as the variant "none" (ie: customer does not want either) it adds it to the cart as Free.

???

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

  • Posts: 83995
  • Thank you received: 13605
  • MODERATOR
10 years 6 months ago #183950

Hi,

You mean turning "on" the option no ?
The "Free" text can be removed with a translation override:
hikashop.com/download/languages.html#modify

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

  • Posts: 209
  • Thank you received: 18
9 years 6 months ago #223038

Hi, sorry to resurrect an old topic but I'm still trying to find a solution to this.

I have the "Display 'add to cart' button for free products" set to "Yes"

I have an option (Tour choices) on the product which has the following variants:

  • None
  • Self guided + $20
  • Tour guide +$40

If the use chooses the default "None" then "None" is added to the cart as a free product. Changing the language file does not prevent the "None" variant from being added to the cart.

If I set "Display 'add to cart' button for free products" to "No" then the "None" variant is not added to the cart but I get an error message saying "The product Tour choices: None is not available"

How do I get rid of the error message or prevent the "None" being added to the cart?

Help please!

PS: I tried to replicate this on your demo site under the Mac Book Pro product with "Test mouse" as an option but it has the same behavior.

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

  • Posts: 83995
  • Thank you received: 13605
  • MODERATOR
9 years 6 months ago #223119

Hi,

What you want to do in that case is remove the "none" variant from your option product. Instead of that, do this modification and that will do what you want:
hikashop.com/forum/product-category-disp...t-option.html#138030

The following user(s) said Thank You: JIK

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

  • Posts: 209
  • Thank you received: 18
8 years 6 months ago #256349

Hi Nicolas, its been a while since I revisited this - I gave up last time.

Changing the code on the product / option view works HOWEVER now if I add an option that does not have variants, it puts 2 "no" choices in for that option.

See image.

I've seen other posts describing this problem too but no solutions. Any help appreciated.

Attachments:

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

  • Posts: 4820
  • Thank you received: 654
  • MODERATOR
8 years 6 months ago #256403

Hello,

Can you try to remove this line (around line 24) :

$this->values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
In order to replace this (WITH previous customization suggest by Nicolas):
...
<?php
		$this->values = array(JHTML::_('select.option', 0,JText::_('HIKASHOP_NO')));
		$value = 0;
		$currency = hikashop_get('class.currency');
		$map = 'hikashop_product_option['.$i.']';
		$id = 'hikashop_product_option_'.$i;
		if(empty($optionElement->variants)){
			if(!$optionElement->product_published || (!$this->config->get('show_out_of_stock',1) && $optionElement->product_quantity==0)) continue;
			$this->values[] = JHTML::_('select.option', 0,JText::_('HIKASHOP_NO'));
			$text = JText::_('HIKASHOP_YES');
			$this->row =& $optionElement;
			if(!empty($optionElement->prices) && ...
...
To have this :
...
<?php
		$this->values = array(JHTML::_('select.option', 0,JText::_('HIKASHOP_NO')));
		$value = 0;
		$currency = hikashop_get('class.currency');
		$map = 'hikashop_product_option['.$i.']';
		$id = 'hikashop_product_option_'.$i;
		if(empty($optionElement->variants)){
			if(!$optionElement->product_published || (!$this->config->get('show_out_of_stock',1) && $optionElement->product_quantity==0)) continue;
// LINE ERASED HERE !!!
			$text = JText::_('HIKASHOP_YES');
			$this->row =& $optionElement;
			if(!empty($optionElement->prices) && ...
...

Hope this will solfe the "double no" issue AND still display good choices for products options WITH variants, awaiting news from you.

Regards

Last edit: 8 years 6 months ago by Philip.

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

  • Posts: 209
  • Thank you received: 18
8 years 6 months ago #256458

Thanks Philip, that removed the "double no". However, now I have the option defaulting to one of the priced variants and I don't have a "no" variant to set as the default.

I want the options to default to "no" which gives customers the choice of adding extras to their base product (ie: upsell). I have 5 options on my products and I don't want them to have to deselect the variants.

Please see image.



Here is my revised code in option.php in case I've not made the changes correctly:
<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.6.4
 * @author	hikashop.com
 * @copyright	(C) 2010-2016 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><table class="hikashop_product_options_table">
<?php
	$old_show_discount = $this->params->get('show_discount');
	$old_per_unit = $this->params->get('per_unit',1);
	$this->params->set('show_discount',0);
	$this->params->set('per_unit',0);
	$this->params->set('from_module','1');
	$i=0;
	$js="var hikashop_options=Array();";

	foreach($this->element->options as $optionElement) {
?>
	<tr>
<?php
		$this->values = array(JHTML::_('select.option', 0,JText::_('HIKASHOP_NO')));
		$value = 0;
		$currency = hikashop_get('class.currency');
		$map = 'hikashop_product_option['.$i.']';
		$id = 'hikashop_product_option_'.$i;
		if(empty($optionElement->variants)){
			if(!$optionElement->product_published || (!$this->config->get('show_out_of_stock',1) && $optionElement->product_quantity==0)) continue;
					$text = JText::_('HIKASHOP_YES');
			$this->row =& $optionElement;
			if(!empty($optionElement->prices) && $this->params->get('show_price')){
				$ok = null;
				$positive=1;
				foreach($optionElement->prices as $k => $price){
					if(empty($price->price_min_quantity)){
						$ok = $price;
						if($price->price_value<0) $positive=false;
						break;
					}
				}
				if($this->params->get('price_with_tax')){
					$price = $ok->price_value_with_tax;
				}else{
					$price = $ok->price_value;
				}
				$text.=' ( '.($positive?'+ ':'').$this->currencyHelper->format($price,$ok->price_currency_id).' )';
				$js.="
				hikashop_options[".(int)$optionElement->product_id."]=".(float)str_replace(',','.',$price).";";
			}
			$this->values[] = JHTML::_('select.option', $optionElement->product_id,$text);
		}else{
			$defaultValue=array();
			if(isset($optionElement->characteristics) && is_array($optionElement->characteristics) && count($optionElement->characteristics)){
				foreach($optionElement->characteristics as $char){
						$defaultValue[]=$char->characteristic_id;
				}
			}

			foreach($optionElement->variants as $variant){
				if(!$variant->product_published || (!$this->config->get('show_out_of_stock',1) && empty($variant->product_quantity))) continue;
				if($variant->product_sale_start>time()) continue;
				if($variant->product_sale_end!='' && $variant->product_sale_end!='0' && $variant->product_sale_end<time()) continue;
				if(empty($variant->variant_name)){
					if(empty($variant->characteristics_text)){
						$text = $variant->product_name;
					}else{
						$text = $variant->characteristics_text;
					}
				}else{
					$text = $variant->variant_name;
				}
				$this->row =& $variant;

				if(!empty($variant->prices) && $this->params->get('show_price')){
					$ok = null;
					$positive=1;
					foreach($variant->prices as $k => $price){
						if(empty($price->price_min_quantity)){
							$ok = $price;
							if($price->price_value<0) $positive=false;
							break;
						}
					}
					if($this->params->get('price_with_tax')){
						$price = $ok->price_value_with_tax;
					}else{
						$price = $ok->price_value;
					}
					$text.=' ( '.($positive?'+ ':'').$this->currencyHelper->format($price,$ok->price_currency_id).' )';
					$js.="
					hikashop_options[".(int)$variant->product_id."]=".(float)str_replace(',','.',$price).";";
				}
				if($defaultValue && isset($variant->characteristics) && is_array($variant->characteristics) && count($variant->characteristics)){
					$default = true;
					foreach($variant->characteristics as $char){
						if(!in_array($char->characteristic_id,$defaultValue)){
							$default = false;
						}
					}
					if($default){
						$value = $variant->product_id;
					}
				}
				$this->values[] = JHTML::_('select.option', $variant->product_id,$text);
			}
		}
		if(!count($this->values)) continue;
		$html = JHTML::_('select.genericlist', $this->values, $map, 'class="inputbox" size="1"  onchange="hikashopChangeOption();"', 'value', 'text', (int)$value, $id);
		if(!empty($optionElement->variants)){
			$optionInfo =& $optionElement->main;
		}else{
			$optionInfo =& $optionElement;
		}
		$options = '';
		if(!empty($optionInfo->product_description) || !empty($optionInfo->product_url)){
			$options='<img src="'.HIKASHOP_IMAGES.'info.png" alt="Information"/>';
			$description = '';
			if(!empty($optionInfo->product_description)){
				$description = $this->escape(html_entity_decode(strip_tags(JHTML::_('content.prepare',$optionInfo->product_description)), ENT_NOQUOTES | ENT_HTML401, 'UTF-8'));
				$options='<span class="hikashop_option_info" title="'.$description.'">'.$options.'</span>';
			}
			if(!empty($optionInfo->product_url)){
				if(empty($description)){
					$description = $optionInfo->product_name;
				}
				$popup = hikashop_get('helper.popup');
				$options = $popup->display(
						$options,
						$optionInfo->product_name,

						$optionInfo->product_url,
						'hikashop_product option_'.$optionInfo->product_id.'_popup',
						760, 480, '', '', 'link'
					);
			}
		}
		$html = '<span class="hikashop_option_name">'.$optionInfo->product_name.$options.'</span></td><td>' . $html;
?>
		<td><?php
			echo $html;
		?></td>
	</tr>
<?php
		$i++;
	}
	global $Itemid;
	$url_itemid='';
	if(!empty($Itemid)){
		$url_itemid='&Itemid='.$Itemid;
	}
	$baseUrl = hikashop_completeLink('product&task=price',true,true);
	if(strpos($baseUrl,'?') !== false)
		$baseUrl .= '&';
	else
		$baseUrl .= '?';
	$js .= "
function hikashopChangeOption(){
	var j = 0;
	total_option_price = 0;
	while(true){
		var option = document.getElementById('hikashop_product_option_'+j);
		if(!option){
			break;
		}
		j++;
		var option_price = hikashop_options[option.value];
		if(option_price){
			total_option_price+=option_price;
		}
	}
	var arr = new Array();
	arr = document.getElementsByName('hikashop_price_product');
	for(var i = 0; i < arr.length; i++){
		var obj = document.getElementsByName('hikashop_price_product').item(i);
		var id_price = 'hikashop_price_product_' + obj.value;
		var id_price_with_options = 'hikashop_price_product_with_options_' + obj.value;
		var price = document.getElementById(id_price);
		var price_with_options = document.getElementById(id_price_with_options);
		if(price && price_with_options){
			price_with_options.value = parseFloat(price.value) + total_option_price;
		}
	}
	hikashopRefreshOptionPrice();
}
function hikashopRefreshOptionPrice(){
	var price_div = document.getElementById('hikashop_product_id_main');
	var inputs = price_div.getElementsByTagName('input');
	if(inputs[0]){
		var id_price_with_options = 'hikashop_price_product_with_options_' + inputs[0].value;
		var price_with_options = document.getElementById(id_price_with_options);
		if(price_with_options){
			try{
				new Ajax('".$baseUrl."price='+price_with_options.value+'".$url_itemid."',  { method: 'get', onComplete: function(result) { var totalPrice = window.document.getElementById('hikashop_product_price_with_options_main'); if(totalPrice) totalPrice.innerHTML = result;}}).request();
			}catch(err){
				new Request({url:'".$baseUrl."price='+price_with_options.value+'".$url_itemid."', method: 'get', onComplete: function(result) { var totalPrice = window.document.getElementById('hikashop_product_price_with_options_main'); if(totalPrice) totalPrice.innerHTML = result;}}).send();
			}
		}
	}
}
window.hikashop.ready( function() { hikashopChangeOption(); });
";
	if(!HIKASHOP_PHP5)
		$doc =& JFactory::getDocument();
	else
		$doc = JFactory::getDocument();
	$doc->addScriptDeclaration("\n<!--\n".$js."\n//-->\n");
	$this->params->set('show_discount',$old_show_discount);
	$this->params->set('per_unit',$old_per_unit);
	$this->params->set('from_module','');
?>
</table>

Attachments:

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

  • Posts: 83995
  • Thank you received: 13605
  • MODERATOR
8 years 6 months ago #256503

Hi,

You can remove that line for that:

$value = $variant->product_id;

The following user(s) said Thank You: JIK

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

  • Posts: 209
  • Thank you received: 18
8 years 6 months ago #256510

Perfect Nicholas! Many thanks :)

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

Time to create page: 0.091 seconds
Powered by Kunena Forum