Question

I created placed custom html in Magento_Catalog>template>product>view>details.phtml file in Magento_Catalog module and added below code to get current product ID and name

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$_product_id = $product->getId();
$_product_name = $product->getName();

What are the other functions to get product details like Price, Images, Short & Long description, etc...

Please sugest me the list of functions i can use to get product details.

Please help me if you know answer to this Question also

Was it helpful?

Solution

You can get price,sku,description by following code

$_product_price = $product->getPrice();
$_product_image= $product->getImage();
$_product_sku = $product->getSku();
$_product_desc=$product->getDescription();

updated solution get category ids and images by following code

protected $_productRepositoryFactory;

public function __construct(
        \Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory
) {

    $this->_productRepositoryFactory = $productRepositoryFactory;
}

In function

 $_items = $order->getAllItems();
foreach($_items as $_item)
{
    $id=$_item->getProductId();
}

$product = $this->_productRepositoryFactory->create()->getById($item->getProductId());
$product->getData('image');
$product->getData('thumbnail');
$product->getData('small_image');
$product->getCategoryIds();

OTHER TIPS

You current_product is the object of following class:

Magento\Catalog\Model\Product

Path:

vendor/magento/module-catalog/Model/Product.php

Now you open this class and search your actual method.

Following code will list you a functions list to get product data according to your code.

echo "<pre>";
var_dump(get_class_methods($product));

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top