cancel
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.

2 REPLIES 2

Re: How can I export SKUs from a particular Category

@aalpdownie3f94 

 

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
https://www.manishmittal.com/

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.

<?php
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);
Mage::app();
$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();
        }
        else
        {            $catname = $category->getName();
        }
    }    $categoryIds = implode('|', $product->getCategoryIds());//change the category separator if needed    fputcsv($fp, array($sku,$proname, $categoryIds,$catname), ",");
}fclose($fp);
?>

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

Problem solved? Click Accept as Solution!