计算opencart的四舍五入零售价格

计算opencart的四舍五入零售价格,opencart,rounding,Opencart,Rounding,也许有人有线索。我想在opencart中将零售价格四舍五入到一个不错的数字 基本计算为:(应产生1,50欧元-2,00欧元-2,50欧元等) 我想我应该在controller/product/product.php中这样做,但这不起作用。我不想编辑所有的theme.tpl,所以它必须在opencart代码中完成 现在我有了这个,但我得到的值是0.49欧元或0.99欧元 $price_new = $this->tax->calculate($result['price'

也许有人有线索。我想在opencart中将零售价格四舍五入到一个不错的数字

基本计算为:(应产生1,50欧元-2,00欧元-2,50欧元等)

我想我应该在controller/product/product.php中这样做,但这不起作用。我不想编辑所有的theme.tpl,所以它必须在opencart代码中完成

现在我有了这个,但我得到的值是0.49欧元或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;
            }
        
以前的尝试没有带来价格:

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

对于一个简洁明了的解决方案,本模块将满足您的需要

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