Magento 1.9 PHP Collection – How to Get Metadescription of Every Product

collection;magento-1.9PHP

I have made a new Controller and inside there a new Action in which I want to be able to get the metadescription of every product. My code snippet is the following:

public function metaDescriptionAction()
{
    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
    foreach ($collection as $product) {
        var_dump($product->getData());
    }
}

But I can't see any information associated with metadescription in the output. What I'm getting is:

array (size=52)
'entity_id' => string '20869' (length=5)
 'type_id' => string 'configurable' (length=12)
 'attribute_set_id' => string '4' (length=1)
 'color' => null
 'color_value' => null
 'cost' => null
 'created_at' => string '2016-05-21 07:58:42' (length=19)
 'gift_message_available' => null
 'has_options' => string '1' (length=1)
 'image_label' => null
 'is_recurring' => null
 'links_exist' => null
 'links_purchased_separately' => null
 'links_title' => null
 'msrp' => null
 'msrp_display_actual_price_type' => null
 'msrp_enabled' => null
 'name' => string 'Jean καμπάνα με patchwork' (length=34)
 'news_from_date' => null
 'news_to_date' => null
 'price' => string '99.9000' (length=7)
 'price_type' => null
 'price_view' => null
 'recurring_profile' => null
 'required_options' => string '1' (length=1)
 'shipment_type' => null
 'short_description' => string 'Jean καμπάνα με patchwork' (length=34)
 'sku' => string '9905202' (length=7)
 'sku_type' => null
 'small_image' => null
 'small_image_label' => null
 'special_from_date' => null
 'special_price' => string '30.0000' (length=7)
 'special_to_date' => null
 'status' => string '1' (length=1)
 'tax_class_id' => string '2' (length=1)
 'thumbnail' => null
 'thumbnail_label' => null
 'updated_at' => string '2017-03-27 10:58:54' (length=19)
 'url_key' => string 'jean-kampana-me-patchwork' (length=25)
 'url_path' => string 'jean-kampana-me-patchwork.html' (length=30)
 'visibility' => string '4' (length=1)
 'weight' => null
 'weight_type' => null
 'size' => string '435' (length=3)
 'size_value' => string 'XL-14' (length=5)
 'barcode' => string '9905202' (length=7)
 'cvg_smartprice' => null
 'season' => string '20' (length=2)
 'season_value' => string 'ΧΕΙΜΩΝΑΣ ' (length=17)
 'is_salable' => string '0' (length=1)
 'stock_item' => 
   object(Varien_Object)[61]
     protected '_data' => 
      array (size=1)
        'is_in_stock' => string '0' (length=1)
    protected '_hasDataChanges' => boolean false
  protected '_origData' => null
  protected '_idFieldName' => null
  protected '_isDeleted' => boolean false
  protected '_oldFieldsMap' => 
    array (size=0)
      empty
  protected '_syncFieldsMap' => 
    array (size=0)
      empty

Any help would be appreciated. Thank you

Best Answer

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect(array('meta_title','meta_description'));

foreach ($collection as $product) { 
    print_r($product->getData()); 
}

output

Array ( [entity_id] => 231 [entity_type_id] => 4 [attribute_set_id] => 13 [type_id] => simple [sku] => msj000 [has_options] => 0 [required_options] => 0 [created_at] => 2013-03-05 10:48:12 [updated_at] => 2017-07-07 11:35:03 [meta_title] => fgdg [meta_description] => dfgfdgf [is_salable] => 1 [stock_item] => Varien_Object Object ( [_data:protected] => Array ( [is_in_stock] => 1 ) [_hasDataChanges:protected] => [_origData:protected] => [_idFieldName:protected] => [_isDeleted:protected] => [_oldFieldsMap:protected] => Array ( ) [_syncFieldsMap:protected] => Array ( ) ) )

Related Topic