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

  • SEARCH
  • Home
  • 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 9012249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:56:52+00:00 2026-06-16T02:56:52+00:00

For a backend module I have the need to check if a product id

  • 0

For a backend module I have the need to check if a product id is valid, that is: is there a product with that id? I’ve found two solutions for that, but I’m not very happy with either one:

  1. Directy query the catalog_product_entity table. Very fast but definitely not very elegant and I fear there might be issues I’m not aware of.

  2. Use the following code:

    $product = Mage::getModel('catalog/product')->load($productID)
    if ($product->getId()) {
      //valid id
    }
    else {
      //not a valid id
    }
    

    This should work but it’s painfully slow, because I have to check several IDs at once. And since I don’t need the actual product data, it doesn’t really make sense to load it.

Any better suggestions?

  • 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-16T02:56:53+00:00Added an answer on June 16, 2026 at 2:56 am

    Thanks benmarks and james, you’ve pointed me in the right direction and I just combined your approches:

    $productIds = array(16,17,18,19,290993,25    /*...*/);
    
    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->addFieldToFilter('entity_id',array('in'=>$productIds));
    
    $foundIds = $collection->getAllIds();
    
    var_dump($foundIds); /* each array value should be a valid ID */
    

    For some reason, getAllIds() returns Ids as strings rather than ints, but that’s fine.

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

Sidebar

Related Questions

I have created a module in backend application. need to remove the 'new' action,
I made a grid in magento backend module but there's an error: SQLSTATE[42000]: Syntax
I have built a backend system that allows a user to add multiple content
I have a backend class that has to raise an event with no arguments.
There is an existing third-party module that overrides existing Mage functionalities. Let's call it
I have a form in a backend module making use of some dynamically created
I have some backend functionality which need to be written in C# (for political,
I have some node.js code using jsdom and I need jquery.min.js file for backend
I have a project that consists of several nod.js backend applications. The apps are
I am working on a X-Cart Module. I need the backend configuration values to

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.