Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php category.tpl页面中的Opencart 2.0属性_Php_Opencart_Opencart2.x - Fatal编程技术网

Php category.tpl页面中的Opencart 2.0属性

Php category.tpl页面中的Opencart 2.0属性,php,opencart,opencart2.x,Php,Opencart,Opencart2.x,我想在category.tpl页面的产品中添加属性。 我只找到了以前opencart版本的答案。但在这个例子中,它不起作用: -在/catalog/model/catalog/product.php中 将内容替换为 "public function getProductAttributes($product_id) {", 公共函数getProductAttributesnocat$product\u id{ $product\u attribute\u data=数组; $product\

我想在category.tpl页面的产品中添加属性。 我只找到了以前opencart版本的答案。但在这个例子中,它不起作用:

-在/catalog/model/catalog/product.php中 将内容替换为

"public function getProductAttributes($product_id) {",
公共函数getProductAttributesnocat$product\u id{ $product\u attribute\u data=数组; $product\u attribute\u query=$this->db->query从.db\u PREFIX.product\u attribute pa LEFT JOIN.db\u PREFIX.pa.attribute a.attribute\u id=a.attribute\u id LEFT JOIN.db\u PREFIX.attribute\u说明a.attribute\u id=ad.attribute\u id其中pa.product\u id='.int$product\u id.'和ad.language\u id=“.int$this->config->get'config\u language\u id.”和pa.language\u id='.int$this->config->get'config\u language\u id.”按a.sort\u顺序排列,ad.name; foreach$product\u属性\u查询->行作为$product\u属性{ $product_属性_数据[]=数组 'attribute_id'=>$product_attribute['attribute_id'], 'name'=>$product_属性['name'], 'text'=>$product_属性['text'] ; } 返回$product\u属性\u数据;
} 虽然我建议使用VqMod,但您可以手动执行以下操作: 打开catalog/controller/product/category.php并找到以下代码:

$data['products'][] = array(
                'product_id'  => $result['product_id'],
                'thumb'       => $image,
                'name'        => $result['name'],
                'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
                'price'       => $price,
                'special'     => $special,
                'tax'         => $tax,
                'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
                'rating'      => $result['rating'],
                'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
            );
现在在它的'attribute\u groups'=>$this->model\u catalog\u product->getProductAttributes$result['product\u id']中添加一行,那么产品数组如下所示:

$data['products'][] = array(
                'product_id'  => $result['product_id'],
                'thumb'       => $image,
                'attribute_groups'       => $this->model_catalog_product->getProductAttributes($result['product_id']),
                'name'        => $result['name'],
                'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
                'price'       => $price,
                'special'     => $special,
                'tax'         => $tax,
                'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
                'rating'      => $result['rating'],
                'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
            );
现在打开catalog/view/theme/YOUR_theme_文件夹/template/product/category.tpl并在下面添加以下代码

保存并重新加载它将显示类别产品中的属性

更多详细信息和演示,请访问

我安装了vqmod并按照说明操作。唉。注意:未定义索引:第112行第112行的/home/m/marsha/sun/public\u html/vqmod/vqcache/vq2-catalog\u view\u theme\u coloring\u template\u product\u category.tpl中的attribute\u groups:['product_id'],将上面的行添加到category.phmm的product array中,我在上一次添加了它,并重试了一次,但它不起作用。它在清理缓存修改器后开始起作用。谢谢!
<p>
              <?php if ($product['attribute_groups']) { ?>
            <div class="tab-pane" id="tab-specification">
              <table class="table table-bordered">
                <?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
                <thead>
                <tr>
                  <td colspan="2"><strong><?php echo $attribute_group['name']; ?></strong></td>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
                <tr>
                  <td><?php echo $attribute['name']; ?></td>
                  <td><?php echo $attribute['text']; ?></td>
                </tr>
                <?php } ?>
                </tbody>
                <?php } ?>
              </table>
            </div>
            <?php } ?>
            </p>