0

Sorry for my English.

I have this code.

 $productCollection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter('attribute_set_id',array(12,4))
        ->joinField(
            'qty',
            'cataloginventory/stock_item',
            'qty',
            'product_id=entity_id',
            '{{table}}.stock_id=1',
            'left'
        )
        ->addAttributeToFilter('qty', array("gt" => 0))
        ->setPageSize(500)
        ->load();

    var_dump($productCollection->getData());

I need get a product name , and I use this ->addAttributeToSelect('name') on my collection, but My collection don't return the data.

in attribute settings, I have this

enter image description here

How can I get all the product data in general?

1

Extending beyond my original answer here are some of the things you can do with product collections. Mixture of filters and functionality to fetch more data.

// Load Product Collection
$collection = Mage::getModel('catalog/product')->getCollection();
$collection = Mage::getResourceModel('catalog/product_collection');
// only products which are visible in frontend
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
// Only Enabled products remain in the collection
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
// Only products that are in stock
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
// Add All Product Attributes
$collection->addAttributeToSelect('*');
// Add Individual Product Attributes
$collection->addAttributeToSelect('name', 'description', 'brand');
// Add Specific Price Attributes
$collection->addMinimalPrice();
$collection->addFinalPrice();
$collection->addTaxPercents();
// Add Category IDs to Products
$collection->addCategoryIds();
// Add Tier Pricing Info
$collection->addTierPriceData();
// Add Product URL Rewrites
$collection->addUrlRewrite();
// Or (Wrong?)
$collection->addAttributeToFilter(
    array('status', 'status'),
    array(array('neq' => 1), array('null' => true))
)
// Or
$collection->addAttributeToFilter(array(
    array(
        'attribute' => 'download_link',
        'null'      => true,
    ),
    array(
        'attribute' => 'download_link',
        'eq'        => '',
    ),
));
// Filter Collection
// Is Equal To
$collection->addAttributeToFilter('status', array('eq' => 1));
// Is Not Equal To
$collection->addAttributeToFilter('visibility', array('neq' => 1));
// Greater Than
$collection->addAttributeToFilter('price', array('gt' => 3));
// Less Than
$collection->addAttributeToFilter('price', array('lt' => 3));
// Greater Than or Equal To
$collection->addAttributeToFilter('price', array('gteq' => 4));
// Less Than or Equal To
$collection->addAttributeToFilter('price', array('lteq' => 4));
// Contains – with % wildcards
$collection->addAttributeToFilter('sku', array('like' => 'DVD%'));
// Does Not Contain – with % wildcards
$collection->addAttributeToFilter('sku', array('nlike' => 'ABC%'));
// In Array
$collection->addAttributeToFilter('entity_id', array('in' => array(1,3,12)));
// Not In Array
$collection->addAttributeToFilter('entity_id', array('nin' => array(1,2,12)));
// Is NULL
$collection->addAttributeToFilter('description', 'null');
$collection->addAttributeToFilter('description', array('null' => true));
// Is Not NULL
$collection->addAttributeToFilter('description', 'notnull');
$collection->addAttributeToFilter('description', array('notnull' => true));
// Further Filtering
// Filter by Product IDs
$collection->addIdFilter(array(4,5,6));
// Filter by Current Store
$collection->addStoreFilter();
// Filter by Current Website
$collection->addWebsiteFilter();
// Filter by Category
$collection->setStoreId($id)->addCategoryFilter($category)
// Sort Collection
// er by Attribute Ascending
$collection->setOrder('price', 'ASC');
// er by Attribute Descending
$collection->setOrder('name', 'DESC');
// Random Order
$collection->setOrder('rand()');
// Limit Collection
$collection->setPageSize(10);
$collection->setCurPage(1);
// Count Results
$collection->count();
// Return Only Product IDs
$collection->getAllIds();
// Debug Collection
$collection->getSelect();
// Static type strings
Mage_Catalog_Model_Product_Type::TYPE_SIMPLE
Mage_Catalog_Model_Product_Type::TYPE_BUNDLE
Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
Mage_Catalog_Model_Product_Type::TYPE_GROUPED
Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL
Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE
0

Try this

$collection
$productCollection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*');
        ->addAttributeToFilter('attribute_set_id',array(12,4))
        ->joinField(
            'qty',
            'cataloginventory/stock_item',
            'qty',
            'product_id=entity_id',
            '{{table}}.stock_id=1',
            'left'
        )
        ->addAttributeToFilter('qty', array("gt" => 0))
        ->setPageSize(500)
        ->load();
  • it doesn't work either. ->addAttributeToSelect does not work at all – Denis Maksiura Jun 15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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