In Magento eCommerce while working with catalog model, There arise the need to fetch product details from product id.
We can get all product details if we have product id.
But sometimes we only have product name, so we need to get product id for getting product details.
I am listing here both the method.
1) Product details from Product ID.
2) Product ID from Product Name
This is little bit complex. (If anybody has better way please post here)
- <?php
- $product_name = 'Test Product'; //product name
- $model = Mage::getModel('catalog/product') //getting product model
- $collection = $model->getCollection(); //products collection
- foreach ($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
- ?>
本文介绍了在Magento电子商务平台中如何通过产品ID获取详细的产品信息,同时也提供了从产品名称查找产品ID的方法。包括PHP代码示例,展示了如何加载产品模型、获取产品详情以及通过名称搜索产品。
1394

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



