2

So I am working with some Magento code that was done by another developer (or the pre-installed Magento code, i'm not sure which) and my method for getting the price variable differs from theirs.

We are both trying to access the price of a product. My method is...

$_configurable_model = Mage::getModel('catalog/product_type_configurable');
$_child_products = $_configurable_model->getUsedProducts(null, $_product);

echo round($_child_product[0]->getPrice(), 2);

The alternative is:

echo $_coreHelper->currency($_price,true,true);

Now obviously their method is shorter, but I do not know how to use the coreHelper-> currency call in order to look at the children product prices so I implemented it my way.

So I am essentially wondering what are the advantages/disadvantages of both of our methods, if any?

Many thanks in advance!

Nathaniel Wendt
  • 1,194
  • 4
  • 23
  • 49

1 Answers1

4

Using the helper's currency method takes a number and converts according to the appropriate store's formatting. Since different stores may have different currencies and localization this is very useful.

Since it only needs a number you can mix the methods like this:

Mage::helper('core')->currency($_child_product[0]->getPrice());

The second and third parameters are optional.

clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
  • Thanks! The only difficulty is now that I would like to loop through the child products to find the lowest price. A foreach statement seems like it wouldn't work with using the currency method. Any ideas? Forgive my naivety if this is a foolish question. – Nathaniel Wendt Jul 11 '11 at 21:44
  • 1
    Simply compare the prices and don't format them with any method. They are just numbers after all. – clockworkgeek Jul 11 '11 at 22:11