共计 1143 个字符,预计需要花费 3 分钟才能阅读完成。
我们在Magento的Catalog Model设计Magento模板时,可以通过下面二个方法来获取商品信息:
方法一:通过ID里获取商品详情
<pre>
<?php$model = Mage::getModel('catalog/product') //getting product model$_product = $model->load($productid); //getting product object for particular product idecho $_product->getShortDescription(); //product's short descriptionecho $_product->getDescription(); // product's long descriptionecho $_product->getName(); //product nameecho $_product->getPrice(); //product's regular Priceecho $_product->getSpecialPrice(); //product's special Priceecho $_product->getProductUrl(); //product urlecho $_product->getImageUrl(); //product's image urlecho $_product->getSmallImageUrl(); //product's small image urlecho $_product->getThumbnailUrl(); //product's thumbnail image url ?></pre>
方法二:通过商品名获取商品ID
<pre>
<?php$product_name = 'Test Product'; //product name$model = Mage::getModel('catalog/product') //getting product model$collection = $model->getCollection(); //products collectionforeach ($collection as $product) //loop for getting products{ $model->load($product->getId()); $pname = $model->getName(); if(strcmp($pname,$product_name)==0) { $id = $product->getId(); }}echo 'Required ID->'.$id; //id of product?></pre>
正文完