Magento2 Showing a custom attribute on category listing page Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento2.1 - Show custom category attribute on frontendCustom attribute values Not showing while compare the product in magento2Unset custom data from product attributeGetting Custom Product Attribute Value via objectManager in Magento 2How to show custom product attribute in Items orderd tab Magento 1.9.3Cannot save product with required custom attribute (unique value)Magento2 - Add custom attribute in transactional sales e-mailHow to show product custom attribute in items ordered section in magento2.2.0?Magento 2 get custom attribute of a single product inside a pluginMagento 2 plugin change price of products that have a custom attribute with

Why did C use the -> operator instead of reusing the . operator?

Is Diceware more secure than a long passphrase?

How to translate "red flag" into Spanish?

FullSimplify a trigonometric expression doesn't work as expected

How to find the right literary agent in the USA?

Additive group of local rings

What was Apollo 13's "Little Jolt" after MECO?

Do you need a weapon for Thunderous Smite, and the other 'Smite' spells?

Check if a string is entirely made of the same substring

Do I need to protect SFP ports and optics from dust/contaminants? If so, how?

Retract an already submitted recommendation letter (written for an undergrad student)

Expansion//Explosion and Siren Stormtamer

Are these square matrices always diagonalisable?

Is Electric Central Heating worth it if using Solar Panels?

Could moose/elk survive in the Amazon forest?

Is there any hidden 'W' sound after 'comment' in : Comment est-elle?

What is it called when you ride around on your front wheel?

What is a 'Key' in computer science?

Error: Syntax error. Missing ')' for CASE Statement

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Does Feeblemind produce an ongoing magical effect that can be dispelled?

Why did Israel vote against lifting the American embargo on Cuba?

Trumpet valves, lengths, and pitch

How to not starve gigantic beasts



Magento2 Showing a custom attribute on category listing page



Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento2.1 - Show custom category attribute on frontendCustom attribute values Not showing while compare the product in magento2Unset custom data from product attributeGetting Custom Product Attribute Value via objectManager in Magento 2How to show custom product attribute in Items orderd tab Magento 1.9.3Cannot save product with required custom attribute (unique value)Magento2 - Add custom attribute in transactional sales e-mailHow to show product custom attribute in items ordered section in magento2.2.0?Magento 2 get custom attribute of a single product inside a pluginMagento 2 plugin change price of products that have a custom attribute with



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a magento2 based website and I am wanting to show a custom attribute on the category listing page. My issue seems to be that on desktop and tablet the products are shown 3 across and on mobile they are shown 2 across.



Now if the last item in the row shouldn't show the custom attribute (or has no value set for the custom attribute) it still shows the prior products custom attribute value.



Below is my code. I know using Object Manager in the php file is not the ideal. the php file edited is



 Magento_Catalog/templates/product/price/final_price.phtml

//THIS CODE WILL HELP US WRITE TEXT UNDER THE PRICE SUCH AS BOGO, ETC
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Has you can see I even tried using the unset() function before I call in the custom attribute. However no matter what I do the very next product after the product that has a value for the custom attribute if the net product does not have a value it shows the prior products value(s).



Its odd because if I do



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
$theitemskunumber_is = $_productdata->getData('sku');

echo "$theitemskunumber_is";


all the products that are last in each row show the correct sku.



Yet if I use a the same code but call in a custom attribute it doesnt show . correctly on the last item in the row?










share|improve this question
























  • You can use by js because this is highly cached page.

    – Sohel Rana
    5 hours ago











  • I am not sure what use by js means?

    – Jayreis
    5 hours ago











  • javascript = js

    – Sohel Rana
    4 hours ago

















0















I have a magento2 based website and I am wanting to show a custom attribute on the category listing page. My issue seems to be that on desktop and tablet the products are shown 3 across and on mobile they are shown 2 across.



Now if the last item in the row shouldn't show the custom attribute (or has no value set for the custom attribute) it still shows the prior products custom attribute value.



Below is my code. I know using Object Manager in the php file is not the ideal. the php file edited is



 Magento_Catalog/templates/product/price/final_price.phtml

//THIS CODE WILL HELP US WRITE TEXT UNDER THE PRICE SUCH AS BOGO, ETC
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Has you can see I even tried using the unset() function before I call in the custom attribute. However no matter what I do the very next product after the product that has a value for the custom attribute if the net product does not have a value it shows the prior products value(s).



Its odd because if I do



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
$theitemskunumber_is = $_productdata->getData('sku');

echo "$theitemskunumber_is";


all the products that are last in each row show the correct sku.



Yet if I use a the same code but call in a custom attribute it doesnt show . correctly on the last item in the row?










share|improve this question
























  • You can use by js because this is highly cached page.

    – Sohel Rana
    5 hours ago











  • I am not sure what use by js means?

    – Jayreis
    5 hours ago











  • javascript = js

    – Sohel Rana
    4 hours ago













0












0








0








I have a magento2 based website and I am wanting to show a custom attribute on the category listing page. My issue seems to be that on desktop and tablet the products are shown 3 across and on mobile they are shown 2 across.



Now if the last item in the row shouldn't show the custom attribute (or has no value set for the custom attribute) it still shows the prior products custom attribute value.



