3

How to display all Product Information in particular Attribute set like Product name , sku , attributes etc..

It shows Attribute Name & Id but i want all details like Product name , sku , attributes etc..

<?php
      require_once('app/Mage.php');
      umask(0);
      Mage::app();//->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
      $entityType = Mage::getModel('catalog/product')->getResource()->getTypeId();
      $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($entityType);
      $allSet = array();
      foreach($collection as $coll){
         $attributeSet['name'] = $coll->getAttributeSetName();
         $attributeSet['id'] = $coll->getAttributeSetId();
         $allSet[] = $attributeSet;
      }
      echo "<pre>";
      print_r($allSet);
      echo "</pre>";
?>
0

You can do it this way:

First, filter whatever attributes you need from the collection:

$_products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku')->addAttributeToSelect('name');

Then loop through these products and do what you want

foreach ($_products as $product){
    $sku = $product->getData('sku');
    echo $sku . '<br>';
     // generally
    $attribute = $product->getData('attribute');

}
|improve this answer|||||
  • I want based on attribute set – user31402 Feb 25 '16 at 9:09
0

To get a list of attributes for each attribute set you can use:

Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);

Try with this code:

        ...
        $entityType = Mage::getModel('catalog/product')->getResource()->getTypeId();
        $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($entityType);
        $allSet = array();
        foreach($collection as $coll){
            $attributeSet['name'] = $coll->getAttributeSetName();
            $attributeSet['id'] = $coll->getAttributeSetId();

            $attributeSet['attributes'] = Mage::getModel('catalog/product_attribute_api')->items($coll->getAttributeSetId());

            $allSet[] = $attributeSet;
        }

        echo "<pre>";
        print_r($allSet);
        echo "</pre>";
        ...
|improve this answer|||||
  • What i need to echo this – user31402 Feb 25 '16 at 11:24
  • Can you please be more clear? – Phoenix128_RiccardoT Feb 25 '16 at 11:29
  • let us assume i want to display in front end i created file in root path and then i call – user31402 Feb 25 '16 at 11:30
  • I'm sorry, I do not understand what you need. – Phoenix128_RiccardoT Feb 25 '16 at 11:31
  • 1
    Magento does not work this way. You need to create at least a module and a controller and include the above code inside. Otherwise just try to paste my code inside your script. But it is not the right way to do it. – Phoenix128_RiccardoT Feb 25 '16 at 11:35
0

==> Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model.

==> To instantiate a Product collection, do the following

$collection = Mage::getModel('catalog/product')->getCollection();

==> Products are a Magento EAV style Model, so you'll need to add on any additional attributes that you want to return.

$collection = Mage::getModel('catalog/product')->getCollection();

//fetch name and orig_price into data

$collection->addAttributeToSelect('name');  
$collection->addAttributeToSelect('orig_price'); 

==> There's multiple syntaxes for setting filters on collections. I always use the verbose one below, but you might want to inspect the Magento source for additional ways the filtering methods can be used.

==> The following shows how to filter by a range of values (greater than AND less than)

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');  
$collection->addAttributeToSelect('orig_price');   

//filter for products whose orig_price is greater than (gt) 100

$collection->addFieldToFilter(array(
    array('attribute'=>'orig_price','gt'=>'100'),
));

//AND filter for products whose orig_price is less than (lt) 130

 $collection->addFieldToFilter(array(
        array('attribute'=>'orig_price','lt'=>'130'),
    ));

While this will filter by a name that equals one thing OR another.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');  
$collection->addAttributeToSelect('orig_price');

//filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B

$collection->addFieldToFilter(array(
    array('attribute'=>'name','eq'=>'Widget A'),
    array('attribute'=>'name','eq'=>'Widget B'),        
));

A full list of the supported short conditionals (eq,lt, etc.) can be found in the _getConditionSql method in lib/Varien/Data/Collection/Db.php

Finally, all Magento collections may be iterated over (the base collection class implements on of the the iterator interfaces). This is how you'll grab your products once filters are set.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');  
$collection->addAttributeToSelect('orig_price');    

//filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B

$collection->addFieldToFilter(array(
    array('name'=>'orig_price','eq'=>'Widget A'),
    array('name'=>'orig_price','eq'=>'Widget B'),       
));

foreach ($collection as $product) {
    //var_dump($product);
    var_dump($product->getData());
}
|improve this answer|||||
0

Try below code..

Mage::getModel('catalog/product')->getCollection()->addAttributeToselect('*')->addAttributeToFilter('sku','value')->addAttributeToFilter('name','value')->addAttributeToFilter('attribute_set_id','setid');

This query will fetch data of all attribute & filter with the attribute name for the specific attribute set. If you don't want to get all attribute try this

Mage::getModel('catalog/product')->getCollection()->addAttributeToselect('sku')->addAttributeToselect('name')->addAttributeToFilter('sku','value')->addAttributeToFilter('name','value')->addAttributeToFilter('attribute_set_id','setid');
|improve this answer|||||

Your Answer

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