SHARE
TWEET

Untitled

a guest Jun 16th, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Upgrading data.. Area code is not set
  2.      
  3. <?php
  4.  
  5.  
  6. namespace LimeMerchantSetup;
  7.  
  8. use MagentoFrameworkSetupUpgradeDataInterface;
  9. use MagentoFrameworkSetupModuleContextInterface;
  10. use MagentoFrameworkSetupModuleDataSetupInterface;
  11.  
  12. class UpgradeData implements UpgradeDataInterface
  13. {
  14.     public function upgrade(
  15.         ModuleDataSetupInterface $setup,
  16.         ModuleContextInterface $context
  17.     ) {
  18.         if (version_compare($context->getVersion(), "1.0.1", "<")) {
  19.           // $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  20.           // $state = $objectManager->get('MagentoFrameworkAppState');
  21.           // if(!$state->getAreaCode()) {
  22.             $state->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
  23.           }
  24.           $this->createVirtualProduct();
  25.         }
  26.     }
  27.  
  28.     public function createVirtualProduct()
  29.     {
  30.       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  31.       $_product = $objectManager->create('MagentoCatalogModelProduct');
  32.       $_product->setName('E-Book');
  33.       $_product->setTypeId('virtual');
  34.       $_product->setAttributeSetId(4);
  35.       $_product->setSku('ebook');
  36.       $_product->setWebsiteIds(array(1));
  37.       $_product->setVisibility(4);
  38.       $_product->setPrice(1000);
  39.       $_product->setStockData(array(
  40.           'use_config_manage_stock' => 0, //'Use config settings' checkbox
  41.           'manage_stock' => 0, //manage stock
  42.           'is_in_stock' => 1, //Stock Availability
  43.           'qty' => 100000, //qty
  44.           'tax_class_id' => 0
  45.           )
  46.       );
  47.  
  48.       $_product->save();
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top