0

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

0

in .phtml

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

Maybe you should try this :

$products = Mage::getModel('catalog/product')->getCollection();
// Put in the array below the attributes you want to select
$products->addAttributeToSelect(array('name'));
// 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)
$products->getSelect()->joinLeft(
    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
$products->getSelect()->joinLeft(
    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');
$products->getSelect()->group('e.entity_id');

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.