Magento get all products

佐手、 提交于 2019-12-03 03:27:49

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.

//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 />';
}

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...

Turn off your flat_catalog_product in admin > system > configuration > catalog > catalog. After this you will get a full product collection. Even though this is a workaround, it helped me to achieve what I needed to achieve.

You might be using Flat Catalog Product Structure . This create separate table for each store view.

Use Code below to print sql query . you will see the collection is coming from flat table like

catalog_product_flat_38

echo Mage::getModel('catalog/product')->getCollection()->getSelect();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!