Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento get all products

I am trying to get the entire magento product collection, without any filters or restrictions, but I fail to get all products.

I've tried various methods already, but they all give me a very limited selection of products. Let's say the store contains 5000 products, but it only shows 500. When I check the catalog -> products is does show me the entire list.

Mage::getModel('catalog/product')->getCollection();
Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
Mage::getModel("catalog/product")->getResourceCollection()->load();

All of them return the same amount (500), while I expect it to give me 5000 products. I would prefer not to use Zend or PHP and just stick to the Magento way to get them.

Does anyone know how to really get ALL products or can point me in the right direction why this isn't working?

The select-string that is returned is:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id` FROM `catalog_product_flat_4` AS `e`
like image 569
JNDPNT Avatar asked Jan 16 '12 13:01

JNDPNT


3 Answers

//to overwrite limit but you need first to increase your memory limit

 $collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)

// we iterate through the list of products to get attribute values
foreach ($collection as $product) {
  echo $product->getName(); //get name
  echo (float) $product->getPrice(); //get price as cast to float
  echo $product->getDescription(); //get description
  echo $product->getShortDescription(); //get short description
  echo $product->getTypeId(); //get product type
  echo $product->getStatus(); //get product status

  // getCategoryIds(); returns an array of category IDs associated with the product
  foreach ($product->getCategoryIds() as $category_id) {
      $category = Mage::getModel('catalog/category')->load($category_id);
      echo $category->getName();
      echo $category->getParentCategory()->getName(); // get parent of category
  }
  //gets the image url of the product
  echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
      'catalog/product'.$product->getImage();
  echo $product->getSpecialPrice();
  echo $product->getProductUrl();  //gets the product url
  echo '<br />';
}
like image 104
ashraf mohammed Avatar answered Nov 11 '22 07:11

ashraf mohammed


And something like this:

$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $prod) {
$product = Mage::getModel('catalog/product')->load($prod->getId());
}

With this method I get more than 500 but all my product...

like image 26
Alexandre Avatar answered Nov 11 '22 08:11

Alexandre


Several possibilities here: 1. Some inner limitation, like 500 at all. 2. Some paging limitation. Products per page(in db abstract) 3. Some lazyload limitation.

Perhaps, there is some over problem, but I think this is some inner limit.

like image 5
Jevgeni Smirnov Avatar answered Nov 11 '22 09:11

Jevgeni Smirnov