0

Due to a migration, some products have a wrong (not existing) attribute group.

Is there a simple way to change this with a SQL query?

If yes, where can I see wich attribute-group is wich...

  • This is the 'error' i get in the reports: a:4:{i:0;s:48:"No such entity with attributeSetId = 31";i:1;s:9778:"#0 /home/...../domains/......./public_html/vendor/magento/module-eav/Model/Attribute/GroupRepository.php(116): Magento\Framework\Exception\NoSuchEntityException::singleField('attributeSetId', '31') ...... – Paul Kuijten May 18 '18 at 7:01
0

You can create setup script in custom module or run provided code in custom controller

namespace Vendorname\Modulename\Setup;

use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface {

/**
 * Installs data for a module
 *
 * @param ModuleDataSetupInterface $setup
 * @param ModuleContextInterface $context
 * @return void
 */
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $setup->startSetup();

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

    $collection = $productCollection->create()
                ->addAttributeToSelect('*')
                ->load();
    foreach ($collection as $product){
         $product->getId();
         $productData = $objectManager->create('\Magento\Catalog\Model\Product')->load($product->getId());
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->set(/*your attribute set id*/); 
    //OR 
    $attributeSetRepository = $attributeSet->getAttributeSetName("attributeSetName");
    $productData->save();
    } 

    $setup->endSetup();
}

}

|improve this answer|||||
  • Sorry for being a noob but how do i actually do that? I't for Magento 2 btw – Paul Kuijten May 18 '18 at 8:55
  • its for magento2 , you can use this script in any module or custom module or else you can create custom controller and execute it with code , just remove startsetup and endsetup from code – jayjit gatha May 18 '18 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.