【发布时间】:2014-09-22 17:00:50
【问题描述】:
我为 Virtuemart 2.6.6 编写了一个自定义字段插件,它在产品页面上显示一些参数,例如“尺寸”,该参数也是一个购物车变量。
这篇文章帮了大忙:
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;
但是当我在整个美德玛特安装中搜索字符串“plgVmOnViewCartOrder”时,没有找到,所以它没有启动(?)
如果有人可以帮助我或发送一份公平的文件,那就太好了。谢谢!
【问题讨论】:
标签: joomla2.5 custom-fields virtuemart