25
« Last post by Kuubs on November 29, 2023, 12:06:09 PM »
Max helped me in writing and optimizing the code. This is the working code:
<?php
defined('_JEXEC') or die('Restricted access');
class plgVmCustomSpecificaties extends vmCustomPlugin {
function __construct(&$subject, $config) {
parent::__construct($subject, $config);
$this->_tablepkey = 'id';
$varsToPush = array(
'icon_field' => array('', 'string'),
'text_field' => array('', 'string'),
'html_field1' => array('', 'string'),
'html_field2' => array('', 'string')
);
$this->setConfigParameterable('customfield_params', $varsToPush);
}
function plgVmOnProductEdit($field, $productId, &$row, &$retValue) {
if ($field->custom_element != $this->_name) return '';
$html = ''; // Initialize HTML variable
// Icon field
$html .= '<div>Icon Field:</div>';
$html .= '<textarea name="customfield_params['.$row.'][icon_field]" style="width: 100%; height: 100px;">';
$html .= htmlspecialchars($field->icon_field);
$html .= '</textarea><br/>';
// Text field
$html .= '<div>Text Field:</div>';
$html .= '<textarea name="customfield_params['.$row.'][text_field]" style="width: 100%; height: 100px;">';
$html .= htmlspecialchars($field->text_field);
$html .= '</textarea><br/>';
// First HTML editor field
$editor = JFactory::getEditor();
$html .= '<div>HTML Field 1:</div>';
$html .= $editor->display('customfield_params['.$row.'][html_field1]', htmlspecialchars($field->html_field1), '100%', '200', '75', '20', false);
// Second HTML editor field
$html .= '<div>HTML Field 2:</div>';
$html .= $editor->display('customfield_params['.$row.'][html_field2]', htmlspecialchars($field->html_field2), '100%', '200', '75', '20', false);
$retValue .= $html;
$row++;
return true;
}
// Additional functions as per your requirement:
function plgVmOnDisplayProductFEVM3(&$product,&$group) {
if ($group->custom_element != $this->_name) return '';
$group->display .= $this->renderByLayout('default',array(&$product,&$group) );
return true;
}
function plgVmOnViewCartVM3(&$product, &$productCustom, &$html) {
if (empty($productCustom->custom_element) or $productCustom->custom_element != $this->_name) return false;
if(empty($product->customProductData[$productCustom->virtuemart_custom_id][$productCustom->virtuemart_customfield_id])) return false;
foreach( $product->customProductData[$productCustom->virtuemart_custom_id] as $k =>$item ) {
if($productCustom->virtuemart_customfield_id == $k) {
if(isset($item['comment'])){
$html .='<span>'.vmText::_($productCustom->custom_title).' '.$item['comment'].'</span>';
}
}
}
return true;
}
function plgVmOnViewCartModuleVM3( &$product, &$productCustom, &$html) {
return $this->plgVmOnViewCartVM3($product,$productCustom,$html);
}
function plgVmDisplayInOrderBEVM3( &$product, &$productCustom, &$html) {
$this->plgVmOnViewCartVM3($product,$productCustom,$html);
}
function plgVmDisplayInOrderFEVM3( &$product, &$productCustom, &$html) {
$this->plgVmOnViewCartVM3($product,$productCustom,$html);
}
/**
*
* vendor order display BE
*/
function plgVmDisplayInOrderBE(&$item, $productCustom, &$html) {
if(!empty($productCustom)){
$item->productCustom = $productCustom;
}
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->plgVmOnViewCart($item,$productCustom,$html); //same render as cart
}
/**
*
* shopper order display FE
*/
function plgVmDisplayInOrderFE(&$item, $productCustom, &$html) {
if(!empty($productCustom)){
$item->productCustom = $productCustom;
}
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->plgVmOnViewCart($item,$productCustom,$html); //same render as cart
}
function plgVmDeclarePluginParamsCustomVM3(&$data){
return $this->declarePluginParams('custom', $data);
}
function plgVmGetTablePluginParams($psType, $name, $id, &$xParams, &$varsToPush){
return $this->getTablePluginParams($psType, $name, $id, $xParams, $varsToPush);
}
function plgVmSetOnTablePluginParamsCustom($name, $id, &$table,$xParams){
return $this->setOnTablePluginParams($name, $id, $table,$xParams);
}
// Continue with other functions as needed...
}
// No closing PHP tag to prevent accidental output
No need to make new tables or anything. This will use the native custom field VM code