Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:33:01+00:00 2026-06-09T00:33:01+00:00

Yesterday I wrote some code to pull a collection of products. This code worked

  • 0

Yesterday I wrote some code to pull a collection of products. This code worked fine, however today, the code doe snot work, nothing has changed, I cannot understand why it won’t work.

This is what I coded

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('MPN')
->addAttributeToSelect('JAN')
->addAttributeToSelect('UPC')
->addFieldToFilter(array(
    array('attribute'=>'type_id','eq'=>'simple')
))
->setPage(1,10);
$collection->load();
foreach($collection as $item)
{

echo print_r($item->getdata());
}

Yesterday I was able to see a list of products that contained my MPN’s, JAN’s and UPC’s (these are custom attributes in the backend). Today they don’t load at all. It’s weird as hell, I think maybe my understanding of collections is not as good as I thought.

Any help would be much appreciated.


EDIT:

Refreshing the magento cache seemed to make everything work again. Does this mean that collection sometimes use the cache, is there some way I can write the code so that it does not use the cache?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:33:02+00:00Added an answer on June 9, 2026 at 12:33 am

    It depends where are you using your collection. If collection is used on the frontend and the Flat mode is turned on, then your attributes won’t be available, since they are not included into Flat index.

    To include them into flat index you need to add the following XML configuration into your config.xml file of the module

    <config>
        <frontend>
             <product>
                  <collection>
                       <attributes>
                          <MPN />
                          <JAN />
                          <UPC />
                       </attributes>
                  </collection>
              </product>
        </frontend>
    </config>
    

    In this case it will be available in the flat mode. Also by adding attributes into this XML node, your attributes also will be automatically added to all product list collections on the frontend.

    Have fun with Magento Development!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I wrote my first lines of code using the new dynamic type in
I'm new to Ant and wrote up a simple build.xml with some help yesterday.
I asked this question yesterday, but I wrote it far more complicated than I
Yesterday I wrote the following c# code (shortened a bit for legibility): var timeObjects
I'm writing this question with reference to this one which I wrote yesterday. After
Yesterday I updated to firefox 13 and I notice that this property is not
Yesterday, I could deploy my services perfectly fine to the hosted service instance on
when I first saw C#, I thought this must be some joke. I was
I posted this yesterday on SO, and I received an answer that works great,
I have a Javascript who works well, because yesterday i get here some very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.