cancel
Showing results for 
Search instead for 
Did you mean: 

Error while trying to run data patch, Invalid argument supplied for foreach() in PatchRegistry.php

Error while trying to run data patch, Invalid argument supplied for foreach() in PatchRegistry.php

Hello,

 

I'm trying to create a store and its store view programatically, but when running php bin/magento setup:upgrade, it produces Invalid argument error. Besides this, before running setup:upgrade, there were GroupFactory and StoreFactory classes in Magento\Store\Model\ namespace, but now they just disappeared.

 

This is the method in my patch class:

use Magento\Store\Model\Website;
use Magento\Store\Model\StoreFactory;
use Magento\Store\Model\GroupFactory;

public function
createStores()
{
// load default website
$defaultWebId = $this->defaultWebsite->load(self::DEFAULT_WEB_ID);

// create english group
$englishGroup = $this->groupFactory->create();
$englishGroup->setName("englishGroup");
$englishGroup->setCode("Task5EnglishGroup");
$englishGroup->setWebsite($defaultWebId);
$englishGroup->setRootCategoryId(self::DEFAULT_ROOT_CATEGORY);

// create german group
$germanGroup = $this->groupFactory->create();
$germanGroup->setName("germanGroup");
$germanGroup->setCode("Task5GermanGroup");
$germanGroup->setWebsite($this->defaultWebsite);
$germanGroup->setRootCategoryId(self::DEFAULT_ROOT_CATEGORY);

// create german store view
$germanStore = $this->storeFactory->create();
$germanStore->setName("germanStoreView");
$germanStore->setCode("Task5GermanView");
$germanStore->setGroup($germanGroup);

// create english store view
$englishStore = $this->storeFactory->create();
$englishStore->setName("englishStoreView");
$englishStore->setCode("Task5EnglishStoreView");
$englishStore->setGroup($englishGroup);
$englishStore->setCurrentCurrencyCode("GBP");
}
 

Any kind of help would be appreciated.

 

This is the error:

Warning: Invalid argument supplied for foreach() in /home/hgresa/Desktop/magento-projects/my-app/vendor/magento/framework/Setup/Patch/PatchRegistry.php on line 144

1 REPLY 1

Re: Error while trying to run data patch, Invalid argument supplied for foreach() in PatchRegistry.p

Just fixed it, the problem was that my getDependencies and getAliases methods were not returning anything and PatchRegistry patch excepted arrays.