0

Is it possible to get a products attributes collection and filter that by name? I want all attributes of a product that end with _whatever.

Possible?

0
$productCollection = Mage::getModel('catalog/product')
                        ->getCollection() 
                        ->addAttributeToSelect('name')
                        ->addAttributeToFilter('name', array('like' => '%'.'_whatever'));
  • Thanks, but I dont want products that have that attribute set. I want to get those attributes from a product that have a name that ends with _whatever. So basically I have a product object and want to go from there. – Arnie May 29 '18 at 6:58
  • which attribute set, you don't want in collection?? – MR.R DNATH May 29 '18 at 8:05
0

Yes, You can Use like this

$_products = Mage::getResourceModel('catalog/product_collection')
             ->addAttributeToSelect('*')
            ->addAttributeToFilter('name', array('like' => '%'.$name.'_whatever'.'%'))
            ->load();
0

Try to use this code :

$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('name', array('like' => '%'.$name.'_whatever'.'%'));
0

Try below code to display product object with all attribute

$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('name', array('like' => '%'.'_whatever'));

IF you don't want specific attribute set in collection use below code

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('name', array('like' => '%'.'_whatever'))
    ->addAttributeToFilter('attribute_set_id',array('nin' => array($setId))); //$setId is 4 as example

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.