/** * Formating front display by roles * for product only ! */ public function displayProductCustomfieldFE(&$product, $customfield, $row = '') { $virtuemart_custom_id = isset($customfield->virtuemart_custom_id) ? $customfield->virtuemart_custom_id : 0; $value = $customfield->custom_value; $type = $customfield->field_type; $is_list = isset($customfield->is_list) ? $customfield->is_list : 0; $price = isset($customfield->custom_price) ? $customfield->custom_price : 0; $is_cart = isset($customfield->is_cart) ? $customfield->is_cart : 0; //vmdebug('displayProductCustomfieldFE and here is something wrong ',$customfield); JLoader::register('CurrencyDisplay', JPATH_VM_ADMINISTRATOR . '/helpers/currencydisplay.php'); $currency = CurrencyDisplay::getInstance(); if ($is_list > 0) { $values = explode(';', $value); if ($is_cart != 0) { $options = array(); foreach ($values as $key => $val) { $options[] = array('value' => $val, 'text' => $val); } // J3 use chosen vmJsApi::chosenDropDowns(); return JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', NULL, 'value', 'text', FALSE, TRUE); } else { $html = ''; $html .= '<div id="custom_' . $virtuemart_custom_id . '_' . $value . '" >' . $value . '</div>'; return $html; } } else { if ($price > 0) { $price = $currency->priceDisplay((double) $price); } switch ($type) { case 'A': $options = array(); $session = JFactory::getSession(); $virtuemart_category_id = $session->get('vmlastvisitedcategoryid', 0, 'vm'); $productModel = VmModel::getModel('product'); //parseCustomParams VirtueMartModelCustomfields::bindParameterableByFieldType($customfield); //Todo preselection as dropdown of children //Note by Max Milbers: This is not necessary, in this case it is better to unpublish the parent and to give the child which should be preselected a category //Or it is withParent, in that case there exists the case, that a parent should be used as a kind of mini category and not be orderable. //There exists already other customs and in special plugins which wanna disable or change the add to cart button. //I suggest that we manipulate the button with a message "choose a variant first" //if(!isset($customfield->pre_selected)) $customfield->pre_selected = 0; $selected = JRequest::getVar('virtuemart_product_id', 0); if (is_array($selected)) { $selected = $selected[0]; } $selected = (int) $selected; $html = ''; $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent); if (empty($uncatChildren)) { return $html; break; } foreach ($uncatChildren as $k => $child) { $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $child['virtuemart_product_id']), 'text' => $child['product_name']); } $html .= JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="inputbox"', "value", "text", JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected, 'cf' . $row . '-' . $selected)); //vmdebug('$customfield',$customfield); if ($customfield->parentOrderable == 0 and $product->product_parent_id == 0) { $product->orderable = FALSE; } return $html; break; /* variants*/ /* variants*/ case 'V': if ($price == 0) { $price = JText::_('COM_VIRTUEMART_CART_PRICE_FREE'); } /* Loads the product price details */ return '<input type="text" value="' . JText::_($value) . '" name="field[' . $row . '][custom_value]" /> ' . JText::_('COM_VIRTUEMART_CART_PRICE') . $price . ' '; break; /*Date variant*/ /*Date variant*/ case 'D': return '<span class="product_custom_date">' . vmJsApi::date($value, 'LC1', TRUE) . '</span>'; //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput; break; /* text area or editor No JText, only displayed in BE */ /* text area or editor No JText, only displayed in BE */ case 'X': case 'Y': return $value; break; /* string or integer */ /* string or integer */ case 'S': case 'I': return JText::_($value); break; /* bool */ /* bool */ case 'B': if ($value == 0) { return JText::_('COM_VIRTUEMART_NO'); } return JText::_('COM_VIRTUEMART_YES'); break; /* parent */ /* parent */ case 'P': return '<span class="product_custom_parent">' . JText::_($value) . '</span>'; break; /* product kit(bundle) */ /* product kit(bundle) */ case 'K': $pModel = VmModel::getModel('product'); $related = $pModel->getProduct((int) $value, TRUE, TRUE, TRUE, 1, FALSE); if (!$related) { vmError('related product is missing, maybe unpublished'); return false; } $param = json_decode($customfield->custom_param); if (empty($param->is_hidden)) { $thumb = ''; if (!empty($related->virtuemart_media_id[0])) { $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0]) . ' '; } else { $thumb = $this->displayCustomMedia(0) . ' '; } return '<span class="span2">' . $thumb . '</span> <span class="span8">' . $related->product_name . '</span></span> <input type="hidden" name="virtuemart_product_id[]" value="' . $related->virtuemart_product_id . '"/> <input type="text" class="quantity-input span2" name="quantity[]" value="1"/> '; } else { return '<input type="hidden" name="virtuemart_product_id[]" value="' . $related->virtuemart_product_id . '"/> <input type="hidden" class="quantity-input" name="quantity[]" value="1"/>'; } break; /* related */ /* related */ case 'R': $pModel = VmModel::getModel('product'); $related = $pModel->getProduct((int) $value, TRUE, TRUE, TRUE, 1, FALSE); if (!$related) { vmError('related product is missing, maybe unpublished'); return false; } $thumb = ''; if (!empty($related->virtuemart_media_id[0])) { $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0]) . ' '; } else { $thumb = $this->displayCustomMedia(0) . ' '; } return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $related->virtuemart_product_id . '&virtuemart_category_id=' . $related->virtuemart_category_id, FALSE), $thumb . $related->product_name, array('title' => $related->product_name)); break; /* image */ /* image */ case 'M': return $this->displayCustomMedia($value); break; /* categorie */ /* categorie */ case 'Z': $q = 'SELECT * FROM `#__virtuemart_categories_' . VMLANG . '` as l JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $value . '" '; $this->_db->setQuery($q); if ($category = $this->_db->loadObject()) { $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" '; $this->_db->setQuery($q); $thumb = ''; if ($media_id = $this->_db->loadResult()) { $thumb = $this->displayCustomMedia($media_id, 'category'); } return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id, 'cf' . $row . '-' . (int) $value), $thumb . ' ' . $category->category_name, array('title' => $category->category_name)); } else { return ''; } /* Child Group list * this have no direct display , used for stockable product */ /* Child Group list * this have no direct display , used for stockable product */ case 'G': return ''; //'<input type="text" value="'.JText::_($value).'" name="field['.$row.'][custom_value]" /> '.JText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' '; break; break; } } }
/** * Formating front display by roles * for product only ! */ public function displayProductCustomfieldFE(&$product, $customfield, $row = '') { $virtuemart_custom_id = isset($customfield->virtuemart_custom_id) ? $customfield->virtuemart_custom_id : 0; $value = $customfield->custom_value; $type = $customfield->field_type; $is_list = isset($customfield->is_list) ? $customfield->is_list : 0; $price = isset($customfield->custom_price) ? $customfield->custom_price : 0; $is_cart = isset($customfield->is_cart) ? $customfield->is_cart : 0; //vmdebug('displayProductCustomfieldFE and here is something wrong ',$customfield); if (!class_exists('CurrencyDisplay')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'; } $currency = CurrencyDisplay::getInstance(); if ($is_list > 0) { $values = explode(';', $value); if ($is_cart != 0) { $options = array(); foreach ($values as $key => $val) { $options[] = array('value' => $val, 'text' => $val); } vmdebug('displayProductCustomfieldFE is a list ', $options); return JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', NULL, 'value', 'text', FALSE, TRUE); } else { $html = ''; // if($type=='M'){ // foreach ($values as $key => $val){ // $html .= '<div id="custom_'.$virtuemart_custom_id.'_'.$val.'" >'.$this->displayCustomMedia($val).'</div>'; // } // } else { // foreach ($values as $key => $val){ $html .= '<div id="custom_' . $virtuemart_custom_id . '_' . $value . '" >' . $value . '</div>'; // } // } return $html; } } else { if ($price > 0) { $price = $currency->priceDisplay((double) $price); } switch ($type) { case 'A': $options = array(); $session = JFactory::getSession(); $virtuemart_category_id = $session->get('vmlastvisitedcategoryid', 0, 'vm'); $productModel = VmModel::getModel('product'); //parseCustomParams VirtueMartModelCustomfields::bindParameterableByFieldType($customfield); //Todo preselection as dropdown of children //Note by Max Milbers: This is not necessary, in this case it is better to unpublish the parent and to give the child which should be preselected a category //Or it is withParent, in that case there exists the case, that a parent should be used as a kind of mini category and not be orderable. //There exists already other customs and in special plugins which wanna disable or change the add to cart button. //I suggest that we manipulate the button with a message "choose a variant first" //if(!isset($customfield->pre_selected)) $customfield->pre_selected = 0; $selected = JRequest::getInt('virtuemart_product_id', 0); $html = ''; $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent); foreach ($uncatChildren as $k => $child) { $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $child['virtuemart_product_id']), 'text' => $child['product_name']); } $html .= JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="inputbox"', "value", "text", JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected)); //vmdebug('$customfield',$customfield); if ($customfield->parentOrderable == 0 and $product->product_parent_id == 0) { vmdebug('Should not be orderable'); $product->orderable = FALSE; /* if(!$productModel->product_parent_id){ vmdebug('$customfield parentOrderable'); $document = JFactory::getDocument(); $document->addScriptDeclaration( 'jQuery(document).ready( function($) { addToCartArea = jQuery(".productdetails-view .addtocart-bar"); addToCartBar = addToCartArea.find("input[name$=addtocart]"); addToCartArea.css({ padding: "0px 0px 0px 0px", width: "auto" }).children("span:not(:nth-child(3))").hide() .parent().children("span::nth-child(3)").css({ margin: "0px 0px 0px 0px", width: "auto", float: "left" }); addToCartButtonClassName = addToCartBar.attr("class"); addToCartBar.removeClass(addToCartButtonClassName) .addClass(addToCartButtonClassName + "-disabled") .attr({ disabled: "disabled", value: "'.JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT').'", }); }); '); }*/ } return $html; break; /* variants*/ /* variants*/ case 'V': if ($price == 0) { $price = JText::_('COM_VIRTUEMART_CART_PRICE_FREE'); } /* Loads the product price details */ return '<input type="text" value="' . JText::_($value) . '" name="field[' . $row . '][custom_value]" /> ' . JText::_('COM_VIRTUEMART_CART_PRICE') . $price . ' '; break; /*Date variant*/ /*Date variant*/ case 'D': return '<span class="product_custom_date">' . vmJsApi::date($value, 'LC1', TRUE) . '</span>'; //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput; break; /* text area or editor No JText, only displayed in BE */ /* text area or editor No JText, only displayed in BE */ case 'X': case 'Y': return $value; break; /* string or integer */ /* string or integer */ case 'S': case 'I': return JText::_($value); break; /* bool */ /* bool */ case 'B': if ($value == 0) { return JText::_('COM_VIRTUEMART_NO'); } return JText::_('COM_VIRTUEMART_YES'); break; /* parent */ /* parent */ case 'P': return '<span class="product_custom_parent">' . JText::_($value) . '</span>'; break; /* related */ /* related */ case 'R': $q = 'SELECT l.`product_name`, p.`product_parent_id` , l.`product_name`, x.`virtuemart_category_id` FROM `#__virtuemart_products_' . VMLANG . '` as l JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`) LEFT JOIN `#__virtuemart_product_categories` as x on x.`virtuemart_product_id` = p.`virtuemart_product_id` WHERE p.`published`=1 AND p.`virtuemart_product_id`= "' . (int) $value . '" '; $this->_db->setQuery($q); $related = $this->_db->loadObject(); if (empty($related)) { return ''; } $thumb = ''; $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_product_medias`WHERE `virtuemart_product_id`= "' . (int) $value . '" AND (`ordering` = 0 OR `ordering` = 1)'; $this->_db->setQuery($q); if ($media_id = $this->_db->loadResult()) { $thumb = $this->displayCustomMedia($media_id); return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $value . '&virtuemart_category_id=' . $related->virtuemart_category_id), $thumb . ' ' . $related->product_name, array('title' => $related->product_name)); } break; /* image */ /* image */ case 'M': return $this->displayCustomMedia($value); break; /* categorie */ /* categorie */ case 'Z': $q = 'SELECT * FROM `#__virtuemart_categories_' . VMLANG . '` as l JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $value . '" '; $this->_db->setQuery($q); if ($category = $this->_db->loadObject()) { $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" '; $this->_db->setQuery($q); $thumb = ''; if ($media_id = $this->_db->loadResult()) { $thumb = $this->displayCustomMedia($media_id); } return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id), $thumb . ' ' . $category->category_name, array('title' => $category->category_name)); } else { return ''; } /* Child Group list * this have no direct display , used for stockable product */ /* Child Group list * this have no direct display , used for stockable product */ case 'G': return ''; //'<input type="text" value="'.JText::_($value).'" name="field['.$row.'][custom_value]" /> '.JText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' '; break; break; } } }