简体   繁体   English

在opencart php中将数字解析为货币

[英]parse number as currency in opencart php

first off, using Opencart 1.5.1.3 首先,使用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. 对于我的一系列产品,我需要创建一个MAP(制造商宣传的定价)定价字段以及一个常规定价字段。 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. 通过使用$ product ['location'](一个数字值)并去除$ product ['price']以显示为数字值,然后使用一系列if语句确定要显示的价格。

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. 我相信我已经追究到了这个问题:由于$ product ['location']不是价格,opencart并没有告诉它处理汇率(在转换货币时),因此我的$ product ['location ']的值没有改变。

i think this can be resolved by editing the following lines in category.php but i'm not sure what to put... 我认为可以通过在category.php中编辑以下行来解决此问题,但我不确定该放置什么...

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 链接: https//arkmarine.ca/instruments/autopilots

You will need to set the value as a float, then pass it to the $this->currency->format method. 您将需要将值设置为浮点数,然后将其传递给$ this-> currency-> format方法。 You can set the float type using the (float) typecasting before the value 您可以使用值前的(float)类型转换来设置浮点类型

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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