问题描述
也许有人有一个线索.我想在opencart中将零售价格四舍五入.
Maybe someone has a clue. I want to round the retail prices to nice numbers in opencart.
基本计算为:(其中应产生的€1,50-€2,00-€2,50等)
Base calculation is: (wich should produce € 1,50 - €2,00 - € 2,50 etc)
$price = sprintf("%.2f", round($pice * 2) / 2);
我以为我会在controller/product/product.php中这样做,但是那没有用.我不想编辑所有主题.tpl,因此必须在opencart代码中完成.
I thought i'dd do it like this in controler/product/product.php but that ain't working. I don't want to edit all theme .tpl so it has to be done in the opencart code.
现在我有了这个,但我得到了€0.49或€0.99的价值
Now i have this but I get values of €0.49 or €0.99
$price_new = $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'));
$price_new_1 = count($price_new , 2)/2-0.01;
$price_complete = $this->currency->format($price_new_1);
$spec_price_new = $this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'));
$spec_price_new_1 = round($spec_price_new, 2)/2-0.01;
$spec_price_complete = $this->currency->format($spec_price_new_1);
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $price_complete;
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $spec_price_complete;
} else {
$special = false;
}
较早的尝试并没有导致价格上涨..
Older try outs wich did not lead to a price..
if (($this->config->get('config_customer_price') && $this->customer- >isLogged()) || !$this->config->get('config_customer_price')) {
$price = sprintf("%.2f", round($this->currency->format($this- >tax->calculate($result['price'], $result['tax_class_id'], $this->config- >get('config_tax'))) * 2) / 2);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = sprintf("%.2f", round($this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')))* 2) / 2);
} else {
$special = false;
}
我也尝试过这种方式:
// round price calculation
$normaloldprice = $this->currency->format($this->tax- >calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$newprice = round($normaloldprice * 2)/2;
$specialoldprice = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$newspecialprice = round($specialoldwprice * 2)/2;
$oldtaxprice = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']);
$newtaxprice = round($oldtaxprice * 2)/2;
// end round price calculation
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$this->data['price'] = $newprice;
} else {
$this->data['price'] = false;
}
if ((float)$product_info['special']) {
$this->data['special'] = $newspecialprice;
} else {
$this->data['special'] = false;
}
if ($this->config->get('config_tax')) {
$this->data['tax'] = $newtaxprice;
} else {
$this->data['tax'] = false;
}
推荐答案
有关干净整洁的解决方案,此模块将满足您的需求.
for a clean and crisp solution, this module will do what you need.
http://www.opencart.com/index.php?route = extension/extension/info& extension_id = 10351
这篇关于计算opencart的零售价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!