Magento2 how to developed custom script export for a configurable product with associated sku please if anyone creates the script to share with me as soon as.i attched screenshot for get export csv like this
-
Please share script if result need that csv format likeRv Singh– Rv Singh2018-05-16 05:45:52 +00:00Commented May 16, 2018 at 5:45
Add a comment
|
2 Answers
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$registry = $objectManager->get('Magento\Framework\Registry');
$registry->register('isSecureArea', true);
// Store id of exported products, This is useful when we have multiple stores.
$store_id = 1;
$fp = fopen("export.csv","w+");
$collection = $objectManager
->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')
->create()->addStoreFilter($store_id)
->addAttributeToFilter('type_id', 'configurable')
->addAttributeToSelect(array('name','sku','associated_skus'));
foreach ($collection as $product) {
$data = array();
$data[] = $product->getTypeId();
$data[] = $product->getName();
$data[] = $product->getSku();
$child_products = $product->getTypeInstance()->getUsedProducts($product, null);
if (count($child_products) > 0) {
$resultstr = array();
foreach($child_products as $child) {
$resultstr[] = $child->getSku();
}
echo $data[] = implode(',', $resultstr);
}
fputcsv($fp, $data);
}
fclose($fp);
Create one php file inside your magento root directory with below code.
<?php
require './app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$_objectManager = $bootstrap->getObjectManager();
$state = $_objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('admin');
$registry = $_objectManager->get('Magento\Framework\Registry');
$registry->register('isSecureArea', true);
//Store id of exported products, This is useful when we have multiple stores.
$store_id = 1;
$fp = fopen("export.csv","w+");
$collection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create()->addStoreFilter($store_id)->addAttributeToFilter('type_id', 'configurable')->addAttributeToSelect(array('name','sku'));
foreach ($collection as $product)
{
$data = array();
$data[] = $product->getTypeId();
$data[] = $product->getName();
$data[] = $product->getSku();
fputcsv($fp, $data);
$child_products = $product->getTypeInstance()->getUsedProducts($product, null);
if(count($child_products) > 0)
{
foreach($child_products as $child)
{
$data = array();
$data[] = $child->getTypeId();
$data[] = $child->getName();
$data[] = $child->getSku();
fputcsv($fp, $data);
}
}
}
fclose($fp);
-
You can find export.csv inside root directory.Bhavin iFlair– Bhavin iFlair2018-05-15 14:33:37 +00:00Commented May 15, 2018 at 14:33
-
how can i import configurable product with associated custom script in magento2Rv Singh– Rv Singh2018-06-18 09:55:57 +00:00Commented Jun 18, 2018 at 9:55
-
How to custom script through export only configurable_variations if you have idea reply meRv Singh– Rv Singh2019-01-16 06:24:42 +00:00Commented Jan 16, 2019 at 6:24
-
They give me error like. Call to undefined method Magento\Catalog\Model\Product\Type\Simple::getUsedProducts()Nikul– Nikul2019-08-20 06:33:21 +00:00Commented Aug 20, 2019 at 6:33