在 html 模块 opencart 2.x 中获取产品价格

Get product price in html module opencart 2.x

我是 opencart 开发的初学者,现在我需要一些非常简单的东西(正如我认为的......)我正在使用 opencart 2.1.0.1,我做了一个简单的 table

<table align="left" border="1" cellspacing="1" style="table-layout:fixed;width:500px;">
<tbody>
    <tr>
        <td style="text-align: center;"></td>
        <td style="text-align: center;"></td>
    </tr>
    <tr>
        <td>here i want the product price</td>
        <td>here i want the prduct price</td>
    </tr>
</tbody>

我想在数据单元格中获取产品价格(并可能稍后在后端对其进行一些操作)。 是否可以通过制作一个 html 模块,或者我需要将我的代码直接放在我的 .tpl 页面上并使用控制器?

编辑: 鉴于对我的原始答案的反馈,更新后的回复如下: 您可以使用 $price 访问价格,但这将包含货币,因此您可以在 table:

之前在 tpl 文件中插入以下代码
<?php 
    $pricenew = $product['price'];
    $pricenew  = preg_replace( '/\D/', '', $pricenew  );
?>

现在您可以根据公式的要求在 table 上使用 $pricenew

原答案: 假设您正在为 OpenCart 安装创建一个扩展,您至少需要同时拥有一个控制器和一个视图(.tpl 文件),最佳实践会鼓励您包含一个语言文件以使翻译更简单。如果您只是展示某些产品,则可能不需要模型。

我建议阅读 this from the OpenCart documentation, there are also tutorials that make learning OpenCart extension development simpler. Here's a tutorial 了解制作显示最新产品的扩展。