【问题标题】:add value to textarea based on selected autocomplete option in opencart根据 opencart 中选择的自动完成选项向 textarea 添加值
【发布时间】:2016-09-30 10:17:42
【问题描述】:

我向 DB 添加了一个新列,用于向 Opencart 中的属性添加描述,我可以轻松地从管理面板添加/编辑描述,但我在 product_form 页面中遇到问题。当我选择属性名称时,我想为每个产品自动添加属性描述。 在 Opencart 中,管理员可以从自动完成框中选择产品的属性,但每次管理员都应该手动添加属性描述。例如属性“黄金”。每次管理员选择属性“黄金”时,他都必须手动添加黄金描述。我想从数据库列'protext'中检索属性描述,以便在管理员时自动填充相关的文本区域。因此,当从输入框中选择“Gold”时,相关文本应出现在相关文本区域中进行描述。

这是我以产品形式编辑的代码,但不起作用。 您的帮助将不胜感激。

function attributeautocomplete(attribute_row) {
    $('input[name=\'product_attribute[' + attribute_row + '][name]\']').autocomplete({
        'source': function(request, response) {
            $.ajax({
                url: 'index.php?route=catalog/attribute/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request),
                dataType: 'json',           
                success: function(json) {
                    response($.map(json, function(item) {
                        return {
                            category: item.attribute_group,
                            label: item.name,
                            label2: item.protext,                           
                            value: item.attribute_id                            
                        }
                    }));
                }
            });
        },
        'select': function(item) {                      
            $('input[name=\'product_attribute[' + attribute_row + '][name]\']').val(item['label']);
            $('input[name=\'product_attribute[' + attribute_row + '][attribute_id]\']').val(item['value']);             
            $('input[name=\'related\']').val('');
        }
        $('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][text]\']').autocomplete({
            'append': function(item) {
            $('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][text]\']').val(item['protext']);
            }
    }); 
}

【问题讨论】:

  • 这是一个紧迫的问题。您的帮助将不胜感激。

标签: php jquery json textarea opencart


【解决方案1】:

为此,您必须更改 ajax 返回结果的控制器文件中的代码。路径 Admin > Controller > Catalog > Attribute -> function autocomplete()。在名称行或您想要的任何其他键之后添加“protext”代码(我写了 1 以便您可以在文件中找到代码并可以在此之后添加)

'name'            => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),

'protext'          => html_entity_decode($result['protext'], ENT_QUOTES, 'UTF-8'),

这就是方法,您将在 tpl 文件中得到它。

  • 数据库已经使用 * 获取,因此您无需更改任何代码。
  • 您已经为 tpl 添加了代码,所以它可以正常工作。

注意 - 最好使用 vqmod 或 ocmod 进行这些更改。我的OC版本2.0.2.0

【讨论】:

  • 这个问题是我从 attribute.php 编辑的第一天开始做的:'protext' => html_entity_decode($result['protext'], ENT_QUOTES, 'UTF-8'), 问题出在 product_form .tpl,我添加了必要的代码,但我现在自动完成功能仅适用于前 2 个属性。
  • 在您的选择函数中添加这一行 $('textarea[name=\'product_attribute[' + attribute_row + '][product_attribute_description][text]\']').val(item['label2 ']);并删除 textarea 自动完成行,它永远不会调用
猜你喜欢
  • 1970-01-01
  • 2014-03-21
  • 1970-01-01
  • 2022-01-21
  • 2023-03-09
  • 1970-01-01
  • 2023-03-13
  • 2012-02-09
  • 1970-01-01
相关资源
最近更新 更多