1

So like alot of other people, im building my first Magento custom module - and im trying to make a list of the products in my store. I have worked most of it out by now, but im having a problem when im trying to retrieve the data from my database.

I have googled to my skin starter to fall off, and i have read (and tried) most of the suggestions on stackoverflow - from older posts.

my current Model class looks like this:

public function getRecentProducts()
{
    $categoryID = 4;
    $category = Mage::getModel('catalog/category')->load($categoryID);
    $productCollection = Mage::getResourceModel('catalog/product_collection')
        ->addCategoryFilter($category);
    //$test = Mage::getModel('catalog/product')
    // ->getCollection->()addAttributeToSelect('*');       
    return $products;
}

I checked to make sure i get the correct category with xdebug, and its defently the category im looking for - but sadly thats where it stops to work :( No matter what i try, when i try to retreieve products it returns the array with _data = Null (using the //$test returns exactly the same

I hope somebody can help me, because im about to go crazy from this


P.s i reindexed all the index's, and tried to delete the caches aswell - neither helps

2
  • how can you return $products if you haven't declared it? wouldn't that throw an error?
    – Robin
    Nov 12, 2015 at 14:26
  • think i failed to do the proper "redo" while trying to get back to something :) it was obviously supposed to have been return $productCollection
    – Mac
    Nov 12, 2015 at 15:34

1 Answer 1

1

Can you find the product ids in the catalog_category_product table? What does the select statement look like?

It should be: SELECT e.*, cat_pro.position AS cat_index_position FROM catalog_product_entity AS e INNER JOIN catalog_category_product AS cat_pro ON cat_pro.product_id=e.entity_id AND cat_pro.category_id='x'

(x = cat id)

2
  • Yeah, im able to find my products in the catalog_catagory_product table. in my database - with correct IDs
    – Mac
    Nov 12, 2015 at 11:29
  • And the select statement is also equal to what I've posted? Have you tried running the select statement in the DB?
    – CCK1979
    Nov 13, 2015 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.