error on characteristic override

  • Posts: 32
  • Thank you received: 2
11 years 2 months ago #91243

Hi All,

I'm trying to produce a characteristic override to show price near the radio button.

I'm not a php expert (and english also :dry: ), but I have already override some view.


On my first step on override I have this error:
Notice: Trying to get property of non-object in .../html/hikashop_characteristics.php on line 7

My code,
where on "PREZZO" (on line #56) I would like insert the unit price:

<?php

function hikashop_characteristics_html(&$element,&$params,&$obj)
{
	switch($params->get('characteristic_display')){
				case 'table':
					if(count($obj->characteristics)==2){
						$html = '';
						$firstCharacteristic = reset($obj->characteristics);
						$secondCharacteristic = end($obj->characteristics);

						$html.= '<table class="hikashop_product_characteristic_chooser"><tr><td></td>';
						if(empty($secondCharacteristic->values)){

						}else{
							foreach($secondCharacteristic->values as $value){
								$html.='<td>'.$value->characteristic_value.'</td>';
							}
						}
						$html.='</tr>';
						$obj->options=' onclick="return hikashopUpdateVariantData(this.value);"';
						$size=0;
						if(!empty($firstCharacteristic->values)){
							foreach($firstCharacteristic->values as $value){
								$html.='<tr><td style="text-align:right">'.$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 = '';
										foreach($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';
													}
													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\" id=\"hikashop_product_characteristic".$name."\" value=\"".$name."\" ".$obj->options;
										if($obj->characteristics[$value->characteristic_parent_id]->default->characteristic_id==$value->characteristic_id && !empty($obj->characteristics[$value2->characteristic_parent_id]->default->characteristic_id) && $obj->characteristics[$value2->characteristic_parent_id]->default->characteristic_id==$value2->characteristic_id){
											$radio.=' checked';
										}
										$radio.=" /></span>";
										$html.='<td>'.$radio.' PREZZO</td>';
									}
								}
								$html.='</tr>';
							}
						}
						$html.='</table>';
						if($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>'.$space.$secondCharacteristic->characteristic_value.'</td></tr><tr><td>'.$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();
					foreach($obj->characteristics as $characteristic){
						$main_html.='<tr>';
						$values = array();
						if(!empty($characteristic->values)){
							foreach($characteristic->values as $k => $value){
								if(!$config->get('show_out_of_stock')){
									$hasQuantity = false;
									foreach($element->variants as $variant){
										foreach($variant->characteristics as $variantCharacteristic){
											if($variantCharacteristic->characteristic_id==$value->characteristic_id){
												if($variant->product_quantity != 0 || $element->product_id==$variant->product_id){
													$hasQuantity = true;
												}
											}
										}
									}
									if(!$hasQuantity) continue;
								}
								$values[$k]=$value->characteristic_value;
							}
						}

						$html=$obj->display($characteristic->characteristic_id,@$characteristic->default->characteristic_id,$values,$params->get('characteristic_display'));
						if($params->get('characteristic_display_text')){
							$html=$characteristic->characteristic_value.'</td><td>'.$html;
						}
						$main_html.='<td>'.$html.'</td></tr>';
					}
					$main_html.='</table>';
					$html = $main_html;
					
				
					break;
					
			}
			
			
			
		}
		

?>

Last edit: 11 years 2 months ago by nibel59. Reason: I tried to change category forum to "how to"

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

  • Posts: 12953
  • Thank you received: 1778
11 years 2 months ago #91325

Hi,

I think that you'll have to add your code through the "show_block_characteristic" or "show_default" file of your product view ("Hikashop->Display->Views").

Hope this will help you.

Last edit: 11 years 2 months ago by Mohamed Thelji.

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

  • Posts: 32
  • Thank you received: 2
11 years 2 months ago #91464

thanks Mohamed,
I'll take a look to those files

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

Time to create page: 0.046 seconds
Powered by Kunena Forum