Question

Magento 2.3

The extension sits in app/code/VendorName/ModuleName/

it has etc, view, Block, Controller, Model directories

What is the best way to call short_description and selected size configurable product (custom attribute)/specific simple product size from the database to render in view/frontend/templates/product/list/items.phtml?

A related question from me: How to show catalog attribute in cross-sell in shopping cart which overridden by an Extension module

I have done it in shopping cart section with method getData() for short_description and getAttributeText() for selected size. But this way to call the data cannot work in an extension module environment.

Source: getData getAttributeText

Was it helpful?

Solution

Following a few googled answers (in my previous question) confused me in the universe of god.

I found out how to achieve this. It's as just simple as

<?php /* @escapeNotVerified */ echo $_item->getData("short_description") ?>

getShortDescription() will work as well for above

For selected size of a product, instead of all the options of the size by using getProductDetailsHtml(),

<?php /* @escapeNotVerified */ echo $_item->getAttributeText("size_owth") ?>

My wholeheartedly opinion:

PHPStorm does not show auto-completion for getShortDescription() and getAttributeText(), what a joke, even with the plugin for Magento too. And go to declaration (or goto definition) don't work these two methods as well.

Magento documentation sucks, wasting my time. It's like calling to you to read and try the classes one by one in the Magento Core, and one by one following the route of the models to retrieve the classes.

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