How to create your own currency type in Magento or Zend?

I'm looking to create a new reward currency, so instead of my Magento store selling $ 300.00 dollars, I want it to display 300 reward points.

I already tried the bad practice solution by adding this to the currency section in the lib / Zend / Locale / Data / en.xml directory

<currency type="RWP">
            <displayName>Reward Point</displayName>
            <displayName count="one">Reward Point</displayName>
            <displayName count="other">Reward Points</displayName>
            <symbol>Reward Points</symbol>
</currency>

I managed to turn it on and use it in Magento by following this topic: http://www.magentocommerce.com/boards/viewthread/56508/  but it still uses the default formatting template: ¤ #,##0.00so it looks like Bonus Points800.00

My locale is set to ru_CA , and as far as I can tell, I was unable to change the formatting template without affecting the CDN and USD format either.

I tried to override Mage_Core_Model_Store, so if the current currency code is RWP, it will format the price using an array of formatting options, but this does not work when I'm in the product view. Not to mention that it also seems like a really dirty way to achieve what I want.

 /**
 * Format price with currency filter (taking rate into consideration)
 *
 * @param   double $price
 * @param   bool $includeContainer
 * @return  string
 */
public function formatPrice($price, $includeContainer = true)
{
    if ($this->getCurrentCurrency()) {
        /**
        * Options array
        *
        * The following options are available
        * 'position'  => Position for the currency sign
        * 'script'    => Script for the output
        * 'format'    => Locale for numeric output
        * 'display'   => Currency detail to show
        * 'precision' => Precision for the currency
        * 'name'      => Name for this currency
        * 'currency'  => 3 lettered international abbreviation
        * 'symbol'    => Currency symbol
        */
        $options = array();

        if ($this->getCurrentCurrencyCode() == 'RWP') {
            $options = array(
                'position' => 16,
                'precision' => 0,
                'format'=> '#,##0.00 '
            );
        }
        return $this->getCurrentCurrency()->format($price, $options, $includeContainer);
    }
    return $price;
}
+5
source share
1 answer

The monetary system is something that I am only familiar with, so it’s all with salt. (also assuming Magento 1.4.2)

- directory/currency. , .

Mage::getModel('directory/currency')

, " / ", . formatPrecision formatTxt - , .

, , directory/currency Magento ( getNumber currency)

public function formatTxt($price, $options=array())
{
    if (!is_numeric($price)) {
        $price = Mage::app()->getLocale()->getNumber($price);
    }
    /**
     * Fix problem with 12 000 000, 1 200 000
     *
     * %f - the argument is treated as a float, and presented as a floating-point number (locale aware).
     * %F - the argument is treated as a float, and presented as a floating-point number (non-locale aware).
     */
    $price = sprintf("%F", $price);
    return Mage::app()->getLocale()->currency($this->getCode())->toCurrency($price, $options);
}

- core/locale. . , .

, , Magento . , , , , .

0

All Articles