Question

I have spent hours trying to find how to get a simple thing like all products - including the disabled ones.

My apologies , this is such an old version! I have looked up most of the posts on stack exchange etc to do this. the closest I have got is This post

In my code below , $products and $allProducts give me exactly the same amount , leaving out 200+ disabled products.

  • This is Magento 1.3

  • I do have flat catalog product & category switched on , and I want to run this script fairly regularly and don't want to have to switch it off.

  • I have read several other stack overflow etc. posts that don't work either.

Any Ideas how I can get all products in Magento 1.3 including the disabled ones?

<?php

header('Content-Type: application/json');
error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once('./app/Mage.php');
Mage::app();

$storeId = Mage::app()->getStore()->getId();

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSort('created_at', 'DESC')
    ->load();



$allProducts = Mage::getResourceModel('catalog/product_collection');

echo $products->getSize();
echo $allProducts->getSize();

?>
Was it helpful?

Solution

Try following way:


$newStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load($newStoreId));

$productCollection = $category->getProductCollection()->addAttributeToSelect('*');

Now you will able to get all products. But one problem here, that is product url. So use following code if you need url as well:


Mage::app()->setCurrentStore('default');
foreach ($productCollection as $product) {

}

OTHER TIPS

Try to use this code. You'll get disabled product collection using this code.

$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top