Showing results for 
Search instead for 
Did you mean: 

How can I export SKUs from a particular Category


How can I export SKUs from a particular Category

Hi All,

I am needing to export all the SKUs that are sitting in a particular category. Does anyone know how I can do this? I am on Magento version 2.2.6.


Re: How can I export SKUs from a particular Category



By default categories product export option is not available with Magento 2.

But you can do like export a product with specific categories id.

go to system -> export -> products -> then in the entity attribute selection

select categories and add categories_id over there and then do export

it will export specific categories products.



Manish Mittal

Re: How can I export SKUs from a particular Category

Hi @aalpdownie3f94 


You need to create 1 file at root folder of magento files directory and create "catproexport.csv". And run the php file. So you can get the data in csv file "catproexport.csv". Also make sure you have write permission of that csv file.

error_reporting(E_ALL | E_STRICT);define('MAGENTO_ROOT', getcwd());$mageFilename = MAGENTO_ROOT . '/app/Mage.php';require_once $mageFilename;
Mage::setIsDeveloperMode(true);ini_set('display_errors', 1);
$categoryIds = array(2,4); // here you can write category id you want to export products from it.
$products = Mage::getModel("catalog/product")->getCollection();$products->addAttributeToSelect('category_ids');$products->addAttributeToFilter('status', 1);//optional for only enabled products$products->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search$products->addAttributeToSelect('*');$products->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left');$products->addAttributeToFilter('category_id', array('in' => $categoryIds));

$fp = fopen('catproexports.csv', 'w');$csvHeader = array("sku","name","category_ids","category_names");fputcsv( $fp, $csvHeader,",");
foreach ($products as $product){    $sku = $product->getSku();    $proname = $product->getName();    $catname = "";
    foreach ($product->getCategoryIds() as $id){        $category = Mage::getModel('catalog/category')->load($id); 

        if($catname != '')
        {            $catname = $catname . "," . $category->getName();
        {            $catname = $category->getName();
    }    $categoryIds = implode('|', $product->getCategoryIds());//change the category separator if needed    fputcsv($fp, array($sku,$proname, $categoryIds,$catname), ",");

It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!