Characteristic price is wrong when go back

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 1 week ago #355286

-- HikaShop version -- : 5.0.0
-- Joomla version -- : 4.3.4

Hello!

I noticed that, when i select 2 characteristics in a product and then add the product to cart, if i go back from the checkout page, the price is wrong.

Thank you

Attachments:

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 1 week ago #355288

Hi,

I'm sorry but I don't see the problem.
If I go back to the product from the checkout page on your website and reselect the same variant, I see the same price as the first time I selected the variant.
It seems to work fine.
Also, your two screenshots have the same price too.
Could you provide more information on how to reproduce the problem and what the problem is ?

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 1 week ago #355296

Hi,

I'm sending the correct screenshot, my bad!
If you go back you will see the correct selection but no add to cart button cause there's a 0 stock characteristic option for "Please select".
It's not about reselecting characteristics when you go back but about what you see (meaning the selection you made).

Thank you

Attachments:

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 1 week ago #355297

Hi,

That's normal.
If you want to see what you had selected, you need to turn off the "remove category and product id in the URLs" setting in the HikaShop configuration.
That way, provided that the "force canonical URLs on listings" setting is not activated, HikaShop will include the id of the variant in the URL of the product from the checkout and thus the system will automatically reselect the corresponding variant, and display the corresponding information on the product page.

The following user(s) said Thank You: verzevoul

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 1 week ago #355323

Hi,

I deactivated the "remove category and product id in the URLs" setting.
the "force canonical URLs on listings" setting is set as "Use canonical URL if specified".
Still not working.
Could you take a look Nicolas?

Thank you

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 1 week ago #355332

Hi,

As I said, you need to turn off the "force canonical URLs on listings" setting. The "Use canonical URL if specified" choice still means that the system takes into accoun the canonical URL.

The following user(s) said Thank You: verzevoul

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 1 week ago #355343

I turned it off but the same thing keeps happenning.

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 1 week ago #355345

Hi,

I don't see what you're talking about on your website now.
For example, I have this cart:
i.imgur.com/LT7Tn1H.png
The link on the first one is: index.php/metallika-epipla/krevatia/stromata-ypnou/product/1894-stroma-ypnou-candia-perfect
When I use it, I arrive on the page with 80*190 preselected and the price of 182€ displayed
The link on the second one is: index.php/metallika-epipla/krevatia/stromata-ypnou/product/1907-stroma-ypnou-candia-perfect
When I use it, I arrive on the page with 120*200 preselected and the price of 235€ displayed
Isn't that what you wanted to have ?
Or maybe I didn't understand what you meant ?

The following user(s) said Thank You: verzevoul

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 1 week ago #355372

Hi nicolas!

You are at this product and you add to cart the 140cm Πλάτος στρώματος and 200cm Μήκος Στρώματος product so the price for that is 270,00 €.
You click on "complete checkout" and you are at the checkout page.
Then you click the Back arrow on the browser and you go back at the product page, you will see there the characteristic options selected correctly but there will be no price or the "add to cart button" available.

I don't know if i'm not explaining it accurately, see the screenshots.

Thank you

Attachments:

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 6 days ago #355377

Hi,

Ok, I see what you mean. It's an artifact of the browser loading the page from the history.
Edit the file components/com_hikashop/views/product/tmpl/show_block_characteristic.php and change the code:

	<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>
window.hikashop.ready( function() { initVariants(); });
<?php } ?>
to:
window.hikashop.ready( function() {
	// register the default values on the charactersitics
	var elements = document.querySelectorAll('[data-characteristic="1"]');
	if(elements && elements.length == 1) {
		for (index = 0; index < elements.length; ++index) {
			elements[index].dataset.default = elements[index].selectedIndex;
		}
	}
	elements = document.querySelector('[data-characrow="1"] input');
	if(elements && elements.length == 1) {
		for (index = 0; index < elements.length; ++index) {
			if(elements[index].checked)
				elements[index].dataset.defaultchecked = true;
			else
				elements[index].dataset.defaultchecked = false;
		}
	}
	// reset the dropdowns and checkboxes when the page changes
	window.addEventListener('beforeunload', (event) => {
		var elements = document.querySelectorAll('[data-characteristic="1"]');
		if(elements && elements.length == 1) {
			for (index = 0; index < elements.length; ++index) {
				if(elements[index].tagName.toLowerCase() == 'select') {
					elements[index].selectedIndex = elements[index].dataset.default;
				}
			}
		}
		elements = document.querySelector('[data-characrow="1"] input');
		if(elements && elements.length == 1) {
			for (index = 0; index < elements.length; ++index) {
				elements[index].checked = elements[index].dataset.defaultchecked;
			}
		}
	});
<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>
	initVariants();
<?php } ?>
});
it should prevent the problem from happening.

Last edit: 7 months 1 week ago by nicolas.
The following user(s) said Thank You: verzevoul

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 6 days ago #355385

Hi,

I did it but still no change!

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 6 days ago #355388

Hi

You have a javascript error on your page which comes from the code:

<script> jQuery(function($) {       
            $('#tm-dialog-mobile .uk-nav-default, #tm-dialog-mobile .uk-nav-sub').addClass('uk-nav-parent-icon').attr('uk-nav', '');
            $('#tm-dialog-mobile .uk-nav-default .uk-parent > a, #tm-dialog-mobile .uk-nav-sub .uk-parent > a').append('<span uk-nav-parent-icon></span>');
            $('.uk-parent:has(.uk-active)').addClass('uk-active');
    });


<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/13956b617854c6a4f34c1e258/f7cfc75ded658143d0579e29d.js");

</script>
As you can see, you have a script tag inside a script tag, and that's not valid.

Because of that, the code I provided is not run by your browser and so it doesn't change anything.

The following user(s) said Thank You: verzevoul

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 6 days ago #355394

Nicolas,

I removed that code and i still see the same thing.

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 6 days ago #355405

Hi,

Indeed, I don't see that javascript error anymore.
However, I don't see the code I provided on your page.
Could it be that you have already a view override for show_block_characteristic ?
In that case, you also need to do the same change to the override of show_block_characteristic via the menu Display>Views of the HikaShop backend.

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 6 days ago #355410

Hi!

There are two more line with the code

<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>

Should i do something there also?

This is what i have now:
<?php
/**
 * @package	HikaShop for Joomla!
 * @version	4.6.2
 * @author	hikashop.com
 * @copyright	(C) 2010-2022 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
if(empty($this->element->characteristics))
	return;

?>
<div id="hikashop_product_characteristics" class="hikashop_product_characteristics">
<?php
if($this->params->get('characteristic_display') != 'list') {

	$app = JFactory::getApplication();
	$config = hikashop_config();
	$characteristics_dynamic_display = $config->get('characteristics_dynamic_display', 1);

	$this->characteristics=&$this->element->main->characteristics;
	foreach($this->characteristics as $k => $characteristic) {
		if(empty($this->characteristics[$k]->characteristic_display_method)) {
			$this->characteristics[$k]->characteristic_display_method = $this->params->get('characteristic_display');
		}
	}

	$chromePath = JPATH_THEMES . DS . $app->getTemplate() . DS . 'html' . DS . 'hikashop_characteristics.php';
	if(file_exists($chromePath)) {
		require_once ($chromePath);
		if(function_exists('hikashop_characteristics_html')) {
			echo hikashop_characteristics_html($this->element, $params, $this);
			echo '</div>';
			return;
		}
	}

	$html = '';
	$js = '';
	$ids = array_keys($this->characteristics);
	$list = '[\''.implode('\',\'',$ids).'\']';

	switch($this->params->get('characteristic_display')){
		case 'table':
			if(count($this->characteristics) == 2) {
				$html = '';
				$firstCharacteristic = reset($this->characteristics);
				$secondCharacteristic = end($this->characteristics);

				$html.= '<table class="hikashop_product_characteristic_chooser"><tr><td></td>';
				if(!empty($secondCharacteristic->values)){
					foreach($secondCharacteristic->values as $value){
						$html.='<td>'.hikashop_translate($value->characteristic_value).'</td>';
					}
				}
				$html.='</tr>';
				$this->options=' onclick="return hikashopUpdateVariantData(this.value);"';
				$size=0;
				if(!empty($firstCharacteristic->values)){
					foreach($firstCharacteristic->values as $value){
						$html .= '<tr><td style="text-align:right">'.hikashop_translate($value->characteristic_value).'</td>';
						if(strlen($value->characteristic_value)>$size)
							$size=strlen($value->characteristic_value);
						if(!empty($secondCharacteristic->values)) {
							foreach($secondCharacteristic->values as $value2) {
								$class = '';
								$classspan = '';
								$extra = '';
								foreach($this->element->variants as $k => $variant) {
									$char1 = false;
									$char2 = false;
									foreach($variant->characteristics as $variantCharacteristic) {
										if($variantCharacteristic->characteristic_id == $value->characteristic_id) {
											$char1 = true;
										} elseif($variantCharacteristic->characteristic_id == $value2->characteristic_id) {
											$char2 = true;
										}
										if($char1 && $char2) {
											if(!$variant->product_published || $variant->product_quantity == 0) {
												$class = ' hikashop_product_variant_out_of_stock';
												$classspan=' hikashop_product_variant_out_of_stock_span';
											}else {
												$extra = ' data-stock="'.(int)$variant->product_quantity.'"';
											}
											break 2;
										}
									}
								}

								$name = '_'.$value->characteristic_id.'_'.$value2->characteristic_id;
								$radio = "\n\t<span class=\"hikashop_product_characteristic_span".$classspan."\"><input type=\"radio\" class=\"hikashop_product_characteristic".$class."\" name=\"hikashop_product_characteristic\"".$extra." id=\"hikashop_product_characteristic".$name."\" value=\"".$name."\" ".$this->options;
								if($this->characteristics[$value->characteristic_parent_id]->default->characteristic_id == $value->characteristic_id && !empty($this->characteristics[$value2->characteristic_parent_id]->default->characteristic_id) && $this->characteristics[$value2->characteristic_parent_id]->default->characteristic_id == $value2->characteristic_id) {
									$radio .= ' checked';
								}
								$radio .= " /></span>";
								$html .= '<td>'.$radio.'</td>';
							}
						}
						$html .= '</tr>';
					}
				}
				$html .= '</table>';
				if($this->params->get('characteristic_display_text')) {
					$space = '';
					for($i = 0; $i <= $size; $i++) {
						$space .= '&nbsp;&nbsp;';
					}
					$html = '<table class="hikashop_product_characteristic_chooser"><tr><td></td><td class="hikashop_charactersitic_name">'.$space.@$secondCharacteristic->characteristic_value.'</td></tr><tr><td class="hikashop_charactersitic_name">'.$firstCharacteristic->characteristic_value.'</td><td>'.$html.'</td></table>';
				}
				break;
			}

		default:
		case 'radio':
		case 'dropdown':
			$main_html = '<table class="hikashop_product_characteristics_table">';
			$config = hikashop_config();
			$count = count($this->characteristics);
			$i = 0;
			foreach($this->characteristics as $characteristic) {
				$i++;
				$main_html.='<tr class="hikashop_characteristic_line_'.$characteristic->characteristic_id.'" data-characrow="'.$i.'">';
				$values = array();
				$switch_done = false;
				if(!empty($characteristic->values)) {
					foreach($characteristic->values as $k => $value){
						if(!$config->get('show_out_of_stock',1)){
							$hasQuantity = false;
							foreach($this->element->variants as $variant){
								foreach($variant->characteristics as $variantCharacteristic){
									if($variantCharacteristic->characteristic_id==$value->characteristic_id){
										if($variant->product_quantity != 0){
											$hasQuantity = true;
										}elseif( $this->element->product_id==$variant->product_id && !$switch_done){
											if($characteristic->characteristic_display_method == 'dropdown'){
												$id = 'hikashop_product_characteristic_'.$characteristic->characteristic_id;
												$js = "hikashopUpdateVariant(document.getElementById('".$id."'));";
											}else{
												$id = 'hikashop_product_characteristic['.$characteristic->characteristic_id.']';
												$js = "var el = document.querySelector('[name=\"".$id."\"]'); if(el) el.checked = true; hikashopUpdateVariant(el);";
											}

											$js = "
											window.hikashop.ready( function() {".$js."});";
											$switch_done = true;
										}
									}
								}
							}
							if(!$hasQuantity)
								continue;
						}
						$values[$k] = $value->characteristic_value;
					}
				}

				if(empty($values) || !is_array($values)){
					echo JText::_('NO_VALUES_FOUND');
					echo '</div>';
					return;
				}

				if(is_array($this->characteristics)){
					$characteristic_id = @$characteristic->characteristic_id;
					@$characteristic->characteristic_id = 'hikashop_product_characteristic['.$characteristic_id.']';
					$id = 'hikashop_product_characteristic_'.$characteristic_id;
				}else{
					$id = $characteristic_id = $map;
				}
				$selected = (int)@$characteristic->default->characteristic_id;

				$this->values = array();
				if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) {
					if($characteristic->characteristic_display_method!='radio')
						$this->values[] = JHTML::_('select.option', '', JText::_('PLEASE_SELECT') );
					$selected = '';
				}
				foreach($values as $key => $val){
					if(strlen($val)!=0 && empty($val)){
						$val = $val.'&nbsp;';
					}

					if(strpos($val, '<img ') !== false)
						$val = str_replace('<img ', '<img onclick="return hikashopVariantSelected(\'hikashop_product_characteristic_'.$characteristic_id.$key.'\');" ', $val);
					$clean = hikashop_translate(strip_tags($val));
					$optionValue = ($characteristic->characteristic_display_method != 'radio' && !empty($clean) ? $clean : hikashop_translate($val));

					$obj = new stdClass;
					$obj->value  = $key;
					$obj->text = $optionValue;
					$obj->id = 'hikashop_product_characteristic_'.$characteristic_id.'_'.$key;
					$this->values[] = $obj;
				}

				$type = 'onclick';
				if($characteristic->characteristic_display_method!='radio'){
					$characteristic->characteristic_display_method='generic';
					$type = 'onchange';
				}
				$options = ' '.$type.'="return hikashopVariantSelected(this);"';
				$options .=' data-characteristic="'.$i.'"';
				if($count == $i)
					$options .=' data-last="1"';

				$html = JHTML::_('select.'.$characteristic->characteristic_display_method.'list', $this->values, @$characteristic->characteristic_id, 'class="custom-select" size="1"' . $options, 'value', 'text', $selected, $id );
				if($this->params->get('characteristic_display_text') && isset($characteristic->characteristic_value)) {

					$html = hikashop_translate($characteristic->characteristic_value).'</td><td>'.$html;
				}
				$main_html .= '<td>'.$html.'</td></tr>';
			}
			$main_html .= '</table>';
			$html = $main_html;

			if($characteristics_dynamic_display) {
				$matches = $this->getAllValuesMatches($this->characteristics, $this->element->variants, $this->element->main);
				$js.="\r\n".'window.hikashop.availableValues = [';
				if($matches) {
					foreach($matches as $value_id => $children) {
						$js.="\r\n\t"."[".implode(',',$children)."],";
					}

				}
				$js.="\r\n".'];';
			}

			break;
	}

	echo $html;
?>
	<script>
<?php echo $js; ?>

window.hikashop.ready( function() {
	// register the default values on the charactersitics
	var elements = document.querySelectorAll('[data-characteristic="1"]');
	if(elements && elements.length == 1) {
		for (index = 0; index < elements.length; ++index) {
			elements[index].dataset.default = elements[index].selectedIndex;
		}
	}
	elements = document.querySelector('[data-characrow="1"] input');
	if(elements && elements.length == 1) {
		for (index = 0; index < elements.length; ++index) {
			if(elements[index].checked)
				elements[index].dataset.defaultchecked = true;
			else
				elements[index].dataset.defaultchecked = false;
		}
	}
	// reset the dropdowns and checkboxes when the page changes
	window.addEventListener('beforeunload', (event) => {
		var elements = document.querySelectorAll('[data-characteristic="1"]');
		if(elements && elements.length == 1) {
			for (index = 0; index < elements.length; ++index) {
				if(elements[index].tagName.toLowerCase() == 'select') {
					elements[index].selectedIndex = elements[index].dataset.default;
				}
			}
		}
		elements = document.querySelector('[data-characrow="1"] input');
		if(elements && elements.length == 1) {
			for (index = 0; index < elements.length; ++index) {
				elements[index].checked = elements[index].dataset.defaultchecked;
			}
		}
	});
<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>
	initVariants();
<?php } ?>
});
function initVariants() {
	var allRows = document.querySelectorAll('tr[data-characrow]'), first = true,
	qtyArea = document.getElementById('hikashop_product_quantity_main'), altArea = document.getElementById('hikashop_product_quantity_alt');
	for (index = 0; index < allRows.length; ++index) {
		if(first) {
			first = false;
		} else {
			allRows[index].style.display = 'none';
		}
	}
	if(qtyArea) {
		qtyArea.style.display = 'none';
	}
	if(altArea) {
		altArea.style.display = '';
	}

<?php if(@$this->displayVariants['prices']) { ?>
	var priceDivs = document.querySelectorAll('#hikashop_product_price_main > .hikashop_product_price_full');
	priceDivs.forEach(function (sub) { sub.style.display = 'none'; });
<?php } ?>

<?php if( $characteristics_dynamic_display <= 1) { ?>
	var firstEl = document.querySelector('[data-characteristic="1"]');
	var firstRow = document.querySelector('[data-characrow="1"]');
	var autoSelect = false;
	if(firstEl.tagName.toLowerCase() == 'select') {
		if(firstEl.options.length == 2) {
			autoSelect = true;
			firstEl.selectedIndex = firstEl.options.length - 1;
			if(window.jQuery && typeof(jQuery().chosen) == "function") {
				jQuery( "#hikashop_product_characteristics select" ).chosen('destroy').chosen({disable_search_threshold:10, search_contains: true});
			}
		}
	} else {
		var inputs = firstRow.querySelectorAll('input');
		if(inputs.length == 1) {
			autoSelect = true;
			inputs[inputs.length-1].checked = true;
		}
	}

	if(autoSelect) {
		if(firstEl.tagName.toLowerCase() == 'select') {
			hikashopVariantSelected(firstEl);
		} else {
			hikashopVariantSelected(inputs[inputs.length-1]);
		}
	}
<?php } ?>
}

function getValidVariants(pos) {
	var allInputs = document.querySelectorAll('[data-characteristic]'), selectedElements = [], validVariants = [];

	for (index = 0; index < allInputs.length; ++index) {
		var input = allInputs[index];
		if(input.tagName.toLowerCase() == 'select') {
			if(input.selectedIndex && input.value)
				selectedElements[selectedElements.length] = parseInt(input.options[input.selectedIndex].value);
		} else {
			if(input.checked)
				selectedElements[selectedElements.length] = parseInt(input.value);
		}
		if(selectedElements.length == pos)
			break;
	}

	if(!selectedElements.length)
		return window.hikashop.availableValues;

	for (index = 0; index < window.hikashop.availableValues.length; ++index) {
		var valid = true;
		for (index2 = 0; index2 < selectedElements.length; ++index2) {
			if(selectedElements[index2] != window.hikashop.availableValues[index][index2]) {
				valid = false;
				break;
			}
		}
		if(valid){
			validVariants[validVariants.length] = window.hikashop.availableValues[index];
		}
	}
	return validVariants;
}

function hikashopVariantSelected(obj) {
<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>
	if(typeof(obj) == "string")
		obj = document.getElementById(obj);
	if(!obj)
		return true;
	var pos = obj.getAttribute('data-characteristic'), last = obj.getAttribute('data-last'), otherRow = null,
	qtyArea = document.getElementById('hikashop_product_quantity_main'), altArea = document.getElementById('hikashop_product_quantity_alt');
	if(!last) {
		validVariants = getValidVariants(pos);

		if(validVariants.length < 1 && obj.value != '') {
			console.log('characteristic value with id ' + obj.value + ' missing in window.hikashop.availableValues');
		} else {
			var next = parseInt(pos) + 1;
			var nextEl = document.querySelector('[data-characteristic="'+next+'"]');
			var nextRow = document.querySelector('[data-characrow="'+next+'"]');
			if(nextEl.tagName.toLowerCase() == 'select') {
				nextEl.selectedIndex = 0;
			} else {
				var inputs = nextRow.querySelectorAll('input');
				for (index = 0; index < inputs.length; ++index) {
					inputs[index].checked = false;
				}
			}
			if(obj.value == '') {
				nextRow.style.display = 'none';
			} else {
				nextRow.style.display = '';
			}
			next++;
			while(otherRow = document.querySelector('[data-characrow="'+next+'"]')) {
				next++;
				otherRow.style.display = 'none';
			}
			var autoSelect = false;
			if(nextEl.tagName.toLowerCase() == 'select') {
				var count = 0;
				var lastIndexFound = 0;
				for (index = 0; index < nextEl.options.length; ++index) {
					var found = false;
					for (i = 0; i < validVariants.length; ++i) {
						var currentVariant = validVariants[i];
						if(parseInt(nextEl.options[index].value) == currentVariant[pos]) {
							found = true;
							lastIndexFound = index;
							nextEl.options[index].hidden = false;
							nextEl.options[index].disabled = false;
						}
					}
					if(!found && index != 0) {
						nextEl.options[index].hidden = true;
						nextEl.options[index].disabled = true;
					} else {
						count++;
					}
				}

				if(count==2) {
					autoSelect = true;
					nextEl.selectedIndex = lastIndexFound;
				}
				if(window.jQuery && typeof(jQuery().chosen) == "function") {
					jQuery( "#hikashop_product_characteristics select" ).chosen('destroy').chosen({disable_search_threshold:10, search_contains: true});
				}
			} else {
				var inputs = nextRow.querySelectorAll('input');
				var count = 0;
				var lastIndexFound = 0;
				for (index = 0; index < inputs.length; ++index) {
					var found = false;
					for (i = 0; i < validVariants.length; ++i) {
						var currentVariant = validVariants[i];
						if(parseInt(inputs[index].value) == currentVariant[pos]) {
							found = true;
							lastIndexFound = index;
							inputs[index].parentNode.style.setProperty('display', '', 'important');
						}
					}

					if(!found) {
						inputs[index].parentNode.style.setProperty('display', 'none', 'important');
					} else {
						count++;
					}
				}
				if(count==2) {
					autoSelect = true;
					inputs[lastIndexFound].checked = true;
				}
			}

			if(qtyArea) {
				qtyArea.style.display = 'none';
			}
			if(altArea) {
				altArea.style.display = '';
			}
			if(autoSelect) {
				if(nextEl.tagName.toLowerCase() == 'select') {
					hikashopVariantSelected(nextEl);
				} else {
					hikashopVariantSelected(inputs[lastIndexFound]);
				}
			}
			return;
		}
	}
	if(obj.value != '') {
		if(qtyArea) {
			qtyArea.style.display = '';
		}
		if(altArea) {
			altArea.style.display = 'none';
		}
	} else {
		if(qtyArea) {
			qtyArea.style.display = 'none';
		}
		if(altArea) {
			altArea.style.display = '';
		}
	}
<?php } ?>
	hikashopUpdateVariant(obj);
}
function hikashopUpdateVariant(obj) {
	var options = <?php echo $list; ?>;
	var len = options.length, selection = '', found = false, el = null;
	if(typeof(obj) == "string")
		obj = document.getElementById(obj);
	if(!obj)
		return true;
	try { obj.blur(); } catch(e){}
	for (var i = 0; i < len; i++) {
		el = document.getElementById('hikashop_product_characteristic_'+options[i]);
		if(el) {
			selection += '_' + el.value;
			continue;
		}
		var form = document['hikashop_product_form'];
		if(!form) {
			continue;
		}
		var checkFields = form.elements['hikashop_product_characteristic['+options[i]+']'];
		if(checkFields && !checkFields.length && checkFields.value) {
			selection += '_' + checkFields.value;
			continue;
		}
		var len2 = (checkFields ? checkFields.length : 0);
		for (var j = 0; j < len2; j++) {
			if(checkFields && checkFields[j] && checkFields[j].checked) {
				selection += '_' + checkFields[j].value;
				found = true;
			}
		}
		if(!found) {
			return true;
		}
	}

	hikashopUpdateVariantData(selection);
	if(window.Oby && window.Oby.fireAjax) window.Oby.fireAjax("hkAfterUpdateVariant", {obj:obj,selection:selection});
	return true;
}

function hikashopUpdateVariantData(selection) {
	if(!selection)
		return true;
	var names = ['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files'];
	var len = names.length;
	for(var i = 0; i < len; i++){
		var el = document.getElementById('hikashop_product_'+names[i]+'_main');
		var el2 = document.getElementById('hikashop_product_'+names[i]+selection);
		if(el && el2)
			el.innerHTML = el2.innerHTML.replace(/_VARIANT_NAME/g, selection).replace(/data-content/g, 'content').replace(/data-itemprop/g, 'itemprop');
	}
	if(window.hikaProductOptions) hikaProductOptions.refreshPrice();
	else if(typeof this.window['hikashopRefreshOptionPrice'] == 'function') hikashopRefreshOptionPrice();
	if(window.Oby && window.Oby.fireAjax) window.Oby.fireAjax("hkContentChanged", {selection:selection});
	return true;
}
	</script>
</div>
<?php
	return;
}

if(!empty($this->element->main->characteristics)) {
	$columns=0;
	if((int)$this->config->get('show_quantity_field') >= 2) {
?>
	<form action="<?php echo hikashop_completeLink('product&task=updatecart'); ?>" method="post" name="hikashop_product_form_variants" enctype="multipart/form-data">
<?php
	}
?>
	<table class="hikashop_variants_table hikashop_products_table adminlist table table-striped table-hover" cellpadding="1">
		<thead class="hikashop_variants_table_thead">
			<tr class="hikashop_variants_table_thead_tr">
<?php if($this->config->get('thumbnail') && @$this->displayVariants['images']) { $columns++; ?>
				<th class="hikashop_product_image title hikashop_variants_table_th"><?php
					echo JText::_( 'HIKA_IMAGE' );
				?></th>
<?php }
	if(@$this->displayVariants['variant_name']) { $columns++; ?>
				<th class="hikashop_product_name title hikashop_variants_table_th"><?php
					echo JText::_( 'PRODUCT' );
				?></th>
<?php }
	if($this->config->get('show_code')) { $columns++; ?>
				<th class="hikashop_product_code title hikashop_variants_table_th"><?php
					echo JText::_( 'PRODUCT_CODE' );
				?></th>
<?php }
	foreach($this->element->main->characteristics as $characteristic) { $columns++; ?>
				<th class="hikashop_product_characteristic hikashop_product_characteristic_<?php echo $characteristic->characteristic_id; ?> title hikashop_variants_table_th"><?php
					echo hikashop_translate($characteristic->characteristic_value);
				?></th>
<?php }

	if(@$this->displayVariants['product_description']) { $columns++; ?>
				<th class="hikashop_product_description title hikashop_variants_table_th"><?php
					echo JText::_( 'HIKA_DESCRIPTION' );
				?></th>
<?php }
	if($this->params->get('show_price','-1') == '-1') {
		$this->params->set('show_price', $this->config->get('show_price'));
	}
	if($this->params->get('show_price') && @$this->displayVariants['prices']) { $columns++; ?>
				<th class="hikashop_product_price title hikashop_variants_table_th"><?php
					echo JText::_('PRICE');
				?></th>
<?php }
	if(!$this->params->get('catalogue')){ $columns++; ?>
				<th class="hikashop_product_add_to_cart title hikashop_variants_table_th">
				</th>
<?php } ?>
			</tr>
		</thead>
		<tbody class="hikashop_variants_table_tbody">
<?php
	$productClass = hikashop_get('class.product');
	$productClass->generateVariantData($this->element);

	foreach($this->element->variants as $variant) {
		if(isset($variant->map))
			continue;
		if(!$this->config->get('show_out_of_stock', 1) && $variant->product_quantity == 0)
			continue;
		if(!$variant->product_published)
			continue;

		$this->row =& $variant;
?>
			<tr id="hikashop_variant_row_<?php echo $variant->product_id; ?>" class="hikashop_variant_row hikashop_variants_table_tbody_tr">
<?php 	if($this->config->get('thumbnail') && @$this->displayVariants['images']){ ?>
				<td class="hikashop_product_image_row hikashop_variants_table_td" data-label="<?php echo JText::_( 'HIKA_IMAGE' ); ?>">
<?php
			if (!empty ($variant->images)) {
				$image = reset($variant->images);
				$width = $this->config->get('thumbnail_x');
				$height = $this->config->get('thumbnail_y');
				$this->image->checkSize($width,$height,$image);
				foreach($variant->images as $image) {
?>
					<div class="hikashop_variants_table_image_thumb"><?php
					if($this->image->override) {
						echo $this->image->display(@$image->file_path, true, @$image->file_name, 'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"','', $width, $height);
					} else {
						if(empty($this->popup))
							$this->popup = hikashop_get('helper.popup');
						$image_options = array('default' => true,'forcesize'=>$this->config->get('image_force_size',true),'scale'=>$this->config->get('image_scale_mode','inside'));
						$img = $this->image->getThumbnail(@$image->file_path, array('width' => $width, 'height' => $height), $image_options);
						if(@$img->success) {
							$attributes = 'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"';
							if($img->external && $img->req_width && $img->req_height)
								$attributes .= ' width="'.$img->req_width.'" height="'.$img->req_height.'"';
							$html = '<img '.$attributes.' title="'.$this->escape((string)@$image->file_description).'" alt="'.$this->escape((string)@$image->file_name).'" src="'.$img->url.'"/>';
							if($this->config->get('add_webp_images', 1) && function_exists('imagewebp') && !empty($img->webpurl)) {
								$html = '
								<picture>
									<source srcset="'.$img->webpurl.'" type="image/webp">
									<source srcset="'.$img->url.'" type="image/'.$img->ext.'">
									'.$html.'
								</picture>
								';
							}

							echo $this->popup->image($html, $img->origin_url, null, 'title="'.$this->escape((string)@$image->file_description).'"');
						}
					}
					?></div>
<?php			}
			}
?>
				</td>
<?php	}
		if(@$this->displayVariants['variant_name']){ ?>
				<td class="hikashop_product_name_row hikashop_variants_table_td" data-label="<?php echo JText::_( 'PRODUCT' ); ?>">
					<?php echo $variant->variant_name; ?>
				</td>
<?php	}
		if ($this->config->get('show_code')) {
?>
				<td class="hikashop_product_code_row hikashop_variants_table_td" data-label="<?php echo JText::_( 'PRODUCT_CODE' ); ?>"><?php
					echo $variant->product_code;
				?></td>
<?php	}

		foreach($this->element->main->characteristics as $characteristic) {
?>
				<td class="hikashop_product_characteristic_row hikashop_product_characteristic_<?php echo $characteristic->characteristic_id; ?>_row hikashop_variants_table_td" data-label="<?php echo $characteristic->characteristic_value; ?>">
<?php
			if(!empty($characteristic->values)) {
				foreach($characteristic->values as $k => $value) {
					foreach($variant->characteristics as $variantCharacteristic) {
						if($variantCharacteristic->characteristic_id == $value->characteristic_id) {
							echo hikashop_translate($variantCharacteristic->characteristic_value);
							break 2;
						}
					}
				}
			}
?>
				</td>
<?php 	}

		if(@$this->displayVariants['product_description']) {
?>
				<td class="hikashop_product_description_row hikashop_variants_table_td" data-label="<?php echo JText::_( 'HIKA_DESCRIPTION' ); ?>"><?php
					echo JHTML::_('content.prepare', preg_replace('#<hr *id="system-readmore" */>#i', '', $variant->product_description));
				?></td>
<?php 	}

		if($this->params->get('show_price') && @$this->displayVariants['prices']){
?>
				<td class="hikashop_product_price_row hikashop_variants_table_td" data-label="<?php echo JText::_( 'PRICE' ); ?>">
<?php
			if ( ($this->row->product_msrp) == ($this->element->main->product_msrp) )
				$this->params->set('from_module',1);

			$this->setLayout('listing_price');
			echo $this->loadTemplate();
			$this->params->set('from_module',0);
?>
				</td>
<?php	}
		if(!$this->params->get('catalogue')) {
?>
				<td class="hikashop_product_add_to_cart_row hikashop_variants_table_td">
<?php
			if ($this->config->get('show_quantity_field') < 2) {
				$this->params->set('main_div_name','variants');
				$this->params->set('extra_div_name','hikashop_product_form');
				$this->params->set('product_waitlist', $this->config->get('product_waitlist', 0));
	 			$this->setLayout('add_to_cart_ajax');
				echo $this->loadTemplate();
				$this->params->set('extra_div_name','');
			} else {
				$start_date = (@$this->row->product_sale_start || empty($this->element->main)) ? @$this->row->product_sale_start : $this->element->main->product_sale_start;
				$end_date = (@$this->row->product_sale_end || empty($this->element->main)) ? @$this->row->product_sale_end : $this->element->main->product_sale_end;
				$now = time();
				if($end_date > 0 && $end_date < $now) {
				?>
					<span class="hikashop_product_sale_end"><?php
					echo JText::_('ITEM_NOT_SOLD_ANYMORE');
					?></span>
				<?php
				}

				else if($start_date > 0 && $start_date > $now) {
				?>
					<span class="hikashop_product_sale_start"><?php
					echo JText::sprintf('ITEM_SOLD_ON_DATE', hikashop_getDate($start_date, $this->params->get('date_format', '%d %B %Y')));
					?></span>
				<?php
				}
				else {
?>
					<span class="hikashop_product_stock_count">
<?php
					if($this->row->product_quantity > 0)
						echo (($this->row->product_quantity == 1 && JText::_('X_ITEM_IN_STOCK') != 'X_ITEM_IN_STOCK') ? JText::sprintf('X_ITEM_IN_STOCK', $this->row->product_quantity) : JText::sprintf('X_ITEMS_IN_STOCK', $this->row->product_quantity));
					elseif($this->row->product_quantity == 0)
						echo JText::_('NO_STOCK');
?>
					</span>
<?php
					if($this->row->product_quantity == -1 || $this->row->product_quantity > 0) {
						$quantityLayout = $this->quantityLayout;
						if(!empty($this->row->product_quantity_layout) && $this->row->product_quantity_layout != 'inherit')
							$quantityLayout = $this->row->product_quantity_layout;
						if(empty($quantityLayout) || !in_array($quantityLayout, array( 'show_select', 'show_select_price'))) {
?>
					<input id="hikashop_listing_quantity_<?php echo $this->row->product_id;?>" type="text" style="width:40px;" name="data[<?php echo $this->row->product_id;?>]" class="hikashop_listing_quantity_field" value="0" />
<?php 				} else {
							$min_quantity = ($this->row->product_min_per_order || empty($this->element->main)) ? $this->row->product_min_per_order : $this->element->main->product_min_per_order;
							$max_quantity = ($this->row->product_max_per_order || empty($this->element->main)) ? $this->row->product_max_per_order : $this->element->main->product_max_per_order;
							$min_quantity = max((int)$min_quantity, 1);
							$max_quantity = max((int)$max_quantity, 0);
							if($max_quantity == 0)
								$max_quantity = $min_quantity * $this->config->get('quantity_select_max_default_value', 15);
							$values = array();
							if($quantityLayout == 'show_select' || empty($this->row->prices)) {
								$values = range($min_quantity, $max_quantity, $min_quantity);
							} else {
								foreach($this->row->prices as $price) {
									$price_min_qty = max((int)$price->price_min_quantity, $min_quantity);
									$values[$price_min_qty] = $price_min_qty;
								}
							}
?>
					<select id="hikashop_listing_quantity_select_<?php echo $this->row->product_id;?>" class="tochosen" onchange="var qty_field = document.getElementById('hikashop_listing_quantity_<?php echo $this->row->product_id;?>'); qty_field.value = this.value;">
<?php
							echo '<option value="0" selected="selected">0</option>';
							foreach($values as $j) {
								echo '<option value="'.$j.'">'.$j.'</option>';
							}
?>
					</select>
					<input id="hikashop_listing_quantity_<?php echo $this->row->product_id;?>" type="hidden" name="data[<?php echo $this->row->product_id;?>]" value="0" />
<?php
						}
					}
				}
			}
?>
				</td>
<?php
		}
?>
			</tr>
<?php
	}
?>
		</tbody>
	</table>
<?php
	if($this->config->get('show_quantity_field') >= 2) {
		$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form_variants\')){ return hikashopModifyQuantity(\'\',field,1,\'hikashop_product_form_variants\'); } return false;';
		$this->row = new stdClass();
		$this->row->prices = array($this->row);
		$this->row->product_quantity = -1;
		$this->row->product_min_per_order = 0;
		$this->row->product_max_per_order = -1;
		$this->row->product_sale_start = 0;
		$this->row->product_sale_end = 0;
		$this->row->formName = 'hikashop_product_form_variants';
		$this->row->prices = array('filler');
		$this->params->set('show_quantity_field', 2);
		$this->setLayout('quantity');
		echo $this->loadTemplate();

		if(!empty($this->ajax) && $this->config->get('redirect_url_after_add_cart','stay_if_cart') == 'ask_user') {
?>
		<input type="hidden" name="popup" value="1"/>
<?php
 		}
?>
		<input type="hidden" name="hikashop_cart_type_0" id="hikashop_cart_type_0" value="cart"/>
		<input type="hidden" name="add" value="1"/>
		<input type="hidden" name="ctrl" value="product"/>
		<input type="hidden" name="task" value="updatecart"/>
		<input type="hidden" name="return_url" value="<?php echo urlencode(base64_encode(urldecode($this->redirect_url)));?>"/>
	</form>
<?php
	}
}
?></div>

Thank you

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

  • Posts: 4540
  • Thank you received: 612
  • MODERATOR
7 months 5 days ago #355414

Hello,

Another possible root issue is that you use an override that which derives from a view that is too old (here 4.6.2) which can no longer work with the new other views of your HikaShop 5.0.0.

In this kind of case, you have to saved on your side your current override view and removed it from your website, and process some tests.
If that solve your current issue, you have to recreate your override from your recent HikaShop version.
Hope this will help you

Regards

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 5 days ago #355450

Hi!

No i have no overrides for this view file.

Thank you

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 4 days ago #355464

Hi,

Could it be that you have some caching you need to clear to see the change ?
Or it could be that you have a file templates/YOUR_TEMPLATE/html/hikashop_characteristics.php
which overrides the characteristics display system.

If you don't see what it could be, we'll need a backend access to check on the situation.

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

  • Posts: 1028
  • Thank you received: 11
  • Hikashop Business
7 months 4 days ago #355469

Hi,

There is no override no,
I checked from other browsers, it's the same.
I will send you backend access OK.

Thank you!

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

  • Posts: 81591
  • Thank you received: 13079
  • MODERATOR
7 months 3 days ago #355533

Hi,

I was able to confirm that you had not done the modification in product / show_block_characteristic.
In your FTP, you have two websites /public_html/ and /public_html/joomla4/
You had made the modification in /public_html/ but the URL of your website points to /public_html/joomla4/ and you had made the modification to /public_html/ only, and that's why I couldn't see any changes on your website.
I actually spent 20 minutes trying to understand what was going on before finding the joomla4 subfolder.

Anyways, after adding the modification I could see there were still some problems in some cases. So I've adapted a bit the code to this version which seems to work fine:

window.hikashop.ready( function() {
	// register the default values on the charactersitics
	var elements = document.querySelectorAll('[data-characteristic]');
	if(elements && elements.length >= 1) {
		for (index = 0; index < elements.length; ++index) {
			elements[index].dataset.default = elements[index].selectedIndex;
		}
	}
	elements = document.querySelector('[data-characrow] input');
	if(elements && elements.length >= 1) {
		for (index = 0; index < elements.length; ++index) {
			if(elements[index].checked)
				elements[index].dataset.defaultchecked = true;
			else
				elements[index].dataset.defaultchecked = false;
		}
	}
	// reset the dropdowns and checkboxes when the page changes
	window.addEventListener('beforeunload', (event) => {
		var elements = document.querySelectorAll('[data-characteristic]');
		if(elements && elements.length >= 1) {
			for (index = 0; index < elements.length; ++index) {
				if(elements[index].tagName.toLowerCase() == 'select') {
					elements[index].selectedIndex = elements[index].dataset.default;
				}
			}
		}
		elements = document.querySelector('[data-characrow] input');
		if(elements && elements.length >= 1) {
			for (index = 0; index < elements.length; ++index) {
				elements[index].checked = elements[index].dataset.defaultchecked;
			}
		}
	});
<?php if(($characteristics_dynamic_display && $count > 1) || $characteristics_dynamic_display > 1) { ?>
	initVariants();
<?php } ?>
});
We're going to include it on our end too.

The following user(s) said Thank You: verzevoul

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

Time to create page: 0.101 seconds
Powered by Kunena Forum