Exemplo n.º 1
0
 /**
  * Get pattern object
  *
  * @param array $patternData
  *
  * @return \Magento\Setup\Model\Complex\Pattern
  */
 protected function getPattern($patternData)
 {
     $pattern = new Pattern();
     $pattern->setHeaders(array_keys($patternData[0]));
     $pattern->setRowsSet($patternData);
     return $pattern;
 }
 /**
  * Get pattern instance
  *
  * @return Pattern
  */
 protected function getPattern()
 {
     if (!$this->_pattern instanceof Pattern) {
         $patternData = [['id' => '%s', 'name' => 'Static', 'calculated' => function ($index) {
             return $index * 10;
         }], ['name' => 'xxx %s'], ['name' => 'yyy %s']];
         $this->_pattern = new Pattern();
         $this->_pattern->setHeaders(array_keys($patternData[0]));
         $this->_pattern->setRowsSet($patternData);
     }
     return $this->_pattern;
 }
Exemplo n.º 3
0
 /**
  * Get next row in set
  *
  * @return array|bool
  */
 protected function _getNextRow()
 {
     $key = $this->key();
     $this->_index = $this->getIndex($key);
     if ($key > $this->_limit) {
         return false;
     }
     return $this->_pattern->getRow($this->_index, $key);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $configurablesCount = $this->fixtureModel->getValue('configurable_products', 0);
     if (!$configurablesCount) {
         return;
     }
     $this->fixtureModel->resetObjectManager();
     /** @var \Magento\Store\Model\StoreManager $storeManager */
     $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\\Store\\Model\\StoreManager');
     /** @var $category \Magento\Catalog\Model\Category */
     $category = $this->fixtureModel->getObjectManager()->get('Magento\\Catalog\\Model\\Category');
     $result = [];
     //Get all websites
     $websites = $storeManager->getWebsites();
     foreach ($websites as $website) {
         $websiteCode = $website->getCode();
         //Get all groups
         $websiteGroups = $website->getGroups();
         foreach ($websiteGroups as $websiteGroup) {
             $websiteGroupRootCategory = $websiteGroup->getRootCategoryId();
             $category->load($websiteGroupRootCategory);
             $categoryResource = $category->getResource();
             $rootCategoryName = $category->getName();
             //Get all categories
             $resultsCategories = $categoryResource->getAllChildren($category);
             foreach ($resultsCategories as $resultsCategory) {
                 $category->load($resultsCategory);
                 $structure = explode('/', $category->getPath());
                 $pathSize = count($structure);
                 if ($pathSize > 1) {
                     $path = [];
                     for ($i = 1; $i < $pathSize; $i++) {
                         $path[] = $category->load($structure[$i])->getName();
                     }
                     array_shift($path);
                     $resultsCategoryName = implode('/', $path);
                 } else {
                     $resultsCategoryName = $category->getName();
                 }
                 //Deleted root categories
                 if (trim($resultsCategoryName) != '') {
                     $result[$resultsCategory] = [$websiteCode, $resultsCategoryName, $rootCategoryName];
                 }
             }
         }
     }
     $result = array_values($result);
     $productWebsite = function ($index) use($result) {
         return $result[$index % count($result)][0];
     };
     $productCategory = function ($index) use($result) {
         return $result[$index % count($result)][2] . '/' . $result[$index % count($result)][1];
     };
     /**
      * Create configurable products
      */
     $pattern = new Pattern();
     $pattern->setHeaders($this->getHeaders());
     $pattern->setRowsSet($this->getRows($productCategory, $productWebsite));
     /** @var \Magento\ImportExport\Model\Import $import */
     $import = $this->fixtureModel->getObjectManager()->create('Magento\\ImportExport\\Model\\Import', ['data' => ['entity' => 'catalog_product', 'behavior' => 'append', 'validation_strategy' => 'validation-stop-on-errors']]);
     $source = new Generator($pattern, $configurablesCount);
     // it is not obvious, but the validateSource() will actually save import queue data to DB
     $import->validateSource($source);
     // this converts import queue into actual entities
     $import->importSource();
 }