Search code examples
opencartopencart2.xopencart-3

How to display price in all currencies in product page?


How to display price in all currencies in product page?

I have added three currencies in admin panel. I check one of them as main currency. Then I added product with price.

When I scan product page I see price only in main currency. How to display price in all currencies in product page?

Ask you, answer more practic and useful! Thank you!


Solution

  • OpenCart 3.0.2.0, Default Theme

    You need to edit these two files:

    1) Controller File

    catalog\controller\product\product.php
    

    Find

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

    Add after it

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

    Find

    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;
    }
    

    Change it to

    $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) View File

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

    Find

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

    Change it to

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

    Then clear all caches (ocmod cache, twig cache, vqmod cache).