php 在 magento 中获取产品 ID 和产品类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16331887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get product id and product type in magento?
提问by Nathan Srivi
I am creating magento store. I am beginner in magento. I want to get product id and product input type in my phtml file is this possible? please guide me..
我正在创建 magento 商店。我是 magento 的初学者。我想在我的 phtml 文件中获取产品 ID 和产品输入类型,这可能吗?请指导我..
I am trying to this way to get product type. but its not working for me
我正在尝试以这种方式获取产品类型。但它对我不起作用
$product=Mage::getModel('catalog/product')->load($product_id);
$productType=$product->getTypeID();
Please guide me...
请指导我...
回答by liyakat
Try below code to get currently loaded product id:
尝试以下代码以获取当前加载的产品 ID:
$product_id = $this->getProduct()->getId();
When you don't have access to $this, you can use Magento registry:
当您无权访问 $this 时,您可以使用 Magento 注册表:
$product_id = Mage::registry('current_product')->getId();
Also for product type i think
也适用于我认为的产品类型
$product = Mage::getModel('catalog/product')->load($product_id);
$productType = $product->getTypeId();
回答by Bakk László
<?php if( $_product->getTypeId() == 'simple' ): ?>
//your code for simple products only
<?php endif; ?>
<?php if( $_product->getTypeId() == 'grouped' ): ?>
//your code for grouped products only
<?php endif; ?>
So on. It works! Magento 1.6.1, place in the view.phtml
很快。有用!Magento 1.6.1,放置在view.phtml
回答by Pragnesh Rupapara
you can get all product information from following code
您可以从以下代码中获取所有产品信息
$product_id=6//Suppose
$_product=Mage::getModel('catalog/product')->load($product_id);
$product_data["id"]=$_product->getId();
$product_data["name"]=$_product->getName();
$product_data["short_description"]=$_product->getShortDescription();
$product_data["description"]=$_product->getDescription();
$product_data["price"]=$_product->getPrice();
$product_data["special price"]=$_product->getFinalPrice();
$product_data["image"]=$_product->getThumbnailUrl();
$product_data["model"]=$_product->getSku();
$product_data["color"]=$_product->getAttributeText('color'); //get cusom attribute value
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId) ->load($_product->getId());
$product_data["rating"]=($summaryData['rating_summary']*5)/100;
$product_data["shipping"]=Mage::getStoreConfig('carriers/flatrate/price');
if($_product->isSalable() ==1)
$product_data["in_stock"]=1;
else
$product_data["in_stock"]=0;
echo "<pre>";
print_r($product_data);
//echo "</pre>";
回答by Saurabh Chandra Patel
Item collection.
项目集合。
$_item->product_type;
$_item->getId()
Product :
产品 :
$product->getTypeId();
$product->getId()
回答by Kesar Sisodiya
You can also try this..
你也可以试试这个..
$this->getProduct()->getId();
$this->getProduct()->getId();
When you don't have access to $this you can use Magento registry:
当您无权访问 $this 时,您可以使用 Magento 注册表:
$cpid=Mage::registry('current_product')->getId();
$cpid=Mage::registry('current_product')->getId();
回答by sudhir
$product=Mage::getModel('catalog/product')->load($product_id);
$product=Mage::getModel('catalog/product')->load($product_id);
above code not working for me. its throw exception;
上面的代码对我不起作用。它的抛出异常;
This is working for me for get product details.
这对我有用以获取产品详细信息。
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id);
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id);
So use for for product type.
所以用于产品类型。
$productType = $_product->getTypeId();
$productType = $_product->getTypeId();
回答by Potamus
This worked for me-
这对我有用-
if(Mage::registry('current_product')->getTypeId() == 'simple' ) {
Use getTypeId()
用 getTypeId()
回答by JAIMIN PATEL
IN MAGENTO query in the database and fetch the result like. product id, product name and manufracturer with out using the product flat table use the eav catalog_product_entity and its attribute table product_id product_name manufacturer 1 | PRODUCTA | NOKIA 2 | PRODUCTB | SAMSUNG
IN MAGENTO 在数据库中查询并获取类似的结果。产品 id、产品名称和制造商不使用产品平面表使用 eav catalog_product_entity 及其属性表 product_id product_name 制造商 1 | 产品展示 | 诺基亚 2 | 产品B | 三星