'. $priceInput;
break;
case 'T':
//TODO Patrick
return '
' . $priceInput;
break;
/* string or integer */
case 'S':
case 'I':
return '
' . $priceInput;
break;
//'X'=>'COM_VIRTUEMART_CUSTOM_EDITOR',
case 'X':
// Not sure why this block is needed to get it to work when editing the customfield (the subsequent block works fine when creating it, ie. in JS)
$document=& JFactory::getDocument();
if (get_class($document) == 'JDocumentHTML') {
$editor =& JFactory::getEditor();
return $editor->display('field['.$row.'][custom_value]',$field->custom_value, '550', '400', '60', '20', false).'
';
}
return '
' . $priceInput;
//return '
'.$priceInput;
break;
//'Y'=>'COM_VIRTUEMART_CUSTOM_TEXTAREA'
case 'Y':
return '
';
return $html;
}
}
else {
if ($price > 0) {
$price = $currency->priceDisplay ((float)$price);
}
switch ($type) {
case 'A':
$options = array();
$session = JFactory::getSession ();
$virtuemart_category_id = $session->get ('vmlastvisitedcategoryid', 0, 'vm');
$productModel = VmModel::getModel ('product');
//Note by Jeremy Magne (Daycounts) 2013-08-31
//Previously the the product model is loaded but we need to ensure the correct product id is set because the getUncategorizedChildren does not get the product id as parameter.
//In case the product model was previously loaded, by a related product for example, this would generate wrong uncategorized children list
$productModel->setId($product->virtuemart_product_id);
//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 $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'],FALSE), 'text' => $child['product_name']);
}
//vmJsApi::chosenDropDowns(); would need class="inputbox vm-chzn-select", but it does not work, in case people have two times the same product,
//because both dropdowns have then the same id and the js does not work.
$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,FALSE));
//vmdebug('$customfield',$customfield);
if($customfield->parentOrderable==0 and $product->product_parent_id==0){
$product->orderable = FALSE;
}
return $html;
break;
/* variants*/
case 'V':
if ($price == 0)
$price = vmText::_ ('COM_VIRTUEMART_CART_PRICE_FREE');
/* Loads the product price details */
return ' ' . vmText::_ ('COM_VIRTUEMART_CART_PRICE') . $price . ' ';
break;
/*Date variant*/
case 'D':
return '' . vmJsApi::date ($value, 'LC1', TRUE) . ''; //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput;
break;
/* text area or editor No vmText, only displayed in BE */
case 'X':
case 'Y':
return $value;
break;
/* string or integer */
case 'S':
case 'I':
return vmText::_ ($value);
break;
/* bool */
case 'B':
if ($value == 0)
return vmText::_ ('COM_VIRTUEMART_NO');
return vmText::_ ('COM_VIRTUEMART_YES');
break;
/* parent */
case 'P':
return '' . vmText::_ ($value) . '';
break;
/* 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 '.$product->product_name.' id: '.$product->virtuemart_product_id);
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 */
case 'M':
return $this->displayCustomMedia ($value);
break;
/* 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, FALSE), $thumb . ' ' . $category->category_name, array('title' => $category->category_name));
}
else return '';
/* Child Group list
* this have no direct display , used for stockable product
*/
case 'G':
return ''; //' '.vmText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' ';
break;
break;
}
}
}
function displayCustomMedia ($media_id, $table = 'product', $absUrl = FALSE) {
if (!class_exists ('TableMedias'))
require(JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'medias.php');
//$data = $this->getTable('medias');
$db = JFactory::getDBO ();
$data = new TableMedias($db);
$data->load ((int)$media_id);
if (!class_exists ('VmMediaHandler'))
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'mediahandler.php');
$media = VmMediaHandler::createMedia ($data, $table);
//if($media_id==0){
// return $media->getIcon('', FALSE, TRUE, TRUE,$absUrl);
//}
return $media->displayMediaThumb ('', FALSE, '', TRUE, TRUE, $absUrl);
}
/**
* There are too many functions doing almost the same for my taste
* the results are sometimes slighty different and makes it hard to work with it, therefore here the function for future proxy use
*
*/
public static function customFieldDisplay ($product, $variantmods, $html, $trigger) {
//vmdebug('customFieldDisplay $variantmods',$variantmods);
$row = 0;
if (!class_exists ('shopFunctionsF'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
//MarkerVarMods
foreach ($variantmods as $selected => $variant) {
//foreach ($variantmods as $variant=> $selected) {
//vmdebug('customFieldDisplay '.$variant.' '.$selected);
if ($selected) {
$productCustom = self::getProductCustomField ($selected);
//vmdebug('customFieldDisplay',$selected,$productCustom);
if (!empty($productCustom)) {
$html .= '';
if ($productCustom->field_type == "E") {
$product = self::addParam ($product);
$product->productCustom = $productCustom;
//vmdebug('CustomsFieldCartDisplay $productCustom',$productCustom);
// vmdebug('customFieldDisplay $product->param selected '.$selected,$product->param);
if (!class_exists ('vmCustomPlugin'))
require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
JPluginHelper::importPlugin ('vmcustom');
$dispatcher = JDispatcher::getInstance ();
$dispatcher->trigger ($trigger, array($product, $row, &$html));
}
else {
//vmdebug('customFieldDisplay $productCustom by self::getProductCustomField $variant: '.$variant.' $selected: '.$selected,$productCustom);
$value = '';
if (($productCustom->field_type == "G")) {
$child = self::getChild ($productCustom->custom_value);
// $html .= $productCustom->custom_title.' '.$child->product_name;
$value = $child->product_name;
}
elseif (($productCustom->field_type == "M")) {
// $html .= $productCustom->custom_title.' '.self::displayCustomMedia($productCustom->custom_value);
$value = self::displayCustomMedia ($productCustom->custom_value);
}
elseif (($productCustom->field_type == "S")) {
// q $html .= $productCustom->custom_title.' '.vmText::_($productCustom->custom_value);
$value = $productCustom->custom_value;
}
else {
// $html .= $productCustom->custom_title.' '.$productCustom->custom_value;
//vmdebug('customFieldDisplay',$productCustom);
$value = $productCustom->custom_value;
}
$html .= ShopFunctionsF::translateTwoLangKeys ($productCustom->show_title ? $productCustom->custom_title : '', $value);
}
$html .= ' ';
}
else {
// falldown method if customfield are deleted
foreach ((array)$selected as $key => $value) {
$html .= ' Couldnt find customfield' . ($key ? '' . $key . ' ' : '') . $value;
}
}
}
$row++;
}
// vmdebug ('customFieldDisplay html begin: ' . $html . ' end');
return $html . '
';
}
/**
* TODO This is html and view stuff and MUST NOT be in the model, notice by Max
* render custom fields display cart module FE
*/
public static function CustomsFieldCartModDisplay ($priceKey, $product) {
if (empty($calculator)) {
if (!class_exists ('calculationHelper'))
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
$calculator = calculationHelper::getInstance ();
}
$variantmods = $calculator->parseModifier ($priceKey);
return self::customFieldDisplay ($product, $variantmods, '
', 'plgVmOnViewCartModule');
}
/**
* TODO This is html and view stuff and MUST NOT be in the model, notice by Max
* render custom fields display cart FE
*/
public static function CustomsFieldCartDisplay ($priceKey, $product) {
if (empty($calculator)) {
if (!class_exists ('calculationHelper'))
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
$calculator = calculationHelper::getInstance ();
}
$variantmods = $calculator->parseModifier ($priceKey);
return self::customFieldDisplay ($product, $variantmods, '
', 'plgVmOnViewCart');
}
/*
* render custom fields display order BE/FE
*/
public function CustomsFieldOrderDisplay ($item, $view = 'FE', $absUrl = FALSE) {
$row = 0;
// $item=(array)$item;
if (!empty($item->product_attribute)) {
$item->param = json_decode ($item->product_attribute, TRUE);
// $html = '
';
if (!empty($item->param)) {
return self::customFieldDisplay ($item, $item->param, '
', 'plgVmDisplayInOrder' . $view);
}
else {
vmdebug ('CustomsFieldOrderDisplay $item->param empty? ');
}
}
else {
// vmTrace('$item->product_attribut is empty');
}
return FALSE;
}
/**
*
* custom fields for cart and cart module
*/
public static function getProductCustomField ($selected) {
$db = JFactory::getDBO ();
$query = 'SELECT C.`virtuemart_custom_id` , `custom_element` , `custom_parent_id` , `admin_only` , `custom_title` , `show_title` , `custom_tip` ,
C.`custom_value` AS value, `custom_field_desc` , `field_type` , `is_list` , `is_cart_attribute` , `is_hidden` , C.`published` ,
field.`virtuemart_customfield_id` , field.`custom_value`,field.`custom_param`,field.`custom_price`
FROM `#__virtuemart_customs` AS C
LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
WHERE `virtuemart_customfield_id` ="' . (int)$selected . '"';
// if($product_parent_id!=0){
// $query .= ' AND (`virtuemart_product_id` ="' . $product_id.'" XOR `virtuemart_product_id` ="' . $product_parent_id.'")';
// } else {
// $query .= ' AND (`virtuemart_product_id` ="' . $product_id.'"';
// }
$db->setQuery ($query);
return $db->loadObject ();
}
/*
* add parameter to product definition
*/
public function addParam ($product) {
// vmdebug('addParam? ',$product->custom_param,$product->customPlugin);
$custom_param = empty($product->custom_param) ? array() : json_decode ($product->custom_param, TRUE);
$product_param = empty($product->customPlugin) ? array() : json_decode ($product->customPlugin, TRUE);
$params = (array)$product_param + (array)$custom_param;
foreach ($params as $key => $param) {
$product->param[$key] = $param;
}
return $product;
}
public function getChild ($child) {
$db = JFactory::getDBO ();
$db->setQuery ('SELECT `product_sku`, `product_name` FROM `#__virtuemart_products_' . VMLANG . '` WHERE virtuemart_product_id=' . $child);
return $db->loadObject ();
}
static public function setEditCustomHidden ($customfield, $i) {
if (!isset($customfield->virtuemart_customfield_id))
$customfield->virtuemart_customfield_id = '0';
$html = '
';
return $html;
}
}
// pure php no closing tag