How do you get a collection of products that do not have a name attribute set for a specific store?


in .phtml

   $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
    $collection = $productCollection->create()
      ->addAttributeToSort('created_at', 'DESC')
  • Does this work for Magento 1.9.x? Looks like Magento 2 code. – Matija Jan 15 at 11:16

Maybe you should try this :

$products = Mage::getModel('catalog/product')->getCollection();
// Put in the array below the attributes you want to select
// Join to get the name
$nameAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'name');
$nameTable = $nameAttribute->getBackendTable();
$nameId = $nameAttribute->getAttributeId();
// Get default store status value (optionnal)
    array('nt' => $nameTable),
    'nt.attribute_id=' . $nameId . ' AND nt.entity_id = e.entity_id AND nt.store_id = 0',
    array('name_default' => new Zend_Db_Expr('nt.value'))
// Get specific store values
    array('nts' => $nameTable),
    'nts.attribute_id=' . $nameId . ' AND nts.entity_id = e.entity_id AND nts.store_id > 0',
    array('name_specific' => new Zend_Db_Expr('nts.value'))
// Select only if no store specific value
$products->getSelect()->where('nts.value is null');

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.