Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento对定制产品价格进行了汇总_Magento - Fatal编程技术网

Magento对定制产品价格进行了汇总

Magento对定制产品价格进行了汇总,magento,Magento,我将根据每位客户设定一个自定义价格。使用Web服务,我收到每个客户的具体价格,格式为:XX,DD 当我使用函数setprice为产品设置新价格时: $product->setFinalPrice($price); $value = "38,50"; //this decimalformat is used in nl_Nl locale $amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));

我将根据每位客户设定一个自定义价格。使用Web服务,我收到每个客户的具体价格,格式为:XX,DD

当我使用函数setprice为产品设置新价格时:

$product->setFinalPrice($price);
$value = "38,50"; //this decimalformat is used in nl_Nl locale
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
$amount = Mage::app()->getStore()->roundPrice($amount); //round price based on Magento logic
$product->setPrice($amount); //price - is actual value of product
// some extra code here
$product->save();
Magento将价格四舍五入,例如,如果$price为38,50,则将产品价格设置为38。我试着用str_replace来更改“for”,但在这种情况下,似乎无法设置价格

我如何告诉Magento也使用小数


谢谢

我将加入您可以使用的:

echo number_format($_product->getPrice(), 2)

它会给你几个小数位

我猜你不希望价格上涨。如果是这种情况,那么您的解决方案取决于您使用的PHP版本

PHP 5.3您可以简单地使用round函数对其进行四舍五入,如下所示:

round($price, 2, PHP_ROUND_HALF_DOWN);
如果您使用的是PHP 5.2,那么您没有PHP_ROUND_HALF_的豪华功能,因此您必须将以下函数放在某个地方(助手对我来说最有意义)并调用它:

floor($line_item_price * 100) / 100;
它的作用是首先将值乘以100,然后将值降到最低。这将为您提供精度为2的向下舍入值。然后除以100得到正确的值

数字100来自电源(10,所需精度)


我希望您使用的是PHP5.3。我不太喜欢使用PHP 5.2解决方案。

首先,您应该将价格转换为十进制数:

$value="38,50";
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
// or you can use str_replace
在Magento中,产品有两种标准价格:

$product->getPrice();
$product->getSpecialPrice();
最终价格-它不是实际的产品价值,它将由Magento根据价格、特殊价格、层级价格等进行计算。您应该设置价格值并保存产品:

$product->setFinalPrice($price);
$value = "38,50"; //this decimalformat is used in nl_Nl locale
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
$amount = Mage::app()->getStore()->roundPrice($amount); //round price based on Magento logic
$product->setPrice($amount); //price - is actual value of product
// some extra code here
$product->save();

要在magento中汇总价格,需要覆盖目录/货币模型转换方法

Mage_Directory_Model_Currency::convert()
在这里你会发现像这样

return $price*$rate
 return round($price*$rate);
需要这样设置

return $price*$rate
 return round($price*$rate);

$price
打印是否正确?是的,在这两种情况下都正确(当它分别为38.50和38,50时)。但Magento似乎将价格转换为四舍五入。。。