Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Upgrading data.. Area code is not set
- <?php
- namespace LimeMerchantSetup;
- use MagentoFrameworkSetupUpgradeDataInterface;
- use MagentoFrameworkSetupModuleContextInterface;
- use MagentoFrameworkSetupModuleDataSetupInterface;
- class UpgradeData implements UpgradeDataInterface
- {
- public function upgrade(
- ModuleDataSetupInterface $setup,
- ModuleContextInterface $context
- ) {
- if (version_compare($context->getVersion(), "1.0.1", "<")) {
- // $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- // $state = $objectManager->get('MagentoFrameworkAppState');
- // if(!$state->getAreaCode()) {
- $state->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
- }
- $this->createVirtualProduct();
- }
- }
- public function createVirtualProduct()
- {
- $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- $_product = $objectManager->create('MagentoCatalogModelProduct');
- $_product->setName('E-Book');
- $_product->setTypeId('virtual');
- $_product->setAttributeSetId(4);
- $_product->setSku('ebook');
- $_product->setWebsiteIds(array(1));
- $_product->setVisibility(4);
- $_product->setPrice(1000);
- $_product->setStockData(array(
- 'use_config_manage_stock' => 0, //'Use config settings' checkbox
- 'manage_stock' => 0, //manage stock
- 'is_in_stock' => 1, //Stock Availability
- 'qty' => 100000, //qty
- 'tax_class_id' => 0
- )
- );
- $_product->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement