Characteristics override question

  • Posts: 1119
  • Thank you received: 114
5 years 1 month ago #312081

Hi,

I have successfully done characteristics override as per documentation. However i have 1 concern regarding the code i used. The whole code is based on default characteristics.php file....

So If i use:

}elseif( $element->product_id==$variant->product_id && !$switch_done){

For some reason first variant isn't checked by js:
$js = "var el = document.querySelector('[name=\"".$id."\"]'); if(el) el.checked = true; hikashopUpdateVariant(el);";

If i set first variant quantity to 0 it works fine. Not sure why it does like that? As the whole code is based on default of the hikashop code it should work...

So i have uncommented it as for now....

Here is the full code of the override:
<?php
defined('_JEXEC') or die('Restricted access');

$this->load();

function hikashop_characteristics_html(&$element, &$params, &$obj) {

    $characteristics =& $element->main->characteristics;
    $doc = JFactory::getDocument();
	$config =& hikashop_config();

    switch ($params->get('characteristic_display')) {
        case 'radio':
         
            foreach ($obj->characteristics as $characteristic) { 
                $html .= '<div class="hikashop_characteristic fz-characteristic-' . $characteristic->characteristic_alias . ' my-3">';
				
				if($characteristic->characteristic_alias == 'color') {
					$html .='test'; // Working on it
				}else{
                    $html .= '<h5>' . $characteristic->characteristic_value . ':</h5>';
                    $html .= '<div class="form-check-inline">';
				
				    $switch_done = false;
				    if(!empty($characteristic->values)) {
                        foreach($characteristic->values as $k => $value){
					        if(!$config->get('show_out_of_stock',1)){
						        $hasQuantity = false;
		 			            foreach($element->variants as $variant){
						            foreach($variant->characteristics as $variantCharacteristic) {
							            if($variantCharacteristic->characteristic_id == $value->characteristic_id) {
										    if($variant->product_quantity != 0){
											    $hasQuantity = true;
										      //}elseif( $element->product_id==$variant->product_id && !$switch_done){
											    $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."});";
											    $doc->addScriptDeclaration("\n<!--\n".$js."\n//-->\n");
											    $switch_done = true;
										    }
						                }
					                }
					            }
					            if(!$hasQuantity)
						           continue;
						    }						
						    if(strlen($value)!=0 && empty($value)){
                                $val = $value.'&nbsp;';
                            }
                            if(strpos($val, '<img ') !== false)
                                $val = str_replace('<img ', '<img onclick="return hikashopUpdateVariant(\'hikashop_product_characteristic_'. $key . $value->characteristic_id.'\');" ', $val);
                                $clean = strip_tags($val);
						
                        $html .= '<label for="hikashop_product_characteristic_' . $characteristic->characteristic_id . $value->characteristic_id . '" id="hikashop_product_characteristic_' . $characteristic->characteristic_id . $value->characteristic_id . '-lbl" class="form-check-label">';
                        $html .= '<input '.$extra.' type="radio" name="hikashop_product_characteristic[' . $characteristic->characteristic_id.']" id="hikashop_product_characteristic_' . $characteristic->characteristic_id . $value->characteristic_id . '" value="' . $value->characteristic_id . '" class="form-check-input d-none" size="1" onclick="return hikashopUpdateVariant(this);" />';
					    $html .= '<span>'. $value->characteristic_value.'</span>';
                        $html .= '</label>';
							
			            }
			         } 
                     $html .= '</div>';
				}
                $html .= '</div>';
            }
            break;
    }
    return $html;
}

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

  • Posts: 12953
  • Thank you received: 1778
5 years 1 month ago #312111

Hello,

Can you tell me which Hikashop's version you're actually using as I'm not able to find the code you have changed ? Thank you.

Kind regards,
Mohamed Thelji.

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

  • Posts: 1119
  • Thank you received: 114
5 years 1 month ago #312177

Hi,

We use Hikashop 4.2.2 version and whole code override is based on characteristics.php file "case: radio" as per this docs: www.hikashop.com/support/documentation/6...tation.html#override

As you can see the difference is that we output our own html structure so it is compatible with bootstrap 4.

The question is more about this line of use:

}elseif( $element->product_id==$variant->product_id && !$switch_done){

And why i do have issue while using it.

Thank you

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
5 years 1 month ago #312179

Hi,

Commenting this line is not a problem. What it does is that it adds some javascript code to the page to refresh the default data on the page. If you don't do that, then the data is not refreshed but it should be fine by default.
So you can leave that line commented, it's totally fine.

The following user(s) said Thank You: kyratn

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

Time to create page: 0.082 seconds
Powered by Kunena Forum