简体   繁体   中英

parse number as currency in opencart php

first off, using Opencart 1.5.1.3

with my array of products, i've had the need to create a MAP (manufacturers advertised pricing) pricing field as well as a regular pricing field. Some manufacturers only allow me to display a minimum price they set, even if my price is lower, they must add to cart.

In order to make this work i used the "location" field in the database and just uploaded the map price to there...

by using $product['location'] (a number value) and stripping out $product['price'] to display as number value then use a series of if statements to determine what price to show.

i believe i've traced my issue to being this: since $product['location'] isn't a price, it's not being told by opencart to process the exchange rate (when switching currencies) and therefore my $product['location'] value is not changing.

i think this can be resolved by editing the following lines in category.php but i'm not sure what to put...

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

any help would be appreciated.

link: https://arkmarine.ca/instruments/autopilots

You will need to set the value as a float, then pass it to the $this->currency->format method. You can set the float type using the (float) typecasting before the value

$this->currency->format( (float) $variable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM