characteristics);
$list = '[\''.implode('\',\'',$ids).'\']';
$js = '
function hikashopUpdateVariant(obj) {
var options = '.$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);
}
if(typeof this.window[\'hikashopRefreshOptionPrice\'] == \'function\') hikashopRefreshOptionPrice();
if(window.Oby && window.Oby.fireAjax) window.Oby.fireAjax("hkContentChanged", {selection:selection});
return true;
}
';
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
}
public function displayFE(&$element,$params){
if(empty($element->main->characteristics))
return '';
$this->characteristics=&$element->main->characteristics;
foreach($this->characteristics as $k => $characteristic) {
if(empty($this->characteristics[$k]->characteristic_display_method)) {
$this->characteristics[$k]->characteristic_display_method = $params->get('characteristic_display');
}
}
$this->load();
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$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')) {
$html = hikashop_characteristics_html($element,$params,$this);
}
}
$extra_html = '
';
if(!empty($html))
return $html . $extra_html;
switch($params->get('characteristic_display')){
case 'table':
if(count($this->characteristics) == 2) {
$html = '';
$firstCharacteristic = reset($this->characteristics);
$secondCharacteristic = end($this->characteristics);
$html.= '
';
if($params->get('characteristic_display_text')) {
$space = '';
for($i = 0; $i <= $size; $i++) {
$space .= ' ';
}
$html = ' | '.$space.@$secondCharacteristic->characteristic_value.' |
'.$firstCharacteristic->characteristic_value.' | '.$html.' |
';
}
break;
}
default:
case 'radio':
case 'dropdown':
$main_html = '';
$config =& hikashop_config();
foreach($this->characteristics as $characteristic) {
$main_html.='';
$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($element->variants as $variant){
foreach($variant->characteristics as $variantCharacteristic){
if($variantCharacteristic->characteristic_id==$value->characteristic_id){
$values[$k] = $variant->product_name;
if($variant->product_quantity != 0){
$hasQuantity = true;
}elseif( $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."});";
$doc->addScriptDeclaration("\n\n");
$switch_done = true;
}
}
}
}
if(!$hasQuantity)
continue;
}
}
}
$html = $this->display(@$characteristic->characteristic_id, @$characteristic->default->characteristic_id, $values, $characteristic->characteristic_display_method);
if($params->get('characteristic_display_text') && isset($characteristic->characteristic_value)) {
$html = $characteristic->characteristic_value.''.$html;
}
$main_html .= ' | '.$html.' |
';
}
$main_html .= '
';
$html = $main_html;
break;
}
return $html . $extra_html;
}
public function display($map, $value, $values, $characteristic_display = 'dropdown') {
if(empty($values) || !is_array($values)){
return JText::_('NO_VALUES_FOUND');
}
if(is_array($this->characteristics)){
$characteristic_id = $map;
$map = 'hikashop_product_characteristic['.$characteristic_id.']';
$id = 'hikashop_product_characteristic_'.$characteristic_id;
}else{
$id = $characteristic_id = $map;
}
$this->values = array();
foreach($values as $key => $val){
if(strlen($val)!=0 && empty($val)){
$val = $val.' ';
}
if(strpos($val, '
values[] = JHTML::_('select.option', $key,( $characteristic_display!='radio' && count(strip_tags($val)) ? strip_tags($val) : $val ));
}
$type = 'onclick';
if($characteristic_display!='radio'){
$characteristic_display='generic';
$type = 'onchange';
}
$options = ' '.$type.'="return hikashopUpdateVariant(this);"';
$html = JHTML::_('select.'.$characteristic_display.'list', $this->values, $map, 'class="inputbox" size="1"' . $options, 'value', 'text', (int)$value,$id );
return $html;
}
}