PHP: Convert curly quotes to straight quotes
A client of mine writes, “Take a look at the personal message (from our web form) on the quote below….what is happening with the characters in those fields. I believe there was likely abbreviation for foot: 8’”
Cause: This is typically caused by someone creating string of text in Microsoft Word and then pasting it into a web form.
Solution: Set up the following search and replace parameters in your PHP script:
$search = array("\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x98", "\xe2\x80\x99");
$replace = array('"', '"', "'", "'");
$formmessage = str_replace($search, $replace, $_POST['message']);
Magento: display and round prices to 3rd decimal point
Second time now I’ve had the client request that set their Magento prices to display and round to the third (3rd) decimal point. This time I will share with you how I performed this change in Magento (ver. 1.3.2.4).
First I FTP to my lib/Zend/Currency.php file and change the following:
protected $_options = array( 'position' => self::STANDARD, 'script' => null, 'format' => null, 'display' => self::NO_SYMBOL, 'precision' => 2, 'name' => null, 'currency' => null, 'symbol' => null );
to
protected $_options = array( 'position' => self::STANDARD, 'script' => null, 'format' => null, 'display' => self::NO_SYMBOL, 'precision' => 3, 'name' => null, 'currency' => null, 'symbol' => null );
Please note that if you upgrade Magento this will be overwritten and this change will be required again after upgrade!!!
Second, copy app/code/core/Mage/Core/Model/Store.php to app/code/local/Mage/Core/Model/Store.php. By doing this you protect this file from being overwritten during upgrades. Next change the following code in that file from:
public function roundPrice($price)
{
return round($price, 2);
}
to
public function roundPrice($price,$roundTo=3)
{
return round($price, $roundTo);
}
Lastly, I suggest copying app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php. Then you can change the following code in that file from:
public function getEscapedValue($index=null)
{
$value = $this->getValue();
if (!is_numeric($value)) {
return null;
}
return number_format($value, 2, null, '');
}
to
public function getEscapedValue($index=null)
{
$value = $this->getValue();
if (!is_numeric($value)) {
return null;
}
return number_format($value, 3, null, '');
}
Clear your Magento Cache and now you have prices that extend to the third (3rd) decimal point both on the front end and in the admin section of Magento!!!
If you have any suggestions on how to improve this post please feel free to drop me a line!