How to change price format in Magento 1 - magento

I am getting stuck over 1 days to find how to change price format in Magento.
My current store displaying the price format like (US$1.114,50) but I need the correct format is (US$1,114.50).
So, everyone here know how to change this format?
Thank you so much for your kindly help.

Formatting price in Magento
There are a couple of methods to format price in Magento. The easiest and most used is:
Mage::helper("core")->currency($price, $format, $includeContainer)
Example:
echo Mage::helper("core")->currency(115, true, false)
//if your currency is Euro then output will be: €115.00
Sometimes you don’t need currency symbols in your prices, then you will need something like:
Mage::getModel('directory/currency')->setData("currency_code", Mage::app()->getStore(null)->getCurrentCurrency()->getCode())->format(
$product->getFinalPrice(),
array('display' =>Zend_Currency::NO_SYMBOL), false);
The value for the display can be Zend_Currency::NO_SYMBOL (it will remove the symbol and show only the price) Zend_Currency::USE_SYMBOL (shows the currency symbol before the price), Zend_Currency::USE_SHORTNAME (shows the abbreviation of the currency before the price) or Zend_Currency::USE_NAME (shows the full name of the currency before the price). Example outputs:
Zend_Currency::NO_SYMBOL: 115.00
Zend_Currency::USE_SYMBOL: €115.00
Zend_Currency::USE_SHORTNAME: EUR115.00
Zend_Currency::USE_NAME: EURO115.00

Related

Exchange rates for ENDOFMONTH

I have an Exchange Rate table that I'm trying to get the ending months calculation
It's using a minimum of 3 currencies lets use GBP USD EUR
I need to return when selecting that currency the End of month Currency
So something like k
EOMCcy=:IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE([Exchange Rate],ENDOFMONTH('Exchange Rates'[Date]) ,BLANK()))
I know I need to validate the currency somewhere and I'm trying many thinks as I have a fromCcy and toCccy column e.g GBP USD
This would show in the [Exchange Rate] column =1.22
I was hoping someone can point me in the right direction or offer a better method with my code
Thank all
So I think I solved it
EOMCcy:=IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE (
SUM ([ExchangeRate]),
FILTER (
ALL ( 'Exchange Rates'[Date]),
'Exchange Rates'[Date] = ENDOFMONTH('Exchange Rates'[Date])
)
),BLANK())

Magento - How to diplsay tax/vat percentage in Invoice PDF totals, and also change Tax labels to Vat

I need to display the vat percentage in the invoice pdfs. So when the admin is in the back end viewing an invoice and clicks print, they'll see the invoice with 'vat # %' in the totals. Currently it displays tax as the label so i'd also like to change that to VAT.
So far I've managed to display the vat % for each product in the invoice by adding the following to
app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
// draw Tax
$taxPercent = $item->getOrderItem()->getTaxPercent();
$taxPercent = number_format($taxPercent,2,',','');
$taxPercent = $taxPercent."%";
$lines[0][] = array(
'text' => $order->formatPriceTxt($item->getTaxAmount())." #".$taxPercent ,
'feed' => 515,
'font' => 'bold',
'align' => 'right'
);
That's works fine but I'd also like to display it next to 'Tax' in the totals.
I've also tried changing the Tax labels to VAT by editing the following csv files in locale
en_US/Mage_Reports.csv
en_us/Mage_Tax.csv
I also copied both csv files to en_GB but that did bugger all for me as well
There must be an easy way to change the labels and add the vat percentage in the totals?
Thank you for any help
EDIT Come to think about it, i dont think its possible to add the tax rate in the totals as each product in the invoice may have a different tax rate. so for now i'm happy listing the tax rate for each product.
Still can't seem to change the tax labels or add a new column to the products table in the invoice, it would be nice to have a "tax rate" column heading next to the tax amount
EDIT 2 Found out it was an extension overriding the invoice.php file stopping me from changing the column headings for the products table, how annoying!. That's solved that issue, Although the totals still have tax not VAT

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

Magento rounds up the custom product price

I'm setting a custom price depending on each customer. Using a webservice I receive the specific price for each customer in the format: XX,DD
When I use the function setprice in order to set the new price for the product:
$product->setFinalPrice($price);
Magento rounds up the price and, for example, if the $price is 38,50, then it sets the product price to 38. I've tried changing the ',' for '.' with str_replace, but in this case, it seems it can't set up the price.
How can I tell Magento to use the decimals as well?
Thanks
First you should convert your price to decimal number:
$value="38,50";
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
// or you can use str_replace
In Magento products has two types of standard price:
$product->getPrice();
$product->getSpecialPrice();
finalPrice - it is not actually product value, it will be calculated by Magento based on price, special_price, tier price and so on. You should set price value and save the product:
$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();
I'll throw in that you can use:
echo number_format($_product->getPrice(), 2)
It will give you a couple of decimal places.
I am guessing you do not want the price to round up. If that is the case then your solution depends on the version of PHP you are using.
PHP 5.3 you can simply use the round function to round it down like so:
round($price, 2, PHP_ROUND_HALF_DOWN);
If you are using PHP 5.2 you do not have the luxary of the PHP_ROUND_HALF_DOWN so you have to put the following function in somewhere (a helper makes the most sense to me) and call it:
floor($line_item_price * 100) / 100;
What this does is first multiply the value with 100 and then floor the value. This gives you a rounded down value with the precision of 2. Then divide by 100 to get the correct value.
The number 100 comes from the power(10, desired precision)
I hope you are on PHP 5.3. I did not enjoy having to do the PHP 5.2 solution very much.
To round up a price in magento you need overwrite a directory/currency model method convert.
Mage_Directory_Model_Currency::convert()
here you will find like this
return $price*$rate
and need to set like this
return round($price*$rate);

How to access to the discount price in Magento?

I'm trying to rewrite a template for the cart.
I need to retrieve the discount amount but I was not able to find where.
Ie If my coupon code gives me $10 discount I want to retrieve 10, if I have a discount of 5% I want to retrieve 5 if the total price is $100.
Thank you.
you can debug your object by printing it out and observing what values it contains
print_r($this->getQuote()->getData());
I used the following code to access discount price. I was accessing the details of last order in a phtml file. For the last order if there was a discount coupon used then I used following code to access the Discount Amount.
$lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
if($lastOrderId) //If order was placed then only display coupon code
{
$coupon=$order->getCouponCode();
echo "<b>Discount coupon used during order:</b>".$coupon;
$disAmount=$order->getDiscountAmount();
echo "<br/>Discount Amount: ".$disAmount;
}

Resources