PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 10, 2022

[FIXED] How to get a list of skus in magento

 May 10, 2022     magento, magento-1.9, product     No comments   

Issue

How to get a list of skus whiout using the looping in magento. Example: I am using below code with my conditons.

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

Now I want to result as array('A001','A002'....) etc. I don't want to iterate (loop) the product collection.

Please suggest.


Solution

If you want to retrieve the collection in that way, you will have to loop through the collection and retrieve the sku.

$skus = array();
foreach ($productsCollection as $product) {
    $skus[] = $product->getSku();
}

If you don't want that, you can just use a simple query because the SKU is kept in the catalog_product_entity table.

$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
$table = 'catalog_product_entity';
$q = "SELECT sku FROM {$table}";
$list = $conn->fetchOneFieldAll($q, 'sku');


Answered By - Marius
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing