How to use $_product on Magento Catalog template pages
-
20-12-2020 - |
Вопрос
I have overridden the Magento catalog phtml file in our store's custom template to display a link to a custom instructional page that we created.
Problem is, I only want this link to display on certain product pages.
I've noticed that on this page we have access to the variable $_product
through the call to
$_product = $block->getProduct();
I've tried logging this object using print_r, etc. but nothing seems to work. How can I see the shape of this object so that I can figure out how to locate something like: $_product->category
Any advice on a better procedure to get this kind of functionality into the catalog?
Решение
To get all the data of a product you can use following.
$_product = $block->getProduct();
echo '<pre>';
print_r($_product->getData());
echo '</pre>';
die();
To get name of product you can use following for example
$_product->getName();
Не связан с magento.stackexchange