Below is my code. I know using Object Manager in the php file is not the ideal. the php file edited is



 Magento_Catalog/templates/product/price/final_price.phtml

//THIS CODE WILL HELP US WRITE TEXT UNDER THE PRICE SUCH AS BOGO, ETC
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Has you can see I even tried using the unset() function before I call in the custom attribute. However no matter what I do the very next product after the product that has a value for the custom attribute if the net product does not have a value it shows the prior products value(s).



Its odd because if I do



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
$theitemskunumber_is = $_productdata->getData('sku');

echo "$theitemskunumber_is";


all the products that are last in each row show the correct sku.



Yet if I use a the same code but call in a custom attribute it doesnt show . correctly on the last item in the row?










share|improve this question
















I have a magento2 based website and I am wanting to show a custom attribute on the category listing page. My issue seems to be that on desktop and tablet the products are shown 3 across and on mobile they are shown 2 across.



Now if the last item in the row shouldn't show the custom attribute (or has no value set for the custom attribute) it still shows the prior products custom attribute value.



Below is my code. I know using Object Manager in the php file is not the ideal. the php file edited is



 Magento_Catalog/templates/product/price/final_price.phtml

//THIS CODE WILL HELP US WRITE TEXT UNDER THE PRICE SUCH AS BOGO, ETC
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Has you can see I even tried using the unset() function before I call in the custom attribute. However no matter what I do the very next product after the product that has a value for the custom attribute if the net product does not have a value it shows the prior products value(s).



Its odd because if I do



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
$theitemskunumber_is = $_productdata->getData('sku');

echo "$theitemskunumber_is";


all the products that are last in each row show the correct sku.



Yet if I use a the same code but call in a custom attribute it doesnt show . correctly on the last item in the row?







magento2 catalog custom-attributes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago







Jayreis

















asked 5 hours ago









JayreisJayreis

312933




312933












  • You can use by js because this is highly cached page.

    – Sohel Rana
    5 hours ago











  • I am not sure what use by js means?

    – Jayreis
    5 hours ago











  • javascript = js

    – Sohel Rana
    4 hours ago

















  • You can use by js because this is highly cached page.

    – Sohel Rana
    5 hours ago











  • I am not sure what use by js means?

    – Jayreis
    5 hours ago











  • javascript = js

    – Sohel Rana
    4 hours ago
















You can use by js because this is highly cached page.

– Sohel Rana
5 hours ago





You can use by js because this is highly cached page.

– Sohel Rana
5 hours ago













I am not sure what use by js means?

– Jayreis
5 hours ago





I am not sure what use by js means?

– Jayreis
5 hours ago













javascript = js

– Sohel Rana
4 hours ago





javascript = js

– Sohel Rana
4 hours ago










1 Answer
1






active

oldest

votes


















1














Try following way:




$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Note: Avoid to use object manager directly and avoid to load product that will impact your page speed.






share|improve this answer























  • Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

    – Jayreis
    4 hours ago












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272322%2fmagento2-showing-a-custom-attribute-on-category-listing-page%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try following way:




$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Note: Avoid to use object manager directly and avoid to load product that will impact your page speed.






share|improve this answer























  • Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

    – Jayreis
    4 hours ago
















1














Try following way:




$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Note: Avoid to use object manager directly and avoid to load product that will impact your page speed.






share|improve this answer























  • Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

    – Jayreis
    4 hours ago














1












1








1







Try following way:




$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Note: Avoid to use object manager directly and avoid to load product that will impact your page speed.






share|improve this answer













Try following way:




$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_productdata = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
unset($promo_text);
$promo_text = $_productdata->getData('promo_text');
$promo_text_start_date = $_productdata->getData('promo_text_start_date');
$promo_text_end_date = $_productdata->getData('promo_text_end_date');
$todays_datefor_promo_text = date('Y-m-d h:i:s');

if($promo_text !='')


if($todays_datefor_promo_text >= "$promo_text_start_date 00:00:00" && $todays_datefor_promo_text <= "$promo_text_end_date 11:59:59")

echo "<p class='bogotextcolor'>$promo_text</p>";




Note: Avoid to use object manager directly and avoid to load product that will impact your page speed.







share|improve this answer












share|improve this answer



share|improve this answer










answered 4 hours ago









Sohel RanaSohel Rana

23.5k34461




23.5k34461












  • Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

    – Jayreis
    4 hours ago


















  • Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

    – Jayreis
    4 hours ago

















Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

– Jayreis
4 hours ago






Thank you Sohel Rana. So I guess i will look up the difference between $objectManager->create and $objectManager->get

– Jayreis
4 hours ago


















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272322%2fmagento2-showing-a-custom-attribute-on-category-listing-page%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

六本木駅

Integral that is continuous and looks like it converges to a geometric seriesTesting if a geometric series converges by taking limit to infinitySummation of arithmetic-geometric series of higher orderGeometric series with polynomial exponentHow to Recognize a Geometric SeriesShowing an integral equality with series over the integersDiscontinuity of a series of continuous functionsReasons why a Series ConvergesSum of infinite geometric series with two terms in summationUsing geometric series for computing IntegralsLimit of geometric series sum when $r = 1$

Joseph Lister