PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/models/customfields.php

https://github.com/srgg6701/auction-ruseasons
PHP | 1362 lines | 873 code | 186 blank | 303 comment | 138 complexity | 124112e15cb402153586c13769f1c673 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, JSON

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * Description
  5. *
  6. * @package VirtueMart
  7. * @subpackage
  8. * @author Max Milbers
  9. * @link http://www.virtuemart.net
  10. * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved by the author.
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  12. * VirtueMart is free software. This version may have been modified pursuant
  13. * to the GNU General Public License, and as distributed it includes or
  14. * is derivative of works licensed under the GNU General Public License or
  15. * other free or open source software licenses.
  16. * @version $Id:$
  17. */
  18. // Check to ensure this file is included in Joomla!
  19. defined ('_JEXEC') or die('Restricted access');
  20. if (!class_exists ('VmModel')) {
  21. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmmodel.php');
  22. }
  23. /**
  24. * Model for VirtueMart Customs Fields
  25. *
  26. * @package VirtueMart
  27. */
  28. class VirtueMartModelCustomfields extends VmModel {
  29. /**
  30. * constructs a VmModel
  31. * setMainTable defines the maintable of the model
  32. *
  33. * @author Max Milbers
  34. */
  35. // function __construct($modelName ='product') {
  36. function __construct ($modelName = 'product') {
  37. parent::__construct ('virtuemart_customfield_id');
  38. $this->setMainTable ('product_customfields');
  39. }
  40. /**
  41. * Gets a single custom by virtuemart_customfield_id
  42. *
  43. * @param string $type
  44. * @param string $mime mime type of custom, use for exampel image
  45. * @return customobject
  46. */
  47. function getCustomfield () {
  48. $this->data = $this->getTable ('product_customfields');
  49. $this->data->load ($this->_id);
  50. return $this;
  51. }
  52. // **************************************************
  53. // Custom FIELDS
  54. //
  55. function getProductCustomsChilds ($childs) {
  56. $data = array();
  57. foreach ($childs as $child) {
  58. $query = 'SELECT C.* , field.*
  59. FROM `#__virtuemart_product_customfields` AS field
  60. LEFT JOIN `#__virtuemart_customs` AS C ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  61. WHERE `virtuemart_product_id` =' . (int)$child->virtuemart_product_id;
  62. $query .= ' and C.field_type = "C" ';
  63. $this->_db->setQuery ($query);
  64. $child->field = $this->_db->loadObject ();
  65. $customfield = new stdClass();
  66. $customfield->custom_value = $child->virtuemart_product_id;
  67. $customfield->field_type = 'C';
  68. $child->display = $this->displayProductCustomfieldFE ($child, $customfield);
  69. if ($child->field) {
  70. $data[] = $child;
  71. }
  72. }
  73. return $data;
  74. }
  75. public function getCustomParentTitle ($custom_parent_id) {
  76. $q = 'SELECT custom_title FROM `#__virtuemart_customs` WHERE virtuemart_custom_id =' . (int)$custom_parent_id;
  77. $this->_db->setQuery ($q);
  78. return $this->_db->loadResult ();
  79. }
  80. /** @return autorized Types of data **/
  81. function getField_types () {
  82. return array('S' => 'COM_VIRTUEMART_CUSTOM_STRING',
  83. 'I' => 'COM_VIRTUEMART_CUSTOM_INT',
  84. 'P' => 'COM_VIRTUEMART_CUSTOM_PARENT',
  85. 'B' => 'COM_VIRTUEMART_CUSTOM_BOOL',
  86. 'D' => 'COM_VIRTUEMART_DATE',
  87. 'T' => 'COM_VIRTUEMART_TIME',
  88. 'M' => 'COM_VIRTUEMART_IMAGE',
  89. 'V' => 'COM_VIRTUEMART_CUSTOM_CART_VARIANT',
  90. 'A' => 'COM_VIRTUEMART_CHILD_GENERIC_VARIANT',
  91. 'X' => 'COM_VIRTUEMART_CUSTOM_EDITOR',
  92. 'Y' => 'COM_VIRTUEMART_CUSTOM_TEXTAREA',
  93. 'E' => 'COM_VIRTUEMART_CUSTOM_EXTENSION'
  94. );
  95. // 'U'=>'COM_VIRTUEMART_CUSTOM_CART_USER_VARIANT',
  96. // 'C'=>'COM_VIRTUEMART_CUSTOM_PRODUCT_CHILD',
  97. // 'G'=>'COM_VIRTUEMART_CUSTOM_PRODUCT_CHILD_GROUP',
  98. // 'R'=>'COM_VIRTUEMART_RELATED_PRODUCT',
  99. // 'Z'=>'COM_VIRTUEMART_RELATED_CATEGORY',
  100. }
  101. static function setParameterableByFieldType(&$table,$type=0){
  102. if($type===0) $type = $table->field_type;
  103. $varsToPush = self::getVarsToPush($type);
  104. if(!empty($varsToPush)){
  105. $table->setParameterable('custom_param',$varsToPush,TRUE);
  106. }
  107. }
  108. static function bindParameterableByFieldType(&$table,$type=0){
  109. if($type===0) $type = $table->field_type;
  110. $varsToPush = self::getVarsToPush($type);
  111. if(!empty($varsToPush)){
  112. VmTable::bindParameterable($table,'custom_param',$varsToPush);
  113. }
  114. }
  115. static function getVarsToPush($type){
  116. $varsToPush = 0;
  117. if($type=='A'){
  118. $varsToPush = array(
  119. 'withParent' => array(0, 'int'),
  120. 'parentOrderable' => array(0, 'int')
  121. );
  122. }
  123. return $varsToPush;
  124. }
  125. private $_hidden = array();
  126. /**
  127. * Use this to adjust the hidden fields of the displaycustomHandler to your form
  128. *
  129. * @author Max Milbers
  130. * @param string $name for exampel view
  131. * @param string $value for exampel custom
  132. */
  133. public function addHidden ($name, $value = '') {
  134. $this->_hidden[$name] = $value;
  135. }
  136. /**
  137. * Adds the hidden fields which are needed for the form in every case
  138. *
  139. * @author Max Milbers
  140. * OBSELTE ?
  141. */
  142. private function addHiddenByType ($datas) {
  143. $this->addHidden ('virtuemart_custom_id', $datas->virtuemart_custom_id);
  144. $this->addHidden ('option', 'com_virtuemart');
  145. }
  146. /**
  147. * Displays a possibility to select created custom
  148. *
  149. * @author Max Milbers
  150. * @author Patrick Kohl
  151. */
  152. public function displayCustomSelection () {
  153. $customslist = $this->getCustomsList ();
  154. if (isset($this->virtuemart_custom_id)) {
  155. $value = $this->virtuemart_custom_id;
  156. }
  157. else {
  158. $value = JRequest::getInt ('custom_parent_id', 0);
  159. }
  160. return VmHTML::row ('select', 'COM_VIRTUEMART_CUSTOM_PARENT', 'custom_parent_id', $customslist, $value);
  161. }
  162. /**
  163. * Retrieve a list of layouts from the default and chosen templates directory.
  164. *
  165. * We may use here the getCustoms function of the custom model or write something simular
  166. *
  167. * @author Max Milbers
  168. * @param name of the view
  169. * @return object List of flypage objects
  170. */
  171. function getCustomsList ($publishedOnly = FALSE) {
  172. $vendorId = 1;
  173. // get custom parents
  174. $q = 'SELECT virtuemart_custom_id as value ,custom_title as text FROM `#__virtuemart_customs` where custom_parent_id=0
  175. AND field_type <> "R" AND field_type <> "Z" ';
  176. if ($publishedOnly) {
  177. $q .= 'AND `published`=1';
  178. }
  179. if ($ID = JRequest::getInt ('virtuemart_custom_id', 0)) {
  180. $q .= ' and `virtuemart_custom_id`!=' . (int)$ID;
  181. }
  182. //if (isset($this->virtuemart_custom_id)) $q.=' and virtuemart_custom_id !='.$this->virtuemart_custom_id;
  183. $this->_db->setQuery ($q);
  184. // $result = $this->_db->loadAssocList();
  185. $result = $this->_db->loadObjectList ();
  186. $errMsg = $this->_db->getErrorMsg ();
  187. $errs = $this->_db->getErrors ();
  188. if (!empty($errMsg)) {
  189. $app = JFactory::getApplication ();
  190. $errNum = $this->_db->getErrorNum ();
  191. $app->enqueueMessage ('SQL-Error: ' . $errNum . ' ' . $errMsg);
  192. }
  193. if ($errs) {
  194. $app = JFactory::getApplication ();
  195. foreach ($errs as $err) {
  196. $app->enqueueMessage ($err);
  197. }
  198. }
  199. return $result;
  200. }
  201. /**
  202. * This displays a custom handler.
  203. *
  204. * @param string $html atttributes, Just for displaying the fullsized image
  205. */
  206. public function displayCustomFields ($datas) {
  207. $identify = ''; // ':'.$this->virtuemart_custom_id;
  208. if (!class_exists ('VmHTML')) {
  209. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'html.php');
  210. }
  211. if ($datas->field_type) {
  212. $this->addHidden ('field_type', $datas->field_type);
  213. }
  214. $this->addHiddenByType ($datas);
  215. //$html = '<div id="custom_title">'.$datas->custom_title.'</div>';
  216. $html = "";
  217. //$html = ' <table class="admintable"> ';
  218. if (!class_exists ('Permissions')) {
  219. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php');
  220. }
  221. if (!Permissions::getInstance ()->check ('admin')) {
  222. $readonly = 'readonly';
  223. }
  224. else {
  225. $readonly = '';
  226. }
  227. // only input when not set else display
  228. if ($datas->field_type) {
  229. $html .= VmHTML::row ('value', 'COM_VIRTUEMART_CUSTOM_FIELD_TYPE', $datas->field_types[$datas->field_type]);
  230. }
  231. else {
  232. $html .= VmHTML::row ('select', 'COM_VIRTUEMART_CUSTOM_FIELD_TYPE', 'field_type', $this->getOptions ($datas->field_types), $datas->field_type, VmHTML::validate ('R'));
  233. }
  234. $html .= VmHTML::row ('input', 'COM_VIRTUEMART_TITLE', 'custom_title', $datas->custom_title, VmHTML::validate ('S'));
  235. $html .= VmHTML::row ('booleanlist', 'COM_VIRTUEMART_PUBLISHED', 'published', $datas->published);
  236. $html .= VmHTML::row ('select', 'COM_VIRTUEMART_CUSTOM_PARENT', 'custom_parent_id', $this->getParentList ($datas->virtuemart_custom_id), $datas->custom_parent_id, '');
  237. $html .= VmHTML::row ('booleanlist', 'COM_VIRTUEMART_CUSTOM_IS_CART_ATTRIBUTE', 'is_cart_attribute', $datas->is_cart_attribute);
  238. $html .= VmHTML::row ('input', 'COM_VIRTUEMART_DESCRIPTION', 'custom_field_desc', $datas->custom_field_desc);
  239. // change input by type
  240. $html .= VmHTML::row ('input', 'COM_VIRTUEMART_DEFAULT', 'custom_value', $datas->custom_value);
  241. $html .= VmHTML::row ('input', 'COM_VIRTUEMART_CUSTOM_TIP', 'custom_tip', $datas->custom_tip);
  242. $html .= VmHTML::row ('input', 'COM_VIRTUEMART_CUSTOM_LAYOUT_POS', 'layout_pos', $datas->layout_pos);
  243. //$html .= VmHTML::row('booleanlist','COM_VIRTUEMART_CUSTOM_PARENT','custom_parent_id',$this->getCustomsList(), $datas->custom_parent_id,'');
  244. $html .= VmHTML::row ('booleanlist', 'COM_VIRTUEMART_CUSTOM_ADMIN_ONLY', 'admin_only', $datas->admin_only);
  245. $html .= VmHTML::row ('booleanlist', 'COM_VIRTUEMART_CUSTOM_IS_LIST', 'is_list', $datas->is_list);
  246. $html .= VmHTML::row ('booleanlist', 'COM_VIRTUEMART_CUSTOM_IS_HIDDEN', 'is_hidden', $datas->is_hidden);
  247. // $html .= '</table>'; removed
  248. $html .= VmHTML::inputHidden ($this->_hidden);
  249. return $html;
  250. }
  251. /**
  252. * child classes can add their own options and you can get them with this function
  253. *
  254. * @param array $optionsarray
  255. */
  256. private function getOptions ($field_types) {
  257. $options = array();
  258. foreach ($field_types as $optionName=> $langkey) {
  259. $options[] = JHTML::_ ('select.option', $optionName, JText::_ ($langkey));
  260. }
  261. return $options;
  262. }
  263. /**
  264. * Just for creating simpel rows
  265. *
  266. * @author Max Milbers
  267. * @param string $descr
  268. * @param string $name
  269. */
  270. private function displayRow ($descr, $name, $readonly = '') {
  271. $html = '<tr>
  272. <td class="labelcell">' . JText::_ ($descr) . '</td>
  273. <td> <input type="text" ' . $readonly . 'class="inputbox ' . $readonly . '" name="' . $name . '" size="70" value="' . $this->$name . '" /></td>
  274. </tr>';
  275. return $html;
  276. }
  277. /**
  278. *
  279. * Enter description here ...
  280. *
  281. * @param unknown_type $excludedId
  282. * @return unknown|multitype:
  283. */
  284. function getParentList ($excludedId = 0) {
  285. $this->_db->setQuery (' SELECT virtuemart_custom_id as value,custom_title as text FROM `#__virtuemart_customs` WHERE `field_type` ="P" and virtuemart_custom_id!=' . $excludedId);
  286. if ($results = $this->_db->loadObjectList ()) {
  287. return $results;
  288. }
  289. else {
  290. return array();
  291. }
  292. }
  293. /**
  294. *
  295. * Enter description here ...
  296. */
  297. function getProductChildCustomRelation () {
  298. $this->_db->setQuery (' SELECT virtuemart_custom_id as value,custom_title as text FROM `#__virtuemart_customs` WHERE `field_type` ="C"');
  299. if ($results = $this->_db->loadObjectList ()) {
  300. return $results;
  301. }
  302. else {
  303. return array();
  304. }
  305. }
  306. /**
  307. *
  308. * Enter description here ...
  309. *
  310. * @param unknown_type $product_id
  311. * @return unknown
  312. */
  313. function getProductChildCustom ($product_id) {
  314. $this->_db->setQuery (' SELECT `virtuemart_custom_id`,`custom_value` FROM `#__virtuemart_product_customfields` WHERE `virtuemart_product_id` =' . (int)$product_id);
  315. if ($childcustom = $this->_db->loadObject ()) {
  316. return $childcustom;
  317. }
  318. else {
  319. $childcustom->virtuemart_custom_id = 0;
  320. $childcustom->custom_value = '';
  321. return $childcustom;
  322. }
  323. }
  324. /**
  325. *
  326. * Enter description here ...
  327. *
  328. * @param unknown_type $product_id
  329. * @return string|Ambigous <string, mixed, multitype:>
  330. */
  331. function getProductParentRelation ($product_id) {
  332. $this->_db->setQuery (' SELECT `custom_value` FROM `#__virtuemart_product_customfields` WHERE `virtuemart_product_id` =' . (int)$product_id);
  333. if ($childcustom = $this->_db->loadResult ()) {
  334. return '(' . $childcustom . ')';
  335. }
  336. else {
  337. return JText::_ ('COM_VIRTUEMART_CUSTOM_NO_PARENT_RELATION');
  338. }
  339. }
  340. /**
  341. * AUthor Kohl Patrick
  342. * Load all custom fields for a Single product
  343. * return custom fields value and definition
  344. */
  345. public function getproductCustomslist ($virtuemart_product_id, $parent_id = NULL) {
  346. $query = 'SELECT C.`virtuemart_custom_id` , `custom_element`, `custom_jplugin_id`, `custom_params`, `custom_parent_id` , `admin_only` , `custom_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`,field.`ordering`
  347. FROM `#__virtuemart_customs` AS C
  348. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  349. Where `virtuemart_product_id` =' . $virtuemart_product_id . ' order by field.`ordering` ASC';
  350. $this->_db->setQuery ($query);
  351. $productCustoms = $this->_db->loadObjectList ();
  352. //if (!$productCustoms ) return array();
  353. if (!$productCustoms) {
  354. return;
  355. }
  356. $row = 0;
  357. foreach ($productCustoms as $field) {
  358. if ($parent_id) {
  359. $field->custom_value = "";
  360. $field->virtuemart_customfield_id = "";
  361. $field->custom_param = NULL;
  362. $virtuemart_product_id = $parent_id;
  363. }
  364. if ($field->field_type == 'E') {
  365. JPluginHelper::importPlugin ('vmcustom');
  366. $dispatcher = JDispatcher::getInstance ();
  367. $retValue = $dispatcher->trigger ('plgVmDeclarePluginParams', array('custom', $field->custom_element, $field->custom_jplugin_id, $field));
  368. }else {
  369. VirtueMartModelCustomfields::bindParameterableByFieldType($field);
  370. }
  371. //vmdebug('fields',$field);
  372. $field->display = $this->displayProductCustomfieldBE ($field, $virtuemart_product_id, $row); //custom_param without S !!!
  373. $row++;
  374. }
  375. return $productCustoms;
  376. }
  377. /* Save and delete from database
  378. * all product custom_fields and xref
  379. @ var $table : the xref table(eg. product,category ...)
  380. @array $data : array of customfields
  381. @int $id : The concerned id (eg. product_id)
  382. */
  383. public function storeProductCustomfields($table,$datas, $id) {
  384. //vmdebug('storeProductCustomfields',$datas);
  385. JRequest::checkToken() or jexit( 'Invalid Token, in store customfields');
  386. //Sanitize id
  387. $id = (int)$id;
  388. //Table whitelist
  389. $tableWhiteList = array('product','category','manufacturer');
  390. if(!in_array($table,$tableWhiteList)) return false;
  391. // Get old IDS
  392. $this->_db->setQuery( 'SELECT `virtuemart_customfield_id` FROM `#__virtuemart_'.$table.'_customfields` as `PC` WHERE `PC`.virtuemart_'.$table.'_id ='.$id );
  393. $old_customfield_ids = $this->_db->loadResultArray();
  394. if (isset ( $datas['custom_param'] )) $params = true ;
  395. else $params = false ;
  396. if (array_key_exists('field', $datas)) {
  397. //vmdebug('datas save',$datas);
  398. $customfieldIds = array();
  399. foreach($datas['field'] as $key => $fields){
  400. $fields['virtuemart_'.$table.'_id'] =$id;
  401. $tableCustomfields = $this->getTable($table.'_customfields');
  402. $tableCustomfields->setPrimaryKey('virtuemart_product_id');
  403. if (!empty($datas['custom_param'][$key]) and !isset($datas['clone']) ) {
  404. if (array_key_exists( $key,$datas['custom_param'])) {
  405. $fields['custom_param'] = json_encode($datas['custom_param'][$key]);
  406. }
  407. }
  408. VirtueMartModelCustomfields::setParameterableByFieldType($tableCustomfields,$fields['field_type']);
  409. if(!isset($datas['clone'])){
  410. VirtueMartModelCustomfields::bindParameterableByFieldType($tableCustomfields,$fields['field_type']);
  411. }
  412. $tableCustomfields->bindChecknStore($fields);
  413. $errors = $tableCustomfields->getErrors();
  414. foreach($errors as $error){
  415. vmError($error);
  416. }
  417. $key = array_search($fields['virtuemart_customfield_id'], $old_customfield_ids );
  418. if ($key !== false ) unset( $old_customfield_ids[ $key ] );
  419. // vmdebug('datas clone',$old_customfield_ids,$fields);
  420. }
  421. }
  422. if ( count($old_customfield_ids) ) {
  423. // delete old unused Customfields
  424. $this->_db->setQuery( 'DELETE FROM `#__virtuemart_'.$table.'_customfields` WHERE `virtuemart_customfield_id` in ("'.implode('","', $old_customfield_ids ).'") ');
  425. $this->_db->query();
  426. }
  427. JPluginHelper::importPlugin('vmcustom');
  428. $dispatcher = JDispatcher::getInstance();
  429. if (isset($datas['plugin_param']) and is_array($datas['plugin_param'])) {
  430. foreach ($datas['plugin_param'] as $key => $plugin_param ) {
  431. $dispatcher->trigger('plgVmOnStoreProduct', array($datas, $plugin_param ));
  432. }
  433. }
  434. }
  435. /**
  436. * Formatting admin display by roles
  437. * input Types for product only !
  438. * $field->is_cart_attribute if can have a price
  439. */
  440. public function displayProductCustomfieldBE ($field, $product_id, $row) {
  441. $field->custom_value = empty($field->custom_value) ? $field->value : $field->custom_value;
  442. if ($field->is_cart_attribute) {
  443. if(!class_exists('VirtueMartModelVendor')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'vendor.php');
  444. if(!class_exists('VirtueMartModelCurrency')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'currency.php');
  445. $vendor_model = VmModel::getModel('vendor');
  446. $vendor_model->setId(1);
  447. $vendor = $vendor_model->getVendor();
  448. $currency_model = VmModel::getModel('currency');
  449. $vendor_currency = $currency_model->getCurrency($vendor->vendor_currency);
  450. $priceInput = '<span style="white-space: nowrap;"><input type="text" size="12" style="text-align:right;" value="' . (isset($field->custom_price) ? $field->custom_price : '0') . '" name="field[' . $row . '][custom_price]" /> '.$vendor_currency->currency_symbol."</span>";
  451. }
  452. else {
  453. $priceInput = ' ';
  454. }
  455. if ($field->is_list) {
  456. $options = array();
  457. $values = explode (';', $field->value);
  458. foreach ($values as $key => $val) {
  459. $options[] = array('value' => $val, 'text' => $val);
  460. }
  461. $currentValue = $field->custom_value;
  462. return JHTML::_ ('select.genericlist', $options, 'field[' . $row . '][custom_value]', null, 'value', 'text', $currentValue) . '</td><td>' . $priceInput;
  463. }
  464. else {
  465. switch ($field->field_type) {
  466. case 'A':
  467. //vmdebug('displayProductCustomfieldBE $field',$field);
  468. if(!isset($field->withParent)) $field->withParent = 0;
  469. if(!isset($field->parentOrderable)) $field->parentOrderable = 0;
  470. //vmdebug('displayProductCustomfieldFE',$field);
  471. if (!class_exists('VmHTML')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'html.php');
  472. $html = JText::_('COM_VIRTUEMART_CUSTOM_WP').VmHTML::checkbox('field[' . $row . '][withParent]',$field->withParent,1,0,'').'<br />';
  473. $html .= JText::_('COM_VIRTUEMART_CUSTOM_PO').VmHTML::checkbox('field[' . $row . '][parentOrderable]',$field->parentOrderable,1,0,'');
  474. $options = array();
  475. // $options[] = array( 'value' => 'product_name' ,'text' =>JText::_('COM_VIRTUEMART_PRODUCT_FORM_NAME')); Is anyway displayed there
  476. $options[] = array('value' => 'product_sku', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_SKU'));
  477. $options[] = array('value' => 'slug', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_ALIAS'));
  478. $options[] = array('value' => 'product_length', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_LENGTH'));
  479. $options[] = array('value' => 'product_width', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_WIDTH'));
  480. $options[] = array('value' => 'product_height', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_HEIGHT'));
  481. $options[] = array('value' => 'product_weight', 'text' => JText::_ ('COM_VIRTUEMART_PRODUCT_WEIGHT'));
  482. $html .= JHTML::_ ('select.genericlist', $options, 'field[' . $row . '][custom_value]', '', 'value', 'text', $field->custom_value) . '</td><td>' . $priceInput;
  483. return $html;
  484. // return 'Automatic Childvariant creation (later you can choose here attributes to show, now product name) </td><td>';
  485. break;
  486. // variants
  487. case 'V':
  488. return '<input type="text" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" /></td><td>' . $priceInput;
  489. break;
  490. /*
  491. * Stockable (group of) child variants
  492. * Special type setted by the plugin
  493. */
  494. case 'G':
  495. return;
  496. break;
  497. /*Extended by plugin*/
  498. case 'E':
  499. $html = '<input type="hidden" value="' . $field->value . '" name="field[' . $row . '][custom_value]" />';
  500. if (!class_exists ('vmCustomPlugin')) {
  501. require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
  502. }
  503. JPluginHelper::importPlugin ('vmcustom', $field->custom_element);
  504. $dispatcher = JDispatcher::getInstance ();
  505. $retValue = '';
  506. $dispatcher->trigger ('plgVmOnProductEdit', array($field, $product_id, &$row, &$retValue));
  507. return $html . $retValue . '</td><td>'. $priceInput;
  508. break;
  509. case 'D':
  510. return vmJsApi::jDate ($field->custom_value, 'field[' . $row . '][custom_value]', 'field_' . $row . '_customvalue') .'</td><td>'. $priceInput;
  511. break;
  512. case 'T':
  513. //TODO Patrick
  514. return '<input type="text" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" /></td><td>' . $priceInput;
  515. break;
  516. /* string or integer */
  517. case 'S':
  518. case 'I':
  519. return '<input type="text" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" /></td><td>' . $priceInput;
  520. break;
  521. //'X'=>'COM_VIRTUEMART_CUSTOM_EDITOR',
  522. case 'X':
  523. return '<textarea class="mceInsertContentNew" name="field[' . $row . '][custom_value]" id="field-' . $row . '-custom_value">' . $field->custom_value . '</textarea>
  524. <script type="text/javascript">// Creates a new editor instance
  525. tinymce.execCommand("mceAddControl",true,"field-' . $row . '-custom_value")
  526. </script></td><td>' . $priceInput;
  527. //return '<input type="text" value="'.$field->custom_value.'" name="field['.$row.'][custom_value]" /></td><td>'.$priceInput;
  528. break;
  529. //'Y'=>'COM_VIRTUEMART_CUSTOM_TEXTAREA'
  530. case 'Y':
  531. return '<textarea id="field[' . $row . '][custom_value]" name="field[' . $row . '][custom_value]" class="inputbox" cols=80 rows=50 >' . $field->custom_value . '</textarea></td><td>' . $priceInput;
  532. //return '<input type="text" value="'.$field->custom_value.'" name="field['.$row.'][custom_value]" /></td><td>'.$priceInput;
  533. break;
  534. case 'editorta':
  535. jimport ('joomla.html.editor');
  536. $editor = JFactory::getEditor ();
  537. //TODO This is wrong!
  538. $_return['fields'][$_fld->name]['formcode'] = $editor->display ($_prefix . $_fld->name, $_return['fields'][$_fld->name]['value'], 300, 150, $_fld->cols, $_fld->rows);
  539. break;
  540. /* bool */
  541. case 'B':
  542. return JHTML::_ ('select.booleanlist', 'field[' . $row . '][custom_value]', 'class="inputbox"', $field->custom_value) . '</td><td>' . $priceInput;
  543. break;
  544. /* parent */
  545. case 'P':
  546. return $field->custom_value . '<input type="hidden" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" /></td><td>';
  547. break;
  548. /* related category*/
  549. case 'Z':
  550. if (!$field->custom_value) {
  551. return '';
  552. } // special case it's category ID !
  553. $q = 'SELECT * FROM `#__virtuemart_categories_' . VMLANG . '` JOIN `#__virtuemart_categories` AS p using (`virtuemart_category_id`) WHERE `published`=1 AND `virtuemart_category_id`= "' . (int)$field->custom_value . '" ';
  554. $this->_db->setQuery ($q);
  555. //echo $this->_db->_sql;
  556. if ($category = $this->_db->loadObject ()) {
  557. $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias` WHERE `virtuemart_category_id`= "' . (int)$field->custom_value . '" ';
  558. $this->_db->setQuery ($q);
  559. $thumb = '';
  560. if ($media_id = $this->_db->loadResult ()) {
  561. $thumb = $this->displayCustomMedia ($media_id,'category');
  562. }
  563. $display = '<input type="hidden" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" />';
  564. return $display . JHTML::link (JRoute::_ ('index.php?option=com_virtuemart&view=category&task=edit&virtuemart_category_id=' . (int)$field->custom_value), $thumb . ' ' . $category->category_name, array('title' => $category->category_name)) . $display;
  565. }
  566. else {
  567. return 'no result';
  568. }
  569. /* related product*/
  570. case 'R':
  571. if (!$field->custom_value) {
  572. return '';
  573. }
  574. $q = 'SELECT `product_name`,`product_sku`,`product_s_desc` FROM `#__virtuemart_products_' . VMLANG . '` as l JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`) WHERE `virtuemart_product_id`=' . (int)$field->custom_value;
  575. $this->_db->setQuery ($q);
  576. $related = $this->_db->loadObject ();
  577. $display = $related->product_name . '(' . $related->product_sku . ')';
  578. $display = '<input type="hidden" value="' . $field->custom_value . '" name="field[' . $row . '][custom_value]" />';
  579. $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_product_medias`WHERE `virtuemart_product_id`= "' . (int)$field->custom_value . '" AND (`ordering` = 0 OR `ordering` = 1)';
  580. $this->_db->setQuery ($q);
  581. $thumb = '';
  582. if ($media_id = $this->_db->loadResult ()) {
  583. $thumb = $this->displayCustomMedia ($media_id);
  584. }
  585. $title= $related->product_s_desc? $related->product_s_desc :'';
  586. return $display . JHTML::link (JRoute::_ ('index.php?option=com_virtuemart&view=product&task=edit&virtuemart_product_id=' . $field->custom_value), $thumb . '<br /> ' . $related->product_name, array('title' => $title));
  587. break;
  588. /* image */
  589. case 'M':
  590. if (empty($product)) {
  591. $vendorId = 1;
  592. }
  593. else {
  594. $vendorId = $product->virtuemart_vendor_id;
  595. }
  596. $q = 'SELECT `virtuemart_media_id` as value,`file_title` as text FROM `#__virtuemart_medias` WHERE `published`=1
  597. AND (`virtuemart_vendor_id`= "' . $vendorId . '" OR `shared` = "1")';
  598. $this->_db->setQuery ($q);
  599. $options = $this->_db->loadObjectList ();
  600. return JHTML::_ ('select.genericlist', $options, 'field[' . $row . '][custom_value]', '', 'value', 'text', $field->custom_value) . '</td><td>' . $priceInput;
  601. break;
  602. /* Child product Group */
  603. case 'G':
  604. break;
  605. /* Child product */
  606. /* case 'C':
  607. if (empty($product)){
  608. $virtuemart_product_id = JRequest::getInt('virtuemart_product_id', 0);
  609. } else {
  610. $virtuemart_product_id = $product->virtuemart_product_id;
  611. }
  612. $html = '';
  613. $q='SELECT concat(`product_sku`,":",`product_name`) as text ,`virtuemart_product_id`,`product_in_stock` FROM `#__virtuemart_products` WHERE `published`=1
  614. AND `virtuemart_product_id`= "'.$field->custom_value.'"';
  615. //$db->setQuery(' SELECT virtuemart_product_id, product_name FROM `#__virtuemart_products` WHERE `product_parent_id` ='.(int)$product_id);
  616. $this->_db->setQuery($q);
  617. if ($child = $this->_db->loadObject()) {
  618. $html .= JHTML::link ( JRoute::_ ( 'index.php?option=com_virtuemart&view=product&task=edit&virtuemart_product_id='.$field->custom_value), $child->text.' ('.$field->custom_value.')', array ('title' => $child->text ));
  619. $html .= ' '.JText::_('COM_VIRTUEMART_PRODUCT_FORM_IN_STOCK').':'.$child->product_in_stock ;
  620. $html .= '<input type="hidden" value="'.$child->virtuemart_product_id.'" name="field['.$row.'][custom_value]" /></div><div>'.$priceInput;
  621. return $html;
  622. // return '<input type="text" value="'.$field->custom_value.'" name="field['.$row.'][custom_value]" />';
  623. }
  624. else return JText::_('COM_VIRTUEMART_CUSTOM_NO_CHILD_PRODUCT');
  625. break;*/
  626. }
  627. }
  628. }
  629. public function getProductCustomsField ($product) {
  630. $query = 'SELECT C.`virtuemart_custom_id` , `custom_element`, `custom_params`, `custom_parent_id` , `admin_only` , `custom_title` , `custom_tip` , C.`custom_value` AS value, `custom_field_desc` , `field_type` , `is_list` , `is_hidden`, `layout_pos`, C.`published` , field.`virtuemart_customfield_id` , field.`custom_value`, field.`custom_param`, field.`custom_price`, field.`ordering`
  631. FROM `#__virtuemart_customs` AS C
  632. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  633. Where `virtuemart_product_id` =' . (int)$product->virtuemart_product_id . ' and `field_type` != "G" and `field_type` != "R" and `field_type` != "Z"';
  634. $query .= ' and is_cart_attribute = 0 order by field.`ordering`,virtuemart_custom_id';
  635. $this->_db->setQuery ($query);
  636. if ($productCustoms = $this->_db->loadObjectList ()) {
  637. $row = 0;
  638. if (!class_exists ('vmCustomPlugin')) {
  639. require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
  640. }
  641. foreach ($productCustoms as $field) {
  642. if ($field->field_type == "E") {
  643. $field->display = '';
  644. JPluginHelper::importPlugin ('vmcustom');
  645. $dispatcher = JDispatcher::getInstance ();
  646. $ret = $dispatcher->trigger ('plgVmOnDisplayProductFE', array($product, &$row, &$field));
  647. }
  648. else {
  649. $field->display = $this->displayProductCustomfieldFE ($product, $field, $row);
  650. }
  651. $row++;
  652. }
  653. return $productCustoms;
  654. }
  655. else {
  656. return array();
  657. }
  658. }
  659. public function getProductCustomsFieldRelatedCategories ($product) {
  660. $query = 'SELECT C.`virtuemart_custom_id` , `custom_parent_id` , `admin_only` , `custom_title` , `custom_tip` , C.`custom_value` AS value, `custom_field_desc` , `field_type` , `is_list` , `is_hidden` , C.`published` , field.`virtuemart_customfield_id` , field.`custom_value`, field.`custom_param`, field.`custom_price`, field.`ordering`
  661. FROM `#__virtuemart_customs` AS C
  662. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  663. Where `virtuemart_product_id` =' . (int)$product->virtuemart_product_id . ' and `field_type` = "Z"';
  664. $query .= ' and is_cart_attribute = 0 order by virtuemart_custom_id';
  665. $this->_db->setQuery ($query);
  666. if ($productCustoms = $this->_db->loadObjectList ()) {
  667. $row = 0;
  668. foreach ($productCustoms as & $field) {
  669. $field->display = $this->displayProductCustomfieldFE ($product, $field, $row);
  670. $row++;
  671. }
  672. return $productCustoms;
  673. }
  674. else {
  675. return array();
  676. }
  677. }
  678. public function getProductCustomsFieldRelatedProducts ($product) {
  679. $query = 'SELECT C.`virtuemart_custom_id` , `custom_parent_id` , `admin_only` , `custom_title` , `custom_tip` , C.`custom_value` AS value, `custom_field_desc` , `field_type` , `is_list` , `is_hidden` , C.`published` , field.`virtuemart_customfield_id` , field.`custom_value`, field.`custom_param`, field.`custom_price`, field.`ordering`
  680. FROM `#__virtuemart_customs` AS C
  681. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  682. Where `virtuemart_product_id` =' . (int)$product->virtuemart_product_id . ' and `field_type` = "R"';
  683. $query .= ' and is_cart_attribute = 0 order by virtuemart_customfield_id';
  684. $this->_db->setQuery ($query);
  685. if ($productCustoms = $this->_db->loadObjectList ()) {
  686. $row = 0;
  687. foreach ($productCustoms as & $field) {
  688. $field->display = $this->displayProductCustomfieldFE ($product, $field, $row);
  689. $row++;
  690. }
  691. return $productCustoms;
  692. }
  693. else {
  694. return array();
  695. }
  696. }
  697. /**
  698. * Display for the cart
  699. *
  700. * @author Patrick Kohl
  701. * @param obj $product product object
  702. * @return html code
  703. */
  704. public function getProductCustomsFieldCart ($product) {
  705. // group by virtuemart_custom_id
  706. $query = 'SELECT C.`virtuemart_custom_id`, `custom_title`, C.`custom_value`,`custom_field_desc` ,`custom_tip`,`field_type`,field.`virtuemart_customfield_id`,`is_hidden`
  707. FROM `#__virtuemart_customs` AS C
  708. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  709. Where `virtuemart_product_id` =' . (int)$product->virtuemart_product_id . ' and `field_type` != "G" and `field_type` != "R" and `field_type` != "Z"';
  710. $query .= ' and is_cart_attribute = 1 group by virtuemart_custom_id ORDER BY field.`ordering`';
  711. $this->_db->setQuery ($query);
  712. $groups = $this->_db->loadObjectList ();
  713. if (!class_exists ('VmHTML')) {
  714. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'html.php');
  715. }
  716. $row = 0;
  717. if (!class_exists ('CurrencyDisplay')) {
  718. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
  719. }
  720. $currency = CurrencyDisplay::getInstance ();
  721. if (!class_exists ('calculationHelper')) {
  722. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
  723. }
  724. $calculator = calculationHelper::getInstance ();
  725. $calculator ->_product = $product;
  726. if (!class_exists ('vmCustomPlugin')) {
  727. require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
  728. }
  729. //$free = JText::_ ('COM_VIRTUEMART_CART_PRICE_FREE');
  730. // render select list
  731. foreach ($groups as $group) {
  732. // $query='SELECT field.`virtuemart_customfield_id` as value ,concat(field.`custom_value`," :bu ", field.`custom_price`) AS text
  733. $query = 'SELECT field.`virtuemart_product_id`, `custom_params`,`custom_element`, field.`virtuemart_custom_id`,
  734. field.`virtuemart_customfield_id`,field.`custom_value`, field.`custom_price`, field.`custom_param`
  735. FROM `#__virtuemart_customs` AS C
  736. LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
  737. Where `virtuemart_product_id` =' . (int)$product->virtuemart_product_id;
  738. $query .= ' and is_cart_attribute = 1 and C.`virtuemart_custom_id`=' . (int)$group->virtuemart_custom_id;
  739. // We want the field to be ordered as the user defined
  740. $query .= ' ORDER BY field.`ordering`';
  741. $this->_db->setQuery ($query);
  742. $options = $this->_db->loadObjectList ();
  743. //vmdebug('getProductCustomsFieldCart options',$options);
  744. $group->options = array();
  745. foreach ($options as $option) {
  746. $group->options[$option->virtuemart_customfield_id] = $option;
  747. }
  748. if ($group->field_type == 'V') {
  749. $default = current ($group->options);
  750. foreach ($group->options as $productCustom) {
  751. $price = self::_getCustomPrice($productCustom->custom_price, $currency, $calculator);
  752. $productCustom->text = $productCustom->custom_value . ' ' . $price;
  753. }
  754. $group->display = VmHTML::select ('customPrice[' . $row . '][' . $group->virtuemart_custom_id . ']', $group->options, $default->custom_value, '', 'virtuemart_customfield_id', 'text', FALSE);
  755. }
  756. else {
  757. if ($group->field_type == 'G') {
  758. $group->display .= ''; // no direct display done by plugin;
  759. }
  760. else {
  761. if ($group->field_type == 'E') {
  762. $group->display = '';
  763. foreach ($group->options as $k=> $productCustom) {
  764. $price = self::_getCustomPrice($productCustom->custom_price, $currency, $calculator);
  765. $productCustom->text = $productCustom->custom_value . ' ' . $price;
  766. $productCustom->virtuemart_customfield_id = $k;
  767. if (!class_exists ('vmCustomPlugin')) {
  768. require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
  769. }
  770. //legacy, it will be removed 2.2
  771. $productCustom->value = $productCustom->virtuemart_customfield_id;
  772. JPluginHelper::importPlugin ('vmcustom');
  773. $dispatcher = JDispatcher::getInstance ();
  774. $fieldsToShow = $dispatcher->trigger ('plgVmOnDisplayProductVariantFE', array($productCustom, &$row, &$group));
  775. // $group->display .= '<input type="hidden" value="' . $k . '" name="customPrice[' . $row . '][' . $group->virtuemart_custom_id . ']" /> ';
  776. $group->display .= '<input type="hidden" value="' . $productCustom->virtuemart_customfield_id . '" name="customPrice[' . $row . '][' . $productCustom->virtuemart_custom_id . ']" /> ';
  777. if (!empty($currency->_priceConfig['variantModification'][0]) and $price !== '') {
  778. $group->display .= '<div class="price-plugin">' . JText::_ ('COM_VIRTUEMART_CART_PRICE') . '<span class="price-plugin">' . $price . '</span></div>';
  779. }
  780. $row++;
  781. }
  782. $row--;
  783. }
  784. else {
  785. if ($group->field_type == 'U') {
  786. foreach ($group->options as $productCustom) {
  787. $price = self::_getCustomPrice($productCustom->custom_price, $currency, $calculator);
  788. $productCustom->text = $productCustom->custom_value . ' ' . $price;
  789. $group->display .= '<input type="text" value="' . JText::_ ($productCustom->custom_value) . '" name="customPrice[' . $row . '][' . $group->virtuemart_custom_id . '][' . $productCustom->value . ']" /> ';
  790. if (!empty($currency->_priceConfig['variantModification'][0]) and $price !== '') {
  791. $group->display .= '<div class="price-plugin">' . JText::_ ('COM_VIRTUEMART_CART_PRICE') . '<span class="price-plugin">' . $price . '</span></div>';
  792. }
  793. }
  794. }
  795. else {
  796. if ($group->field_type == 'A') {
  797. $group->display = '';
  798. foreach ($group->options as $productCustom) {
  799. /* if ((float)$productCustom->custom_price) {
  800. $price = $currency->priceDisplay ($calculator->calculateCustomPriceWithTax ($productCustom->custom_price));
  801. }
  802. else {
  803. $price = ($productCustom->custom_price === '') ? '' : $free;
  804. }*/
  805. $productCustom->field_type = $group->field_type;
  806. $productCustom->is_cart = 1;
  807. $group->display .= $this->displayProductCustomfieldFE ($product, $productCustom, $row);
  808. $checked = '';
  809. }
  810. }
  811. else {
  812. $group->display = '';
  813. $checked = 'checked="checked"';
  814. foreach ($group->options as $productCustom) {
  815. //vmdebug('getProductCustomsFieldCart',$productCustom);
  816. $price = self::_getCustomPrice($productCustom->custom_price, $currency, $calculator);
  817. $productCustom->field_type = $group->field_type;
  818. $productCustom->is_cart = 1;
  819. // $group->display .= '<input id="' . $productCustom->virtuemart_custom_id . '" ' . $checked . ' type="radio" value="' .
  820. // $productCustom->virtuemart_custom_id . '" name="customPrice[' . $row . '][' . $productCustom->virtuemart_customfield_id . ']" /><label
  821. // for="' . $productCustom->virtuemart_custom_id . '">' . $this->displayProductCustomfieldFE ($productCustom, $row) . ' ' . $price . '</label>';
  822. //MarkerVarMods
  823. $group->display .= '<input id="' . $productCustom->virtuemart_custom_id .$row. '" ' . $checked . ' type="radio" value="' .
  824. $productCustom->virtuemart_customfield_id . '" name="customPrice[' . $row . '][' . $productCustom->virtuemart_custom_id . ']" /><label
  825. for="' . $productCustom->virtuemart_custom_id . '" class="other-customfield">' . $this->displayProductCustomfieldFE ($product, $productCustom, $row) . ' ' . $price . '</label>';
  826. $checked = '';
  827. }
  828. }
  829. }
  830. }
  831. }
  832. }
  833. $row++;
  834. }
  835. return $groups;
  836. }
  837. static function _getCustomPrice($customPrice, $currency, $calculator) {
  838. if ((float)$customPrice) {
  839. $price = strip_tags ($currency->priceDisplay ($calculator->calculateCustomPriceWithTax ($customPrice)));
  840. if ($customPrice >0) {
  841. $price ="+".$price;
  842. }
  843. }
  844. else {
  845. $price = ($customPrice === '') ? '' : JText::_ ('COM_VIRTUEMART_CART_PRICE_FREE');
  846. }
  847. return $price;
  848. }
  849. /**
  850. * Formating front display by roles
  851. * for product only !
  852. */
  853. public function displayProductCustomfieldFE (&$product, $customfield, $row = '') {
  854. $virtuemart_custom_id = isset($customfield->virtuemart_custom_id)? $customfield->virtuemart_custom_id:0;
  855. $value = $customfield->custom_value;
  856. $type = $customfield->field_type;
  857. $is_list = isset($customfield->is_list)? $customfield->is_list:0;
  858. $price = isset($customfield->custom_price)? $customfield->custom_price:0;
  859. $is_cart = isset($customfield->is_cart)? $customfield->is_cart:0;
  860. //vmdebug('displayProductCustomfieldFE and here is something wrong ',$customfield);
  861. if (!class_exists ('CurrencyDisplay'))
  862. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
  863. $currency = CurrencyDisplay::getInstance ();
  864. if ($is_list > 0) {
  865. $values = explode (';', $value);
  866. if ($is_cart != 0) {
  867. $options = array();
  868. foreach ($values as $key => $val) {
  869. $options[] = array('value' => $val, 'text' => $val);
  870. }
  871. vmdebug('displayProductCustomfieldFE is a list ',$options);
  872. return JHTML::_ ('select.genericlist', $options, 'field[' . $row . '][custom_value]', NULL, 'value', 'text', FALSE, TRUE);
  873. }
  874. else {
  875. $html = '';
  876. // if($type=='M'){
  877. // foreach ($values as $key => $val){
  878. // $html .= '<div id="custom_'.$virtuemart_custom_id.'_'.$val.'" >'.$this->displayCustomMedia($val).'</div>';
  879. // }
  880. // } else {
  881. // foreach ($values as $key => $val){
  882. $html .= '<div id="custom_' . $virtuemart_custom_id . '_' . $value . '" >' . $value . '</div>';
  883. // }
  884. // }
  885. return $html;
  886. }
  887. }
  888. else {
  889. if ($price > 0) {
  890. $price = $currency->priceDisplay ((float)$price);
  891. }
  892. switch ($type) {
  893. case 'A':
  894. $options = array();
  895. $session = JFactory::getSession ();
  896. $virtuemart_category_id = $session->get ('vmlastvisitedcategoryid', 0, 'vm');
  897. $productModel = VmModel::getModel ('product');
  898. //parseCustomParams
  899. VirtueMartModelCustomfields::bindParameterableByFieldType($customfield);
  900. //Todo preselection as dropdown of children
  901. //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
  902. //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.
  903. //There exists already other customs and in special plugins which wanna disable or change the add to cart button.
  904. //I suggest that we manipulate the button with a message "choose a variant first"
  905. //if(!isset($customfield->pre_selected)) $customfield->pre_selected = 0;
  906. $selected = JRequest::getInt ('virtuemart_product_id',0);
  907. $html = '';
  908. $uncatChildren = $productModel->getUncategorizedChildren ($customfield->withParent);
  909. foreach ($uncatChildren as $k => $child) {
  910. $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']);
  911. }
  912. $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",
  913. JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected));
  914. //vmdebug('$customfield',$customfield);
  915. if($customfield->parentOrderable==0 and $product->product_parent_id==0){
  916. $product->orderable = FALSE;
  917. }
  918. return $html;
  919. break;
  920. /* variants*/
  921. case 'V':
  922. if ($price == 0)
  923. $price = JText::_ ('COM_VIRTUEMART_CART_PRICE_FREE');
  924. /* Loads the product price details */
  925. return '<input type="text" value="' . JText::_ ($value) . '" name="field[' . $row . '][custom_value]" /> ' . JText::_ ('COM_VIRTUEMART_CART_PRICE') . $price . ' ';
  926. break;
  927. /*Date variant*/
  928. case 'D':
  929. 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;
  930. break;
  931. /* text area or editor No JText, only displayed in BE */
  932. case 'X':
  933. case 'Y':
  934. return $value;
  935. break;
  936. /* string or integer */
  937. case 'S':
  938. case 'I':
  939. return JText::_ ($value);
  940. break;
  941. /* bool */
  942. case 'B':
  943. if ($value == 0)
  944. return JText::_ ('COM_VIRTUEMART_NO');
  945. return JText::_ ('COM_VIRTUEMART_YES');
  946. break;
  947. /* parent */
  948. case 'P':
  949. return '<span class="product_custom_parent">' . JText::_ ($value) . '</span>';
  950. break;
  951. /* related */
  952. case 'R':
  953. $q = 'SELECT l.`product_name`, p.`product_parent_id` , l.`product_name`, x.`virtuemart_category_id` FROM `#__virtuemart_products_' . VMLANG . '` as l
  954. JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`)
  955. LEFT JOIN `#__virtuemart_product_categories` as x on x.`virtuemart_product_id` = p.`virtuemart_product_id`
  956. WHERE p.`published`=1 AND p.`virtuemart_product_id`= "' . (int)$value . '" ';
  957. $this->_db->setQuery ($q);
  958. $related = $this->_db->loadObject ();
  959. if (empty ($related))
  960. return '';
  961. $thumb = '';
  962. $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_product_medias`WHERE `virtuemart_product_id`= "' . (int)$value . '" AND (`ordering` = 0 OR `ordering` = 1)';
  963. $this->_db->setQuery ($q);
  964. $thumb="";
  965. if ($media_id = $this->_db->loadResult ()) {
  966. $thumb = $this->displayCustomMedia ($media_id).' ';
  967. }
  968. 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));
  969. break;
  970. /* image */
  971. case 'M':
  972. return $this->displayCustomMedia ($value);
  973. break;
  974. /* categorie */
  975. case 'Z':
  976. $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 . '" ';
  977. $this->_db->setQuery ($q);
  978. if ($category = $this->_db->loadObject ()) {
  979. $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" ';
  980. $this->_db->setQuery ($q);
  981. $thumb = '';
  982. if ($media_id = $this->_db->loadResult ()) {
  983. $thumb = $this->displayCustomMedia ($media_id,'category');
  984. }
  985. 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));
  986. }
  987. else return '';
  988. /* Child Group list
  989. * this have no direct display , used for stockable product
  990. */
  991. case 'G':
  992. return ''; //'<input type="text" value="'.JText::_($value).'" name="field['.$row.'][custom_value]" /> '.JText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' ';
  993. break;
  994. break;
  995. }
  996. }
  997. }
  998. function displayCustomMedia ($media_id, $table = 'product', $absUrl = FALSE) {
  999. if (!class_exists ('TableMedias'))
  1000. require(JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'medias.php');
  1001. //$data = $this->getTable('medias');
  1002. $db = JFactory::getDBO ();
  1003. $data = new TableMedias($db);
  1004. $data->load ((int)$media_id);
  1005. if (!class_exists ('VmMediaHandler'))
  1006. require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'mediahandler.php');
  1007. $media = VmMediaHandler::createMedia ($data, $table);
  1008. return $media->displayMediaThumb ('', FALSE, '', TRUE, TRUE, $absUrl);
  1009. }
  1010. /**
  1011. * There are too many functions doing almost the same for my taste
  1012. * the results are sometimes slighty different and makes it hard to work with it, therefore here the function for future proxy use
  1013. *
  1014. */
  1015. public function customFieldDisplay ($product, $variantmods, $html, $trigger) {
  1016. //vmdebug('customFieldDisplay $variantmods',$variantmods);
  1017. $row = 0;
  1018. if (!class_exists ('shopFunctionsF'))
  1019. require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
  1020. //MarkerVarMods
  1021. foreach ($variantmods as $selected => $variant) {
  1022. //foreach ($variantmods as $variant=> $selected) {
  1023. //vmdebug('customFieldDisplay '.$variant.' '.$selected);
  1024. if ($selected) {
  1025. $productCustom = self::getProductCustomField ($selected);
  1026. //vmdebug('customFieldDisplay',$selected,$productCustom);
  1027. if (!empty($productCustom)) {
  1028. $html .= ' <span class="product-field-type-' . $productCustom->field_type . '">';
  1029. if ($productCustom->field_type == "E") {
  1030. $product = self::addParam ($product);
  1031. $product->productCustom = $productCustom;
  1032. //vmdebug('CustomsFieldCartDisplay $productCustom',$productCustom);
  1033. // vmdebug('customFieldDisplay $product->param selected '.$selected,$product->param);
  1034. if (!class_exists ('vmCustomPlugin'))
  1035. require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
  1036. JPluginHelper::importPlugin ('vmcustom');
  1037. $dispatcher = JDispatcher::getInstance ();
  1038. $dispatcher->trigger ($trigger, array($product, $row, &$html));
  1039. }
  1040. else {
  1041. //vmdebug('customFieldDisplay $productCustom by self::getProductCustomField $variant: '.$variant.' $selected: '.$selected,$productCustom);
  1042. $value = '';
  1043. if (($productCustom->field_type == "G")) {
  1044. $child = self::getChild ($productCustom->custom_value);
  1045. // $html .= $productCustom->custom_title.' '.$child->product_name;
  1046. $value = $child->product_name;
  1047. }
  1048. elseif (($productCustom->field_type == "M")) {
  1049. // $html .= $productCustom->custom_title.' '.self::displayCustomMedia($productCustom->custom_value);
  1050. $value = self::displayCustomMedia ($productCustom->custom_value);
  1051. }
  1052. elseif (($productCustom->field_type == "S")) {
  1053. // q $html .= $productCustom->custom_title.' '.JText::_($productCustom->custom_value);
  1054. $value = $productCustom->custom_value;
  1055. }
  1056. else {
  1057. // $html .= $productCustom->custom_title.' '.$productCustom->custom_value;
  1058. //vmdebug('customFieldDisplay',$productCustom);
  1059. $value = $productCustom->custom_value;
  1060. }
  1061. $html .= ShopFunctionsF::translateTwoLangKey

Large files files are truncated, but you can click here to view the full file