Magento2 Showing a custom attribute on category listing pageMagento2.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

What is the relationship between spectral sequences and obstruction theory?

Checks user level and limit the data before saving it to mongoDB

Is DC-DC (24v to 12v) Buck Conversion typically more efficient than AC-DC (110v to 12v) conversion?

How exactly does Hawking radiation decrease the mass of black holes?

If a warlock with the Repelling Blast invocation casts Eldritch Blast and hits, must the targets always be pushed back?

How did Captain America manage to do this?

Does this extra sentence in the description of the warlock's Eyes of the Rune Keeper eldritch invocation appear in any official reference?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

How could Tony Stark make this in Endgame?

Is there a way to get a compiler for the original B programming language?

Term for maladaptive animal behavior that will lead to their demise?

Examples of non trivial equivalence relations , I mean equivalence relations without the expression " same ... as" in their definition?

Uniformly continuous derivative implies existence of limit

What happened to Captain America in Endgame?

Fizzy, soft, pop and still drinks

What is the incentive for curl to release the library for free?

How to stop co-workers from teasing me because I know Russian?

Stop and Take a Breath!

The Defining Moment

What do the phrase "Reeyan's seacrest" and the word "fraggle" mean in a sketch?

How to make a pipeline wait for end-of-file or stop after an error?

Is contacting this expert in the field something acceptable or would it be discourteous?

Can someone publish a story that happened to you?

Critique of timeline aesthetic



Magento2 Showing a custom attribute on category listing page


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
    Apr 24 at 16:03











  • I am not sure what use by js means?

    – Jayreis
    Apr 24 at 16:07











  • javascript = js

    – Sohel Rana
    Apr 24 at 16:10

















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
    Apr 24 at 16:03











  • I am not sure what use by js means?

    – Jayreis
    Apr 24 at 16:07











  • javascript = js

    – Sohel Rana
    Apr 24 at 16:10













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 Apr 24 at 16:19







Jayreis

















asked Apr 24 at 15:50









JayreisJayreis

312933




312933












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

    – Sohel Rana
    Apr 24 at 16:03











  • I am not sure what use by js means?

    – Jayreis
    Apr 24 at 16:07











  • javascript = js

    – Sohel Rana
    Apr 24 at 16:10

















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

    – Sohel Rana
    Apr 24 at 16:03











  • I am not sure what use by js means?

    – Jayreis
    Apr 24 at 16:07











  • javascript = js

    – Sohel Rana
    Apr 24 at 16:10
















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

– Sohel Rana
Apr 24 at 16:03





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

– Sohel Rana
Apr 24 at 16:03













I am not sure what use by js means?

– Jayreis
Apr 24 at 16:07





I am not sure what use by js means?

– Jayreis
Apr 24 at 16:07













javascript = js

– Sohel Rana
Apr 24 at 16:10





javascript = js

– Sohel Rana
Apr 24 at 16:10










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
    Apr 24 at 16:45












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
    Apr 24 at 16:45
















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
    Apr 24 at 16:45














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 Apr 24 at 16:34









Sohel RanaSohel Rana

23.6k34461




23.6k34461












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

    – Jayreis
    Apr 24 at 16:45


















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

    – Jayreis
    Apr 24 at 16:45

















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

– Jayreis
Apr 24 at 16:45






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

– Jayreis
Apr 24 at 16:45


















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

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?