Creating website programmaticallydata: current version - none, required version - 2.0.0Setup version for module 'Sample_CustomController' is not specifiedI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Unable to synchronized app import configuration failedNot able to add/update magento2 category post upgrade from 1.9 to 2.1.0Trying to uninstall moduleMagento 2 Front controller reached 100 router match iterations issueDeleted ShipperHQ module causing error in “All Customers” section of Magento 2“Area code is not set” in var/logwhen click on place order then paypal showing error in Magento2
What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?
How to draw a matrix with arrows in limited space
Why do Radio Buttons not fill the entire outer circle?
How to make money from a browser who sees 5 seconds into the future of any web page?
Why should universal income be universal?
Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?
C++ check if statement can be evaluated constexpr
What (the heck) is a Super Worm Equinox Moon?
15% tax on $7.5k earnings. Is that right?
Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?
Does the Linux kernel need a file system to run?
Quoting Keynes in a lecture
Can I cause damage to electrical appliances by unplugging them when they are turned on?
awk assign to multiple variables at once
Pre-mixing cryogenic fuels and using only one fuel tank
Multiplicative persistence
Doesn't the system of the Supreme Court oppose justice?
How many arrows is an archer expected to fire by the end of the Tyranny of Dragons pair of adventures?
What does Apple's new App Store requirement mean
What is the difference between lands and mana?
I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
What is Cash Advance APR?
Did the UK lift the requirement for registering SIM cards?
Creating website programmatically
data: current version - none, required version - 2.0.0Setup version for module 'Sample_CustomController' is not specifiedI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Unable to synchronized app import configuration failedNot able to add/update magento2 category post upgrade from 1.9 to 2.1.0Trying to uninstall moduleMagento 2 Front controller reached 100 router match iterations issueDeleted ShipperHQ module causing error in “All Customers” section of Magento 2“Area code is not set” in var/logwhen click on place order then paypal showing error in Magento2
I'm using magento 2.3. I'm trying to create a website through a custom command. Here's my code
$website = $this->websiteFactory->create();
$website->setName("foo")->setCode("foobar");
$website->save();
var_dump("expression");
This gives an error - Validation Failed. In Save.php line 59.
However, it does create the website.
If I remove $website->save(), "expression" is displayed.
Stack trace:
Exception #0 (MagentoFrameworkValidationValidationException): Validation Failed
#0 vendor/magento/module-inventory/Model/StockRepository.php(67): MagentoInventoryModelStockCommandSave->execute(Object(MagentoInventoryModelStock))
#1 vendor/magento/framework/Interception/Interceptor.php(58): MagentoInventoryModelStockRepository->save(Object(MagentoInventoryModelStock))
#2 vendor/magento/framework/Interception/Interceptor.php(138): MagentoInventoryModelStockRepositoryInterceptor->___callParent('save', Array)
#3 vendor/magento/framework/Interception/Interceptor.php(153): MagentoInventoryModelStockRepositoryInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoInventoryModelStock))
#4 generated/code/Magento/Inventory/Model/StockRepository/Interceptor.php(26): MagentoInventoryModelStockRepositoryInterceptor->___callPlugins('save', Array, Array)
#5 vendor/magento/module-inventory-sales/Plugin/Store/Model/ResourceModel/Website/AssignWebsiteToDefaultStockPlugin.php(100): MagentoInventoryModelStockRepositoryInterceptor->save(Object(MagentoInventoryModelStock))
#6 vendor/magento/framework/Interception/Interceptor.php(146): MagentoInventorySalesPluginStoreModelResourceModelWebsiteAssignWebsiteToDefaultStockPlugin->afterSave(Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelWebsiteInterceptor))
#7 vendor/magento/framework/Interception/Interceptor.php(153): MagentoStoreModelResourceModelWebsiteInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoStoreModelWebsiteInterceptor))
#8 generated/code/Magento/Store/Model/ResourceModel/Website/Interceptor.php(130): MagentoStoreModelResourceModelWebsiteInterceptor->___callPlugins('save', Array, NULL)
#9 app/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index.php(27): MagentoStoreModelResourceModelWebsiteInterceptor->save(Object(MagentoStoreModelWebsiteInterceptor))
#10 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(24): SampleModuleControllerAdminhtmlHelloWorldIndex->execute()
#11 vendor/magento/framework/App/Action/Action.php(108): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->execute()
#12 vendor/magento/module-backend/App/AbstractAction.php(231): MagentoFrameworkAppActionAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#13 vendor/magento/framework/Interception/Interceptor.php(58): MagentoBackendAppAbstractAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#14 vendor/magento/framework/Interception/Interceptor.php(138): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callParent('dispatch', Array)
#15 vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#16 vendor/magento/framework/Interception/Interceptor.php(135): MagentoBackendAppActionPluginAuthentication->aroundDispatch(Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor), Object(Closure), Object(MagentoFrameworkAppRequestHttp))
#17 vendor/magento/framework/Interception/Interceptor.php(153): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#18 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(39): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callPlugins('dispatch', Array, NULL)
#19 vendor/magento/framework/App/FrontController.php(159): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#20 vendor/magento/framework/App/FrontController.php(99): MagentoFrameworkAppFrontController->processRequest(Object(MagentoFrameworkAppRequestHttp), Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor))
#21 vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch(Object(MagentoFrameworkAppRequestHttp))
#22 vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent('dispatch', Array)
#23 vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#24 generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins('dispatch', Array, Array)
#25 vendor/magento/framework/App/Http.php(135): MagentoFrameworkAppFrontControllerInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#26 generated/code/Magento/Framework/App/Http/Interceptor.php(24): MagentoFrameworkAppHttp->launch()
#27 vendor/magento/framework/App/Bootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch()
#28 pub/index.php(37): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#29 main
What am I doing wrong? What is the correct way to create a website programmatically?
magento2
add a comment |
I'm using magento 2.3. I'm trying to create a website through a custom command. Here's my code
$website = $this->websiteFactory->create();
$website->setName("foo")->setCode("foobar");
$website->save();
var_dump("expression");
This gives an error - Validation Failed. In Save.php line 59.
However, it does create the website.
If I remove $website->save(), "expression" is displayed.
Stack trace:
Exception #0 (MagentoFrameworkValidationValidationException): Validation Failed
#0 vendor/magento/module-inventory/Model/StockRepository.php(67): MagentoInventoryModelStockCommandSave->execute(Object(MagentoInventoryModelStock))
#1 vendor/magento/framework/Interception/Interceptor.php(58): MagentoInventoryModelStockRepository->save(Object(MagentoInventoryModelStock))
#2 vendor/magento/framework/Interception/Interceptor.php(138): MagentoInventoryModelStockRepositoryInterceptor->___callParent('save', Array)
#3 vendor/magento/framework/Interception/Interceptor.php(153): MagentoInventoryModelStockRepositoryInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoInventoryModelStock))
#4 generated/code/Magento/Inventory/Model/StockRepository/Interceptor.php(26): MagentoInventoryModelStockRepositoryInterceptor->___callPlugins('save', Array, Array)
#5 vendor/magento/module-inventory-sales/Plugin/Store/Model/ResourceModel/Website/AssignWebsiteToDefaultStockPlugin.php(100): MagentoInventoryModelStockRepositoryInterceptor->save(Object(MagentoInventoryModelStock))
#6 vendor/magento/framework/Interception/Interceptor.php(146): MagentoInventorySalesPluginStoreModelResourceModelWebsiteAssignWebsiteToDefaultStockPlugin->afterSave(Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelWebsiteInterceptor))
#7 vendor/magento/framework/Interception/Interceptor.php(153): MagentoStoreModelResourceModelWebsiteInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoStoreModelWebsiteInterceptor))
#8 generated/code/Magento/Store/Model/ResourceModel/Website/Interceptor.php(130): MagentoStoreModelResourceModelWebsiteInterceptor->___callPlugins('save', Array, NULL)
#9 app/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index.php(27): MagentoStoreModelResourceModelWebsiteInterceptor->save(Object(MagentoStoreModelWebsiteInterceptor))
#10 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(24): SampleModuleControllerAdminhtmlHelloWorldIndex->execute()
#11 vendor/magento/framework/App/Action/Action.php(108): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->execute()
#12 vendor/magento/module-backend/App/AbstractAction.php(231): MagentoFrameworkAppActionAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#13 vendor/magento/framework/Interception/Interceptor.php(58): MagentoBackendAppAbstractAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#14 vendor/magento/framework/Interception/Interceptor.php(138): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callParent('dispatch', Array)
#15 vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#16 vendor/magento/framework/Interception/Interceptor.php(135): MagentoBackendAppActionPluginAuthentication->aroundDispatch(Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor), Object(Closure), Object(MagentoFrameworkAppRequestHttp))
#17 vendor/magento/framework/Interception/Interceptor.php(153): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#18 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(39): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callPlugins('dispatch', Array, NULL)
#19 vendor/magento/framework/App/FrontController.php(159): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#20 vendor/magento/framework/App/FrontController.php(99): MagentoFrameworkAppFrontController->processRequest(Object(MagentoFrameworkAppRequestHttp), Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor))
#21 vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch(Object(MagentoFrameworkAppRequestHttp))
#22 vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent('dispatch', Array)
#23 vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#24 generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins('dispatch', Array, Array)
#25 vendor/magento/framework/App/Http.php(135): MagentoFrameworkAppFrontControllerInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#26 generated/code/Magento/Framework/App/Http/Interceptor.php(24): MagentoFrameworkAppHttp->launch()
#27 vendor/magento/framework/App/Bootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch()
#28 pub/index.php(37): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#29 main
What am I doing wrong? What is the correct way to create a website programmatically?
magento2
try setting a sort order and a default group id. probably 0 for group id->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
Still getting the same error
– coderGeek
Feb 26 at 18:02
add a comment |
I'm using magento 2.3. I'm trying to create a website through a custom command. Here's my code
$website = $this->websiteFactory->create();
$website->setName("foo")->setCode("foobar");
$website->save();
var_dump("expression");
This gives an error - Validation Failed. In Save.php line 59.
However, it does create the website.
If I remove $website->save(), "expression" is displayed.
Stack trace:
Exception #0 (MagentoFrameworkValidationValidationException): Validation Failed
#0 vendor/magento/module-inventory/Model/StockRepository.php(67): MagentoInventoryModelStockCommandSave->execute(Object(MagentoInventoryModelStock))
#1 vendor/magento/framework/Interception/Interceptor.php(58): MagentoInventoryModelStockRepository->save(Object(MagentoInventoryModelStock))
#2 vendor/magento/framework/Interception/Interceptor.php(138): MagentoInventoryModelStockRepositoryInterceptor->___callParent('save', Array)
#3 vendor/magento/framework/Interception/Interceptor.php(153): MagentoInventoryModelStockRepositoryInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoInventoryModelStock))
#4 generated/code/Magento/Inventory/Model/StockRepository/Interceptor.php(26): MagentoInventoryModelStockRepositoryInterceptor->___callPlugins('save', Array, Array)
#5 vendor/magento/module-inventory-sales/Plugin/Store/Model/ResourceModel/Website/AssignWebsiteToDefaultStockPlugin.php(100): MagentoInventoryModelStockRepositoryInterceptor->save(Object(MagentoInventoryModelStock))
#6 vendor/magento/framework/Interception/Interceptor.php(146): MagentoInventorySalesPluginStoreModelResourceModelWebsiteAssignWebsiteToDefaultStockPlugin->afterSave(Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelWebsiteInterceptor))
#7 vendor/magento/framework/Interception/Interceptor.php(153): MagentoStoreModelResourceModelWebsiteInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoStoreModelWebsiteInterceptor))
#8 generated/code/Magento/Store/Model/ResourceModel/Website/Interceptor.php(130): MagentoStoreModelResourceModelWebsiteInterceptor->___callPlugins('save', Array, NULL)
#9 app/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index.php(27): MagentoStoreModelResourceModelWebsiteInterceptor->save(Object(MagentoStoreModelWebsiteInterceptor))
#10 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(24): SampleModuleControllerAdminhtmlHelloWorldIndex->execute()
#11 vendor/magento/framework/App/Action/Action.php(108): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->execute()
#12 vendor/magento/module-backend/App/AbstractAction.php(231): MagentoFrameworkAppActionAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#13 vendor/magento/framework/Interception/Interceptor.php(58): MagentoBackendAppAbstractAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#14 vendor/magento/framework/Interception/Interceptor.php(138): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callParent('dispatch', Array)
#15 vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#16 vendor/magento/framework/Interception/Interceptor.php(135): MagentoBackendAppActionPluginAuthentication->aroundDispatch(Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor), Object(Closure), Object(MagentoFrameworkAppRequestHttp))
#17 vendor/magento/framework/Interception/Interceptor.php(153): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#18 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(39): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callPlugins('dispatch', Array, NULL)
#19 vendor/magento/framework/App/FrontController.php(159): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#20 vendor/magento/framework/App/FrontController.php(99): MagentoFrameworkAppFrontController->processRequest(Object(MagentoFrameworkAppRequestHttp), Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor))
#21 vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch(Object(MagentoFrameworkAppRequestHttp))
#22 vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent('dispatch', Array)
#23 vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#24 generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins('dispatch', Array, Array)
#25 vendor/magento/framework/App/Http.php(135): MagentoFrameworkAppFrontControllerInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#26 generated/code/Magento/Framework/App/Http/Interceptor.php(24): MagentoFrameworkAppHttp->launch()
#27 vendor/magento/framework/App/Bootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch()
#28 pub/index.php(37): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#29 main
What am I doing wrong? What is the correct way to create a website programmatically?
magento2
I'm using magento 2.3. I'm trying to create a website through a custom command. Here's my code
$website = $this->websiteFactory->create();
$website->setName("foo")->setCode("foobar");
$website->save();
var_dump("expression");
This gives an error - Validation Failed. In Save.php line 59.
However, it does create the website.
If I remove $website->save(), "expression" is displayed.
Stack trace:
Exception #0 (MagentoFrameworkValidationValidationException): Validation Failed
#0 vendor/magento/module-inventory/Model/StockRepository.php(67): MagentoInventoryModelStockCommandSave->execute(Object(MagentoInventoryModelStock))
#1 vendor/magento/framework/Interception/Interceptor.php(58): MagentoInventoryModelStockRepository->save(Object(MagentoInventoryModelStock))
#2 vendor/magento/framework/Interception/Interceptor.php(138): MagentoInventoryModelStockRepositoryInterceptor->___callParent('save', Array)
#3 vendor/magento/framework/Interception/Interceptor.php(153): MagentoInventoryModelStockRepositoryInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoInventoryModelStock))
#4 generated/code/Magento/Inventory/Model/StockRepository/Interceptor.php(26): MagentoInventoryModelStockRepositoryInterceptor->___callPlugins('save', Array, Array)
#5 vendor/magento/module-inventory-sales/Plugin/Store/Model/ResourceModel/Website/AssignWebsiteToDefaultStockPlugin.php(100): MagentoInventoryModelStockRepositoryInterceptor->save(Object(MagentoInventoryModelStock))
#6 vendor/magento/framework/Interception/Interceptor.php(146): MagentoInventorySalesPluginStoreModelResourceModelWebsiteAssignWebsiteToDefaultStockPlugin->afterSave(Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelResourceModelWebsiteInterceptor), Object(MagentoStoreModelWebsiteInterceptor))
#7 vendor/magento/framework/Interception/Interceptor.php(153): MagentoStoreModelResourceModelWebsiteInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoStoreModelWebsiteInterceptor))
#8 generated/code/Magento/Store/Model/ResourceModel/Website/Interceptor.php(130): MagentoStoreModelResourceModelWebsiteInterceptor->___callPlugins('save', Array, NULL)
#9 app/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index.php(27): MagentoStoreModelResourceModelWebsiteInterceptor->save(Object(MagentoStoreModelWebsiteInterceptor))
#10 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(24): SampleModuleControllerAdminhtmlHelloWorldIndex->execute()
#11 vendor/magento/framework/App/Action/Action.php(108): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->execute()
#12 vendor/magento/module-backend/App/AbstractAction.php(231): MagentoFrameworkAppActionAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#13 vendor/magento/framework/Interception/Interceptor.php(58): MagentoBackendAppAbstractAction->dispatch(Object(MagentoFrameworkAppRequestHttp))
#14 vendor/magento/framework/Interception/Interceptor.php(138): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callParent('dispatch', Array)
#15 vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#16 vendor/magento/framework/Interception/Interceptor.php(135): MagentoBackendAppActionPluginAuthentication->aroundDispatch(Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor), Object(Closure), Object(MagentoFrameworkAppRequestHttp))
#17 vendor/magento/framework/Interception/Interceptor.php(153): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#18 generated/code/Sample/Module/Controller/Adminhtml/HelloWorld/Index/Interceptor.php(39): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->___callPlugins('dispatch', Array, NULL)
#19 vendor/magento/framework/App/FrontController.php(159): SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#20 vendor/magento/framework/App/FrontController.php(99): MagentoFrameworkAppFrontController->processRequest(Object(MagentoFrameworkAppRequestHttp), Object(SampleModuleControllerAdminhtmlHelloWorldIndexInterceptor))
#21 vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppFrontController->dispatch(Object(MagentoFrameworkAppRequestHttp))
#22 vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppFrontControllerInterceptor->___callParent('dispatch', Array)
#23 vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppFrontControllerInterceptor->MagentoFrameworkInterceptionclosure(Object(MagentoFrameworkAppRequestHttp))
#24 generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): MagentoFrameworkAppFrontControllerInterceptor->___callPlugins('dispatch', Array, Array)
#25 vendor/magento/framework/App/Http.php(135): MagentoFrameworkAppFrontControllerInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#26 generated/code/Magento/Framework/App/Http/Interceptor.php(24): MagentoFrameworkAppHttp->launch()
#27 vendor/magento/framework/App/Bootstrap.php(258): MagentoFrameworkAppHttpInterceptor->launch()
#28 pub/index.php(37): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#29 main
What am I doing wrong? What is the correct way to create a website programmatically?
magento2
magento2
edited Feb 26 at 20:07
coderGeek
asked Feb 26 at 17:39
coderGeekcoderGeek
163
163
try setting a sort order and a default group id. probably 0 for group id->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
Still getting the same error
– coderGeek
Feb 26 at 18:02
add a comment |
try setting a sort order and a default group id. probably 0 for group id->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
Still getting the same error
– coderGeek
Feb 26 at 18:02
try setting a sort order and a default group id. probably 0 for group id
->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
try setting a sort order and a default group id. probably 0 for group id
->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
Still getting the same error
– coderGeek
Feb 26 at 18:02
Still getting the same error
– coderGeek
Feb 26 at 18:02
add a comment |
2 Answers
2
active
oldest
votes
Try :
$website = $this->websiteFactory->create();
$website->setCode('foobar');
$website->setName('foo Name');
$website->setDefaultGroupId(1);
$this->websiteResourceModel->save($website);
where $this->websiteResourceModel
is MagentoStoreModelResourceModelWebsite
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
add a comment |
I am having exactly the same issue - I have handled it by catching the exception and ignoring it if the website actually saved (because it does).
/**
* @namespace Namespace
* @module WebConfig
* @brief Module for Installation Scripts for Websites, Stores, Groups, etc.
*/
namespace NamespaceWebConfigSetup;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoStoreModelGroupFactory;
use MagentoStoreModelResourceModelGroup;
use MagentoStoreModelResourceModelStore;
use MagentoStoreModelResourceModelWebsite;
use MagentoStoreModelStoreFactory;
use MagentoStoreModelWebsiteFactory;
use MagentoConfigModelResourceModelConfig;
use MagentoFrameworkAppState;
use PsrLogLoggerInterface as Logger;
/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
const WEBSITE_STORES
= array(
'Store One' => 'store_one',
'Store Two' => 'store_two',
);
/**
* @var WebsiteFactory
*/
private $websiteFactory;
/**
* @var Website
*/
private $websiteResourceModel;
/**
* @var StoreFactory
*/
private $storeFactory;
/**
* @var GroupFactory
*/
private $groupFactory;
/**
* @var Group
*/
private $groupResourceModel;
/**
* @var Store
*/
private $storeResourceModel;
/**
* @var ManagerInterface
*/
private $eventManager;
/**
* @var Config
*/
private $configResourceModel;
/**
* @var State
*/
private $appState;
/**
* @var Logger
*/
private $logger;
/**
* InstallData constructor.
*
* @param WebsiteFactory $websiteFactory
* @param Website $websiteResourceModel
* @param Store $storeResourceModel
* @param Group $groupResourceModel
* @param StoreFactory $storeFactory
* @param GroupFactory $groupFactory
* @param ManagerInterface $eventManager
* @param Config $configResourcModel
* @param Logger $logger
*/
public function __construct(
WebsiteFactory $websiteFactory,
Website $websiteResourceModel,
Store $storeResourceModel,
Group $groupResourceModel,
StoreFactory $storeFactory,
GroupFactory $groupFactory,
ManagerInterface $eventManager,
Config $configResourceModel,
State $appState,
Logger $logger
)
$this->websiteFactory = $websiteFactory;
$this->websiteResourceModel = $websiteResourceModel;
$this->storeFactory = $storeFactory;
$this->groupFactory = $groupFactory;
$this->groupResourceModel = $groupResourceModel;
$this->storeResourceModel = $storeResourceModel;
$this->eventManager = $eventManager;
$this->configResourceModel = $configResourceModel;
$this->appState = $appState;
$this->logger = $logger;
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*
* @return void
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
)
try
$this->appState->getAreaCode();
catch (MagentoFrameworkExceptionLocalizedException $ex)
$this->appState->setAreaCode('adminhtml');
$setup->startSetup();
$sortOrder = 0;
foreach (self::WEBSITE_STORES as $store_name => $store_code)
/** @var MagentoStoreModelWebsite $website */
$website = $this->websiteFactory->create();
$website->load($store_code);
if (!$website->getId())
$website->setCode($store_code);
$website->setName($store_name . ' Website');
$website->setDefaultGroupId(0);
$website->setSortOrder(0);
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error('fail to save website: ' . $website->getName() . ' ' . $e->getMessage());
if (!$website->getId())
//ignore if website actually did save
return;
else
//do not make store/group if website did not save
continue;
/** @var MagentoStoreModelStore $store */
$store = $this->storeFactory->create();
$store->load($store_code . '_store_view');
if (!$store->getId())
$store->setCode($store_code . '_store_view');
$store->setName($store_name . ' Store View');
$store->setWebsiteId($website->getId());
$store->setData('is_active', '1');
$store->setSortOrder($sortOrder);
try
$this->logger->info('trying to save store');
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('fail to save store: ' . $store->getName() . ' ' . $e->getMessage());
if (!$store->getId())
return;
/* Config */
$this->configResourceModel
->saveConfig('design/header/logo_width', '173', 'stores', $store->getId())
->saveConfig('design/header/logo_height', '26', 'stores', $store->getId())
->saveConfig('design/theme/theme_id', '4', 'stores', $store->getId())
->saveConfig('design/header/logo_src', 'stores/' . $store->getId() . '/logo.png', 'stores',
$store->getId());
// Trigger event to insert some data to the sales_sequence_meta table (fix bug place order in checkout)
$this->eventManager->dispatch('store_add', ['store' => $store]);
if ($website->getId())
/** @var MagentoStoreModelGroup $group */
$group = $this->groupFactory->create();
$group->setWebsiteId($website->getWebsiteId());
$group->setName($store_name . ' Store');
$group->setRootCategoryId(2);
$group->setDefaultStoreId($store->getId());
$group->setCode($store_code .'_store');
try
$this->groupResourceModel->save($group);
catch (Exception $e)
$this->logger->error('fail to save group: ' . $group->getName() . ' ' . $e->getMessage());
return;
$website->setDefaultGroupId($group->getId());
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error($e->getMessage());
if (!$website->getId())
return;
$store->setGroupId($group->getId());
try
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('cannot save store group ' . $group->getId() . ' ' . $e->getMessage());
return;
$setup->endSetup();
New contributor
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263532%2fcreating-website-programmatically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try :
$website = $this->websiteFactory->create();
$website->setCode('foobar');
$website->setName('foo Name');
$website->setDefaultGroupId(1);
$this->websiteResourceModel->save($website);
where $this->websiteResourceModel
is MagentoStoreModelResourceModelWebsite
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
add a comment |
Try :
$website = $this->websiteFactory->create();
$website->setCode('foobar');
$website->setName('foo Name');
$website->setDefaultGroupId(1);
$this->websiteResourceModel->save($website);
where $this->websiteResourceModel
is MagentoStoreModelResourceModelWebsite
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
add a comment |
Try :
$website = $this->websiteFactory->create();
$website->setCode('foobar');
$website->setName('foo Name');
$website->setDefaultGroupId(1);
$this->websiteResourceModel->save($website);
where $this->websiteResourceModel
is MagentoStoreModelResourceModelWebsite
Try :
$website = $this->websiteFactory->create();
$website->setCode('foobar');
$website->setName('foo Name');
$website->setDefaultGroupId(1);
$this->websiteResourceModel->save($website);
where $this->websiteResourceModel
is MagentoStoreModelResourceModelWebsite
answered Feb 26 at 19:59
VinzVinz
483313
483313
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
add a comment |
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
It isn't working. I have updated the question with the stack trace
– coderGeek
Feb 26 at 20:05
add a comment |
I am having exactly the same issue - I have handled it by catching the exception and ignoring it if the website actually saved (because it does).
/**
* @namespace Namespace
* @module WebConfig
* @brief Module for Installation Scripts for Websites, Stores, Groups, etc.
*/
namespace NamespaceWebConfigSetup;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoStoreModelGroupFactory;
use MagentoStoreModelResourceModelGroup;
use MagentoStoreModelResourceModelStore;
use MagentoStoreModelResourceModelWebsite;
use MagentoStoreModelStoreFactory;
use MagentoStoreModelWebsiteFactory;
use MagentoConfigModelResourceModelConfig;
use MagentoFrameworkAppState;
use PsrLogLoggerInterface as Logger;
/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
const WEBSITE_STORES
= array(
'Store One' => 'store_one',
'Store Two' => 'store_two',
);
/**
* @var WebsiteFactory
*/
private $websiteFactory;
/**
* @var Website
*/
private $websiteResourceModel;
/**
* @var StoreFactory
*/
private $storeFactory;
/**
* @var GroupFactory
*/
private $groupFactory;
/**
* @var Group
*/
private $groupResourceModel;
/**
* @var Store
*/
private $storeResourceModel;
/**
* @var ManagerInterface
*/
private $eventManager;
/**
* @var Config
*/
private $configResourceModel;
/**
* @var State
*/
private $appState;
/**
* @var Logger
*/
private $logger;
/**
* InstallData constructor.
*
* @param WebsiteFactory $websiteFactory
* @param Website $websiteResourceModel
* @param Store $storeResourceModel
* @param Group $groupResourceModel
* @param StoreFactory $storeFactory
* @param GroupFactory $groupFactory
* @param ManagerInterface $eventManager
* @param Config $configResourcModel
* @param Logger $logger
*/
public function __construct(
WebsiteFactory $websiteFactory,
Website $websiteResourceModel,
Store $storeResourceModel,
Group $groupResourceModel,
StoreFactory $storeFactory,
GroupFactory $groupFactory,
ManagerInterface $eventManager,
Config $configResourceModel,
State $appState,
Logger $logger
)
$this->websiteFactory = $websiteFactory;
$this->websiteResourceModel = $websiteResourceModel;
$this->storeFactory = $storeFactory;
$this->groupFactory = $groupFactory;
$this->groupResourceModel = $groupResourceModel;
$this->storeResourceModel = $storeResourceModel;
$this->eventManager = $eventManager;
$this->configResourceModel = $configResourceModel;
$this->appState = $appState;
$this->logger = $logger;
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*
* @return void
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
)
try
$this->appState->getAreaCode();
catch (MagentoFrameworkExceptionLocalizedException $ex)
$this->appState->setAreaCode('adminhtml');
$setup->startSetup();
$sortOrder = 0;
foreach (self::WEBSITE_STORES as $store_name => $store_code)
/** @var MagentoStoreModelWebsite $website */
$website = $this->websiteFactory->create();
$website->load($store_code);
if (!$website->getId())
$website->setCode($store_code);
$website->setName($store_name . ' Website');
$website->setDefaultGroupId(0);
$website->setSortOrder(0);
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error('fail to save website: ' . $website->getName() . ' ' . $e->getMessage());
if (!$website->getId())
//ignore if website actually did save
return;
else
//do not make store/group if website did not save
continue;
/** @var MagentoStoreModelStore $store */
$store = $this->storeFactory->create();
$store->load($store_code . '_store_view');
if (!$store->getId())
$store->setCode($store_code . '_store_view');
$store->setName($store_name . ' Store View');
$store->setWebsiteId($website->getId());
$store->setData('is_active', '1');
$store->setSortOrder($sortOrder);
try
$this->logger->info('trying to save store');
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('fail to save store: ' . $store->getName() . ' ' . $e->getMessage());
if (!$store->getId())
return;
/* Config */
$this->configResourceModel
->saveConfig('design/header/logo_width', '173', 'stores', $store->getId())
->saveConfig('design/header/logo_height', '26', 'stores', $store->getId())
->saveConfig('design/theme/theme_id', '4', 'stores', $store->getId())
->saveConfig('design/header/logo_src', 'stores/' . $store->getId() . '/logo.png', 'stores',
$store->getId());
// Trigger event to insert some data to the sales_sequence_meta table (fix bug place order in checkout)
$this->eventManager->dispatch('store_add', ['store' => $store]);
if ($website->getId())
/** @var MagentoStoreModelGroup $group */
$group = $this->groupFactory->create();
$group->setWebsiteId($website->getWebsiteId());
$group->setName($store_name . ' Store');
$group->setRootCategoryId(2);
$group->setDefaultStoreId($store->getId());
$group->setCode($store_code .'_store');
try
$this->groupResourceModel->save($group);
catch (Exception $e)
$this->logger->error('fail to save group: ' . $group->getName() . ' ' . $e->getMessage());
return;
$website->setDefaultGroupId($group->getId());
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error($e->getMessage());
if (!$website->getId())
return;
$store->setGroupId($group->getId());
try
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('cannot save store group ' . $group->getId() . ' ' . $e->getMessage());
return;
$setup->endSetup();
New contributor
add a comment |
I am having exactly the same issue - I have handled it by catching the exception and ignoring it if the website actually saved (because it does).
/**
* @namespace Namespace
* @module WebConfig
* @brief Module for Installation Scripts for Websites, Stores, Groups, etc.
*/
namespace NamespaceWebConfigSetup;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoStoreModelGroupFactory;
use MagentoStoreModelResourceModelGroup;
use MagentoStoreModelResourceModelStore;
use MagentoStoreModelResourceModelWebsite;
use MagentoStoreModelStoreFactory;
use MagentoStoreModelWebsiteFactory;
use MagentoConfigModelResourceModelConfig;
use MagentoFrameworkAppState;
use PsrLogLoggerInterface as Logger;
/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
const WEBSITE_STORES
= array(
'Store One' => 'store_one',
'Store Two' => 'store_two',
);
/**
* @var WebsiteFactory
*/
private $websiteFactory;
/**
* @var Website
*/
private $websiteResourceModel;
/**
* @var StoreFactory
*/
private $storeFactory;
/**
* @var GroupFactory
*/
private $groupFactory;
/**
* @var Group
*/
private $groupResourceModel;
/**
* @var Store
*/
private $storeResourceModel;
/**
* @var ManagerInterface
*/
private $eventManager;
/**
* @var Config
*/
private $configResourceModel;
/**
* @var State
*/
private $appState;
/**
* @var Logger
*/
private $logger;
/**
* InstallData constructor.
*
* @param WebsiteFactory $websiteFactory
* @param Website $websiteResourceModel
* @param Store $storeResourceModel
* @param Group $groupResourceModel
* @param StoreFactory $storeFactory
* @param GroupFactory $groupFactory
* @param ManagerInterface $eventManager
* @param Config $configResourcModel
* @param Logger $logger
*/
public function __construct(
WebsiteFactory $websiteFactory,
Website $websiteResourceModel,
Store $storeResourceModel,
Group $groupResourceModel,
StoreFactory $storeFactory,
GroupFactory $groupFactory,
ManagerInterface $eventManager,
Config $configResourceModel,
State $appState,
Logger $logger
)
$this->websiteFactory = $websiteFactory;
$this->websiteResourceModel = $websiteResourceModel;
$this->storeFactory = $storeFactory;
$this->groupFactory = $groupFactory;
$this->groupResourceModel = $groupResourceModel;
$this->storeResourceModel = $storeResourceModel;
$this->eventManager = $eventManager;
$this->configResourceModel = $configResourceModel;
$this->appState = $appState;
$this->logger = $logger;
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*
* @return void
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
)
try
$this->appState->getAreaCode();
catch (MagentoFrameworkExceptionLocalizedException $ex)
$this->appState->setAreaCode('adminhtml');
$setup->startSetup();
$sortOrder = 0;
foreach (self::WEBSITE_STORES as $store_name => $store_code)
/** @var MagentoStoreModelWebsite $website */
$website = $this->websiteFactory->create();
$website->load($store_code);
if (!$website->getId())
$website->setCode($store_code);
$website->setName($store_name . ' Website');
$website->setDefaultGroupId(0);
$website->setSortOrder(0);
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error('fail to save website: ' . $website->getName() . ' ' . $e->getMessage());
if (!$website->getId())
//ignore if website actually did save
return;
else
//do not make store/group if website did not save
continue;
/** @var MagentoStoreModelStore $store */
$store = $this->storeFactory->create();
$store->load($store_code . '_store_view');
if (!$store->getId())
$store->setCode($store_code . '_store_view');
$store->setName($store_name . ' Store View');
$store->setWebsiteId($website->getId());
$store->setData('is_active', '1');
$store->setSortOrder($sortOrder);
try
$this->logger->info('trying to save store');
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('fail to save store: ' . $store->getName() . ' ' . $e->getMessage());
if (!$store->getId())
return;
/* Config */
$this->configResourceModel
->saveConfig('design/header/logo_width', '173', 'stores', $store->getId())
->saveConfig('design/header/logo_height', '26', 'stores', $store->getId())
->saveConfig('design/theme/theme_id', '4', 'stores', $store->getId())
->saveConfig('design/header/logo_src', 'stores/' . $store->getId() . '/logo.png', 'stores',
$store->getId());
// Trigger event to insert some data to the sales_sequence_meta table (fix bug place order in checkout)
$this->eventManager->dispatch('store_add', ['store' => $store]);
if ($website->getId())
/** @var MagentoStoreModelGroup $group */
$group = $this->groupFactory->create();
$group->setWebsiteId($website->getWebsiteId());
$group->setName($store_name . ' Store');
$group->setRootCategoryId(2);
$group->setDefaultStoreId($store->getId());
$group->setCode($store_code .'_store');
try
$this->groupResourceModel->save($group);
catch (Exception $e)
$this->logger->error('fail to save group: ' . $group->getName() . ' ' . $e->getMessage());
return;
$website->setDefaultGroupId($group->getId());
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error($e->getMessage());
if (!$website->getId())
return;
$store->setGroupId($group->getId());
try
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('cannot save store group ' . $group->getId() . ' ' . $e->getMessage());
return;
$setup->endSetup();
New contributor
add a comment |
I am having exactly the same issue - I have handled it by catching the exception and ignoring it if the website actually saved (because it does).
/**
* @namespace Namespace
* @module WebConfig
* @brief Module for Installation Scripts for Websites, Stores, Groups, etc.
*/
namespace NamespaceWebConfigSetup;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoStoreModelGroupFactory;
use MagentoStoreModelResourceModelGroup;
use MagentoStoreModelResourceModelStore;
use MagentoStoreModelResourceModelWebsite;
use MagentoStoreModelStoreFactory;
use MagentoStoreModelWebsiteFactory;
use MagentoConfigModelResourceModelConfig;
use MagentoFrameworkAppState;
use PsrLogLoggerInterface as Logger;
/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
const WEBSITE_STORES
= array(
'Store One' => 'store_one',
'Store Two' => 'store_two',
);
/**
* @var WebsiteFactory
*/
private $websiteFactory;
/**
* @var Website
*/
private $websiteResourceModel;
/**
* @var StoreFactory
*/
private $storeFactory;
/**
* @var GroupFactory
*/
private $groupFactory;
/**
* @var Group
*/
private $groupResourceModel;
/**
* @var Store
*/
private $storeResourceModel;
/**
* @var ManagerInterface
*/
private $eventManager;
/**
* @var Config
*/
private $configResourceModel;
/**
* @var State
*/
private $appState;
/**
* @var Logger
*/
private $logger;
/**
* InstallData constructor.
*
* @param WebsiteFactory $websiteFactory
* @param Website $websiteResourceModel
* @param Store $storeResourceModel
* @param Group $groupResourceModel
* @param StoreFactory $storeFactory
* @param GroupFactory $groupFactory
* @param ManagerInterface $eventManager
* @param Config $configResourcModel
* @param Logger $logger
*/
public function __construct(
WebsiteFactory $websiteFactory,
Website $websiteResourceModel,
Store $storeResourceModel,
Group $groupResourceModel,
StoreFactory $storeFactory,
GroupFactory $groupFactory,
ManagerInterface $eventManager,
Config $configResourceModel,
State $appState,
Logger $logger
)
$this->websiteFactory = $websiteFactory;
$this->websiteResourceModel = $websiteResourceModel;
$this->storeFactory = $storeFactory;
$this->groupFactory = $groupFactory;
$this->groupResourceModel = $groupResourceModel;
$this->storeResourceModel = $storeResourceModel;
$this->eventManager = $eventManager;
$this->configResourceModel = $configResourceModel;
$this->appState = $appState;
$this->logger = $logger;
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*
* @return void
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
)
try
$this->appState->getAreaCode();
catch (MagentoFrameworkExceptionLocalizedException $ex)
$this->appState->setAreaCode('adminhtml');
$setup->startSetup();
$sortOrder = 0;
foreach (self::WEBSITE_STORES as $store_name => $store_code)
/** @var MagentoStoreModelWebsite $website */
$website = $this->websiteFactory->create();
$website->load($store_code);
if (!$website->getId())
$website->setCode($store_code);
$website->setName($store_name . ' Website');
$website->setDefaultGroupId(0);
$website->setSortOrder(0);
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error('fail to save website: ' . $website->getName() . ' ' . $e->getMessage());
if (!$website->getId())
//ignore if website actually did save
return;
else
//do not make store/group if website did not save
continue;
/** @var MagentoStoreModelStore $store */
$store = $this->storeFactory->create();
$store->load($store_code . '_store_view');
if (!$store->getId())
$store->setCode($store_code . '_store_view');
$store->setName($store_name . ' Store View');
$store->setWebsiteId($website->getId());
$store->setData('is_active', '1');
$store->setSortOrder($sortOrder);
try
$this->logger->info('trying to save store');
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('fail to save store: ' . $store->getName() . ' ' . $e->getMessage());
if (!$store->getId())
return;
/* Config */
$this->configResourceModel
->saveConfig('design/header/logo_width', '173', 'stores', $store->getId())
->saveConfig('design/header/logo_height', '26', 'stores', $store->getId())
->saveConfig('design/theme/theme_id', '4', 'stores', $store->getId())
->saveConfig('design/header/logo_src', 'stores/' . $store->getId() . '/logo.png', 'stores',
$store->getId());
// Trigger event to insert some data to the sales_sequence_meta table (fix bug place order in checkout)
$this->eventManager->dispatch('store_add', ['store' => $store]);
if ($website->getId())
/** @var MagentoStoreModelGroup $group */
$group = $this->groupFactory->create();
$group->setWebsiteId($website->getWebsiteId());
$group->setName($store_name . ' Store');
$group->setRootCategoryId(2);
$group->setDefaultStoreId($store->getId());
$group->setCode($store_code .'_store');
try
$this->groupResourceModel->save($group);
catch (Exception $e)
$this->logger->error('fail to save group: ' . $group->getName() . ' ' . $e->getMessage());
return;
$website->setDefaultGroupId($group->getId());
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error($e->getMessage());
if (!$website->getId())
return;
$store->setGroupId($group->getId());
try
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('cannot save store group ' . $group->getId() . ' ' . $e->getMessage());
return;
$setup->endSetup();
New contributor
I am having exactly the same issue - I have handled it by catching the exception and ignoring it if the website actually saved (because it does).
/**
* @namespace Namespace
* @module WebConfig
* @brief Module for Installation Scripts for Websites, Stores, Groups, etc.
*/
namespace NamespaceWebConfigSetup;
use MagentoFrameworkEventManagerInterface;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoStoreModelGroupFactory;
use MagentoStoreModelResourceModelGroup;
use MagentoStoreModelResourceModelStore;
use MagentoStoreModelResourceModelWebsite;
use MagentoStoreModelStoreFactory;
use MagentoStoreModelWebsiteFactory;
use MagentoConfigModelResourceModelConfig;
use MagentoFrameworkAppState;
use PsrLogLoggerInterface as Logger;
/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
const WEBSITE_STORES
= array(
'Store One' => 'store_one',
'Store Two' => 'store_two',
);
/**
* @var WebsiteFactory
*/
private $websiteFactory;
/**
* @var Website
*/
private $websiteResourceModel;
/**
* @var StoreFactory
*/
private $storeFactory;
/**
* @var GroupFactory
*/
private $groupFactory;
/**
* @var Group
*/
private $groupResourceModel;
/**
* @var Store
*/
private $storeResourceModel;
/**
* @var ManagerInterface
*/
private $eventManager;
/**
* @var Config
*/
private $configResourceModel;
/**
* @var State
*/
private $appState;
/**
* @var Logger
*/
private $logger;
/**
* InstallData constructor.
*
* @param WebsiteFactory $websiteFactory
* @param Website $websiteResourceModel
* @param Store $storeResourceModel
* @param Group $groupResourceModel
* @param StoreFactory $storeFactory
* @param GroupFactory $groupFactory
* @param ManagerInterface $eventManager
* @param Config $configResourcModel
* @param Logger $logger
*/
public function __construct(
WebsiteFactory $websiteFactory,
Website $websiteResourceModel,
Store $storeResourceModel,
Group $groupResourceModel,
StoreFactory $storeFactory,
GroupFactory $groupFactory,
ManagerInterface $eventManager,
Config $configResourceModel,
State $appState,
Logger $logger
)
$this->websiteFactory = $websiteFactory;
$this->websiteResourceModel = $websiteResourceModel;
$this->storeFactory = $storeFactory;
$this->groupFactory = $groupFactory;
$this->groupResourceModel = $groupResourceModel;
$this->storeResourceModel = $storeResourceModel;
$this->eventManager = $eventManager;
$this->configResourceModel = $configResourceModel;
$this->appState = $appState;
$this->logger = $logger;
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*
* @return void
*/
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
)
try
$this->appState->getAreaCode();
catch (MagentoFrameworkExceptionLocalizedException $ex)
$this->appState->setAreaCode('adminhtml');
$setup->startSetup();
$sortOrder = 0;
foreach (self::WEBSITE_STORES as $store_name => $store_code)
/** @var MagentoStoreModelWebsite $website */
$website = $this->websiteFactory->create();
$website->load($store_code);
if (!$website->getId())
$website->setCode($store_code);
$website->setName($store_name . ' Website');
$website->setDefaultGroupId(0);
$website->setSortOrder(0);
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error('fail to save website: ' . $website->getName() . ' ' . $e->getMessage());
if (!$website->getId())
//ignore if website actually did save
return;
else
//do not make store/group if website did not save
continue;
/** @var MagentoStoreModelStore $store */
$store = $this->storeFactory->create();
$store->load($store_code . '_store_view');
if (!$store->getId())
$store->setCode($store_code . '_store_view');
$store->setName($store_name . ' Store View');
$store->setWebsiteId($website->getId());
$store->setData('is_active', '1');
$store->setSortOrder($sortOrder);
try
$this->logger->info('trying to save store');
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('fail to save store: ' . $store->getName() . ' ' . $e->getMessage());
if (!$store->getId())
return;
/* Config */
$this->configResourceModel
->saveConfig('design/header/logo_width', '173', 'stores', $store->getId())
->saveConfig('design/header/logo_height', '26', 'stores', $store->getId())
->saveConfig('design/theme/theme_id', '4', 'stores', $store->getId())
->saveConfig('design/header/logo_src', 'stores/' . $store->getId() . '/logo.png', 'stores',
$store->getId());
// Trigger event to insert some data to the sales_sequence_meta table (fix bug place order in checkout)
$this->eventManager->dispatch('store_add', ['store' => $store]);
if ($website->getId())
/** @var MagentoStoreModelGroup $group */
$group = $this->groupFactory->create();
$group->setWebsiteId($website->getWebsiteId());
$group->setName($store_name . ' Store');
$group->setRootCategoryId(2);
$group->setDefaultStoreId($store->getId());
$group->setCode($store_code .'_store');
try
$this->groupResourceModel->save($group);
catch (Exception $e)
$this->logger->error('fail to save group: ' . $group->getName() . ' ' . $e->getMessage());
return;
$website->setDefaultGroupId($group->getId());
try
$this->websiteResourceModel->save($website);
catch (Exception $e)
$this->logger->error($e->getMessage());
if (!$website->getId())
return;
$store->setGroupId($group->getId());
try
$this->storeResourceModel->save($store);
catch (Exception $e)
echo $e->getMessage();
$this->logger->error('cannot save store group ' . $group->getId() . ' ' . $e->getMessage());
return;
$setup->endSetup();
New contributor
New contributor
answered 13 mins ago
jnodwelljnodwell
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263532%2fcreating-website-programmatically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try setting a sort order and a default group id. probably 0 for group id
->setSortOrder(1)->setDefaultGroupId(0)
– Marius♦
Feb 26 at 18:00
Still getting the same error
– coderGeek
Feb 26 at 18:02