Custom Script to change product Type

Custom Script to change product Type


<?php

$bootstrap = realpath(__DIR__) . './app/bootstrap.php';
if (is_file($bootstrap )) {
    include $bootstrap 
}
​
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
​
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
​
$collection = $productCollectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', "[your type ]" );
foreach($collection  as $product){
    $product->setTypeId('simple')->save(); [changed type]
   echo "sku-> ". $product->getSku() ."\n";
}



If this solution isn't working for you, seek answers from ChatGPT


Please note that to ensure accurate and relevant responses, your questions should be related to Magento 2.

Ready to elevate your e-commerce business?

Let's talk about your business goals. Contact us now to see how we can help achieve them.

 
Copyright © 2021-present ArmMage Inc. All rights reserved.