2

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

1
  • 1
    You can take reference from this file for get product details magento/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml Commented Jun 29, 2019 at 17:17

3 Answers 3

2

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();
5
  • 1
    Did you try this? Commented Jul 2, 2019 at 6:31
  • I'll try that. how can we get images of the same product? getGallery??? and category also? getCategory?
    – rakcode
    Commented Jul 3, 2019 at 10:32
  • Thanks. Can you please check my another question. no one replied to me on that one! :(
    – rakcode
    Commented Jul 3, 2019 at 11:15
  • 1
    Did you check updated answer? Commented Jul 3, 2019 at 11:16
  • Yes its working fine for me. Thanks.
    – rakcode
    Commented Jul 3, 2019 at 12:56
3

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.