3

When I am Trying to call Custom Template file test.phtml on product view page Template file i.e on wrapper.phtml template file is called but, when I am trying to output product details from my custom test.phtml I am unable to output,So any help how to get product details on my Custom test.phtml

File path:

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/options/wrapper.phtml

<?php include ($block->getTemplateFile('Magento_Catalog::product/view/options/test.phtml')) ?>

My Custom Template File Path:

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/options/test.phtml

But I was unable to load product details when I write code on test.phtml file

Thanks

4
  • Welcome to forum.Add more information about what we tried, whats your magento version and some code part
    – Mujahidh
    Commented Feb 3, 2017 at 5:30
  • In Magento 2 version Commented Feb 3, 2017 at 5:44
  • How you are trying to load product ??? can you explain
    – BornCoder
    Commented Feb 3, 2017 at 5:50
  • $productId = 8; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $currentproduct = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);echo $currentproduct->getName(); when i am adding this in test.phtml, i was getting output, but when i try to put $_option = $block->getOption(); these lines and try to get details i am unable to output Commented Feb 3, 2017 at 6:16

1 Answer 1

1

Please try below code

$objectManagerProduct = \Magento\Framework\App\ObjectManager::getInstance();

$objectManagerProduct->create('\Magento\Framework\Registry');

$category = $objectManagerProduct->registry('current_product');

productId = $category->getId();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$currentproduct =
$objectManager->create('Magento\Catalog\Model\Product')->loa&#8204;&#8203;d($productId);

echo $currentproduct->getName();

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.