如何在产品页面中以所有货币显示价格?

How to display price in all currencies in product page?

如何在产品页面显示所有货币的价格?

我在管理面板中添加了三种货币。我检查其中之一作为主要货币。然后我添加了带有价格的产品。

当我扫描产品页面时,我只看到以主要货币显示的价格。如何在产品页面显示所有货币的价格?

问你,回答更实用有用!谢谢!

OpenCart 3.0.2.0,默认主题

您需要编辑这两个文件:

1) 控制器文件

catalog\controller\product\product.php

查找

$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);

后面加上

$currencies = $this->model_localisation_currency->getCurrencies();

查找

if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
    $data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
    $data['price'] = false;
}

改为

$data['price'] = array();
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
    foreach ($currencies as $currency) {
        if ($currency['status']) {
            $data['price'][] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency['code']);
        }
    }
}

2) 查看文件

catalog\view\theme\default\template\product\product.twig

查找

<h2>{{ price }}</h2>

改为

{% for currency_price in price %}
    <h2>{{ currency_price }}</h2>
{% endfor %}

然后清除所有缓存(ocmod 缓存、twig 缓存、vqmod 缓存)。