我为Virtuemart 2.6.6编写了一个自定义字段插件,该插件在产品页面上显示了一些参数,例如“ size”,并且该参数也是cart变量。
这篇文章对我们有很大的帮助:
https://www.spiralscripts.co.uk/Joomla-Tips/custom-plugin-fields-in-virtuemart-2-2.html
当然还有stackoverflow论坛和出厂默认的VM自定义插件。
一切正常(将产品添加到购物车时,尺寸显示在产品详细信息视图和购物车中),但有一件事情:
我在插件中放置了以下函数,但没有解决我的问题:
function plgVmOnViewCart($product, $row, &$html)
{
if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return '';
if (!$plgParam = $this->GetPluginInCart($product)) return false ;
$html .= '<div class="parameterek_attributes">';
foreach ($plgParam as $attributes) {
foreach ($attributes as $k => $attribute) {
if ($k =='child_id') continue;
if ($k == 'custom_param_default3') $name = 'Veľkosť'; else $name = '';
$html .='<span class="parameterek_attribute"> '.$name.': '.JText::_($attribute).' </span>';
}
}
$html.='</div>';
return true;
}
/**
*
* shopper order display BackEnd
*/
function plgVmDisplayInOrderBE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
if(!empty($productCustom)){
$item->productCustom = $productCustom;
}
$this->plgVmOnViewCart($item, $row,$html);
}
/**
*
* shopper order display FrontEnd
*/
function plgVmDisplayInOrderFE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->plgVmOnViewCart($item, $row,$html);
}
存入名为#__virtuemart_order_items的数据库表中的值已保存:类似:
{“ 357”:“ 5”}
但应该是这样的:
{“ 357”:“尺寸M”}
我看到关键函数是GetPluginInCart($ product),当我在结帐过程中打印出$ product-> param时,得到了以下输出:
Array
(
[0] => Array
(
[parameterek] => Array
(
[custom_param_default3] => L
)
)
)
但是在完成订单并进入订单详细信息之后,$ product-> param具有以下值:
Array
(
[357] => 5
)
在以下站点上https://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins
我发现了一个功能:
plgVmOnViewCartOrder($product, $param,$productCustom, $row)
handel $param before adding it in the order
return $param;
但是当我在整个consmartmart安装中搜索字符串“ plgVmOnViewCartOrder”时,找不到该字符串,因此它没有启动(?)
如果有人可以帮助我或发送公正的文档,那将是很好的。谢谢!
我想,我解决了我的问题,那是什么:
在功能plgVmOnDisplayProductVariantFE我犯了一个错误,我没有使用布局渲染,生成一个对象$可视数据与变量virtuemart_customfield_id。
然后在插件的布局中,输入字段名称必须如下所示:
<input
class="parameterekInput"
type="radio"
id="plugin_param['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.']['.$c.']"
name="customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][custom_param_default3]"
value="'.$size.'" />
因此name属性应始终为:
plgVmOnDisplayProductVariantFE函数的正确用法是使用表达式:
这里的整个函数具有正确的表达式:
function plgVmOnDisplayProductVariantFE ($field, &$idx, &$group) {
if ($field->custom_element != $this->_name) return '';
$this->getCustomParams($field);
$this->getPluginCustomData($field, $field->virtuemart_product_id);
$group->display .= $this->renderByLayout('default',array($field,&$idx,&$group ) );
return true;
}
现在,当我在函数GetPluginInCart($ product)中使用print_r -ing $ product-> param时,我得到了:
Array
(
[273] => Array //previously the key was Zero, now it is 273, value of virtuemart_customfield_id
(
[parameterek] => Array
(
[custom_param_default3] => L
)
)
)
...现在我很高兴,我可以继续进行我的项目了:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句