【问题标题】:VirtueMart 2.6.6 custom field (cart variable) not displayed in the order detailsVirtueMart 2.6.6 自定义字段(购物车变量)未显示在订单详细信息中
【发布时间】: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


    【解决方案1】:

    我想,我解决了我的问题,是什么:

    在函数plgVmOnDisplayProductVariantFE中我犯了一个错误,我没有使用布局渲染器,它生成了一个带有变量virtuemart_customfield_id的对象$viewData

    那么在你的插件布局中,输入字段名称必须如下:

    <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 属性应该总是:

    • customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][随便]

    plgVmOnDisplayProductVariantFE函数的正确用法是使用表达式:

    • $group->display .= $this->renderByLayout('default',array($field,&$idx,&$group )

    这里是正确表达的整个函数:

    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
                )
    
        )
    
    )
    

    ...现在我很高兴,我可以继续我的项目 :)

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 2015-12-10
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多