Example #1
0
 function getBuildSelectAttributes($attributeValues, $attributeActive, $displayonlyattrtype = null)
 {
     $jshopConfig = JSFactory::getConfig();
     if (!$jshopConfig->admin_show_attributes) {
         return array();
     }
     $dispatcher = JDispatcher::getInstance();
     $attrib = JSFactory::getAllAttributes();
     $userShop = JSFactory::getUserShop();
     $selects = array();
     foreach ($attrib as $k => $v) {
         $attr_id = $v->attr_id;
         if ($displayonlyattrtype) {
             $v->attr_type = $displayonlyattrtype;
         }
         if (isset($attributeValues[$attr_id]) && $attributeValues[$attr_id]) {
             if (isset($attributeActive[$attr_id])) {
                 $_firstval = $attributeActive[$attr_id];
             } else {
                 $_firstval = 0;
             }
             $selects[$attr_id] = new stdClass();
             $selects[$attr_id]->attr_id = $attr_id;
             $selects[$attr_id]->attr_name = $v->name;
             $selects[$attr_id]->attr_description = $v->description;
             $selects[$attr_id]->groupname = $v->groupname;
             $selects[$attr_id]->firstval = $_firstval;
             $options = $attributeValues[$attr_id];
             $attrimage = array();
             foreach ($options as $k2 => $v2) {
                 $attrimage[$v2->val_id] = $v2->image;
                 $addPrice = $v2->addprice;
                 $addPrice = getPriceFromCurrency($addPrice, $this->currency_id);
                 $addPrice = getPriceCalcParamsTax($addPrice, $this->product_tax_id);
                 if ($userShop->percent_discount) {
                     $addPrice = getPriceDiscount($addPrice, $userShop->percent_discount);
                 }
                 $options[$k2]->addprice = $addPrice;
             }
             if ($v->attr_type == 1) {
                 // attribut type select
                 if ($jshopConfig->attr_display_addprice) {
                     foreach ($options as $k2 => $v2) {
                         if (($v2->price_mod == "+" || $v2->price_mod == "-" || $jshopConfig->attr_display_addprice_all_sign) && $v2->addprice > 0) {
                             $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice, null, 0, -1) . ")";
                             $options[$k2]->value_name .= $ext_price_info;
                         }
                     }
                 }
                 if ($jshopConfig->product_attribut_first_value_empty) {
                     $first = array();
                     $first[] = JHTML::_('select.option', '0', _JSHOP_SELECT, 'val_id', 'value_name');
                     $options = array_merge($first, $options);
                 }
                 if (isset($attributeActive[$attr_id]) && isset($attrimage[$attributeActive[$attr_id]])) {
                     $_active_image = $attrimage[$attributeActive[$attr_id]];
                 } else {
                     $_active_image = '';
                 }
                 if (isset($attributeActive[$attr_id])) {
                     $_select_active = $attributeActive[$attr_id];
                 } else {
                     $_select_active = '';
                 }
                 $html_select_attribute_param = 'class="' . $jshopConfig->frontend_attribute_select_class_css . '" size = "' . $jshopConfig->frontend_attribute_select_size . '" onchange="setAttrValue(\'' . $attr_id . '\', this.value);"';
                 $selects[$attr_id]->selects = JHTML::_('select.genericlist', $options, 'jshop_attr_id[' . $attr_id . ']', $html_select_attribute_param, 'val_id', 'value_name', $_select_active) . "<span class='prod_attr_img'>" . $this->getHtmlDisplayProdAttrImg($attr_id, $_active_image) . "</span>";
                 $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects);
             } else {
                 // attribut type radio
                 foreach ($options as $k2 => $v2) {
                     if ($v2->image) {
                         $options[$k2]->value_name = "<img src='" . $jshopConfig->image_attributes_live_path . "/" . $v2->image . "' alt='' /> " . $v2->value_name;
                     }
                 }
                 if ($jshopConfig->attr_display_addprice) {
                     foreach ($options as $k2 => $v2) {
                         if (($v2->price_mod == "+" || $v2->price_mod == "-" || $jshopConfig->attr_display_addprice_all_sign) && $v2->addprice > 0) {
                             $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice) . ")";
                             $options[$k2]->value_name .= $ext_price_info;
                         }
                     }
                 }
                 $radioseparator = '';
                 if ($jshopConfig->radio_attr_value_vertical) {
                     $radioseparator = "<br/>";
                 }
                 foreach ($options as $k2 => $v2) {
                     $options[$k2]->value_name = "<span class='radio_attr_label'>" . $v2->value_name . "</span>";
                 }
                 $selects[$attr_id]->selects = sprintRadioList($options, 'jshop_attr_id[' . $attr_id . ']', 'onclick="setAttrValue(\'' . $attr_id . '\', this.value);"', 'val_id', 'value_name', $attributeActive[$attr_id], $radioseparator);
                 $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects);
             }
             $dispatcher->trigger('onBuildSelectAttribute', array(&$attributeValues, &$attributeActive, &$selects, &$options, &$attr_id, &$v));
         }
     }
     $grname = '';
     foreach ($selects as $k => $v) {
         if ($v->groupname != $grname) {
             $grname = $v->groupname;
             $selects[$k]->grshow = 1;
         } else {
             $selects[$k]->grshow = 0;
         }
     }
     return $selects;
 }
 function getBuildSelectAttributes($attributeValues, $attributeActive)
 {
     $jshopConfig = JSFactory::getConfig();
     if (!$jshopConfig->admin_show_attributes) {
         return array();
     }
     JPluginHelper::importPlugin('jshoppingproducts');
     $dispatcher = JDispatcher::getInstance();
     $attrib = JSFactory::getAllAttributes();
     $selects = array();
     foreach ($attrib as $k => $v) {
         $attr_id = $v->attr_id;
         if (isset($attributeValues[$attr_id]) && $attributeValues[$attr_id]) {
             if (isset($attributeActive[$attr_id])) {
                 $_firstval = $attributeActive[$attr_id];
             } else {
                 $_firstval = 0;
             }
             $selects[$attr_id] = new stdClass();
             $selects[$attr_id]->attr_id = $attr_id;
             $selects[$attr_id]->attr_name = $v->name;
             $selects[$attr_id]->attr_description = $v->description;
             $selects[$attr_id]->firstval = $_firstval;
             $options = $attributeValues[$attr_id];
             $attrimage = array();
             foreach ($options as $k2 => $v2) {
                 $attrimage[$v2->val_id] = $v2->image;
             }
             if ($v->attr_type == 1) {
                 // attribut type select
                 if ($jshopConfig->attr_display_addprice) {
                     foreach ($options as $k2 => $v2) {
                         if (($v2->price_mod == "+" || $v2->price_mod == "-") && $v2->addprice > 0) {
                             $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice, null, 1) . ")";
                             $options[$k2]->value_name .= $ext_price_info;
                         }
                     }
                 }
                 if ($jshopConfig->product_attribut_first_value_empty) {
                     $first = array();
                     $first[] = JHTML::_('select.option', '0', _JSHOP_SELECT, 'val_id', 'value_name');
                     $options = array_merge($first, $options);
                 }
                 if (isset($attributeActive[$attr_id]) && isset($attrimage[$attributeActive[$attr_id]])) {
                     $_active_image = $attrimage[$attributeActive[$attr_id]];
                 } else {
                     $_active_image = '';
                 }
                 if (isset($attributeActive[$attr_id])) {
                     $_select_active = $attributeActive[$attr_id];
                 } else {
                     $_select_active = '';
                 }
                 $selects[$attr_id]->selects = JHTML::_('select.genericlist', $options, 'jshop_attr_id[' . $attr_id . ']', 'class = "inputbox" size = "1" onchange="setAttrValue(\'' . $attr_id . '\', this.value);"', 'val_id', 'value_name', $_select_active) . "<span class='prod_attr_img'>" . $this->getHtmlDisplayProdAttrImg($attr_id, $_active_image) . "</span>";
                 $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects);
             } else {
                 // attribut type radio
                 foreach ($options as $k2 => $v2) {
                     if ($v2->image) {
                         $options[$k2]->value_name = "<img src='" . $jshopConfig->image_attributes_live_path . "/" . $v2->image . "' alt='' /> " . $v2->value_name;
                     }
                 }
                 if ($jshopConfig->attr_display_addprice) {
                     foreach ($options as $k2 => $v2) {
                         if (($v2->price_mod == "+" || $v2->price_mod == "-") && $v2->addprice > 0) {
                             $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice, null, 1) . ")";
                             $options[$k2]->value_name .= $ext_price_info;
                         }
                     }
                 }
                 $radioseparator = '';
                 if ($jshopConfig->radio_attr_value_vertical) {
                     $radioseparator = "<br/>";
                 }
                 foreach ($options as $k2 => $v2) {
                     $options[$k2]->value_name = "<span class='radio_attr_label'>" . $v2->value_name . "</span>";
                 }
                 $selects[$attr_id]->selects = sprintRadioList($options, 'jshop_attr_id[' . $attr_id . ']', 'onclick="setAttrValue(\'' . $attr_id . '\', this.value);"', 'val_id', 'value_name', $attributeActive[$attr_id], $radioseparator);
                 $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects);
             }
             $dispatcher->trigger('onBuildSelectAttribute', array(&$attributeValues, &$attributeActive, &$selects, &$options, &$attr_id, &$v));
         }
     }
     return $selects;
 }