If you are developing Magento template sooner or later you willneed to obtain some product information and rearrange it to fityour template. One of the most useful function while working withMagento is Mage::getModel($modelClass).
Here is how you would use it to retrieve Magento productinformationMage::getModel(‘catalog/product’);.
This
For the last few weeks I’ve been using NetBeans 6.5beta, regularlydownloading night builds of it. Let’s suppose you open the/template/catalog/category/view.phtml
All you need to do is something like
$cProduct = Mage::getModel(‘catalog/product’);
Don’t let the name variable $cProduct confuse you. I’m using theletter “c”as
a sort of personal standard, stands for
Here is how:
$cProduct->load(152);
echo ‘<p>Product name:<strong>’ .$cProduct->getName() .‘</strong></p>’;
echo ‘<p>Product price:<strong>’ .$cProduct->getPrice() .‘</strong></p>’;
echo ‘<p>Product url:<strong>’ .$cProduct->getProductUrl() .‘</strong></p>’;
echo ‘<p>Product Category:<strong>’ .$cProduct->getCategory() .‘</strong></p>’;
echo ‘<p>Product image url:<strong>’ .$cProduct->getImageUrl() .‘</strong></p>’;
echo ‘<p>Product status (this one isboolean): <strong>’ .$cProduct->getStatus() .‘</strong></p>’;
echo ‘<p>Product weight:<strong>’ .$cProduct->getWeight() .‘</strong></p>’;
Most important line in the above code is the
本文介绍如何使用Magento的Mage::getModel方法来获取产品信息,并通过示例代码展示了如何加载特定产品并提取其名称、价格等属性。
2万+

被折叠的 条评论
为什么被折叠?



