Example #1
0
 /**
  * @inheritdoc
  */
 public function create(WriterInterface $writer)
 {
     $number = $this->config->getNumberVouchers();
     $this->loadDataInfile = new LoadDataInfile();
     $voucherCsv = $this->writerManager->createWriter('vouchers', 'csv');
     $voucherCodeCsv = $this->writerManager->createWriter('voucher_code', 'csv');
     $voucherAttributeCsv = $this->writerManager->createWriter('voucher_code', 'csv');
     $this->createProgressBar($number);
     for ($voucherCounter = 0; $voucherCounter < $number; $voucherCounter++) {
         $this->advanceProgressBar();
         $id = $this->getUniqueId('voucher');
         $isIndividual = $voucherCounter % 2 === 1;
         $isPercental = !$voucherCounter % 3;
         $numOrder = !$isIndividual;
         // individual vouchers are not restricted
         $code = 'code' . $id;
         if ($isIndividual) {
             $code = '';
         }
         $value = mt_rand(5, 100);
         $voucherCsv->write("{$id},Voucher #{$id},{$code},{$value},101,\\N,\\N,VOUCHER{$id},{$isIndividual},{$isPercental},{$numOrder},\\N,auto");
         $voucherAttributeCsv->write("{$id}");
         if ($isIndividual) {
             for ($i = 0; $i < $this->numberOfIndividualVoucherCodes; $i++) {
                 $code = "code-{$id}-{$i}";
                 $voucherCodeCsv->write("{$id},\\N,{$code},0");
             }
         }
     }
     $writer->write($this->loadDataInfile->get('s_emarketing_vouchers', $voucherCsv->getFileName()));
     $writer->write($this->loadDataInfile->get('s_emarketing_vouchers_attributes', $voucherAttributeCsv->getFileName()));
     $writer->write($this->loadDataInfile->get('s_emarketing_voucher_codes', $voucherCodeCsv->getFileName()));
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function create(WriterInterface $writer)
 {
     $this->ids['customerNumber'] = 20002;
     $number = $this->config->getNumberCustomers();
     $this->loadDataInfile = new LoadDataInfile();
     $importCustomers = $this->writerManager->createWriter('customers', 'csv');
     $importCustomersAttributes = $this->writerManager->createWriter('customers_attributes', 'csv');
     $importCustomersBilling = $this->writerManager->createWriter('customers_billing', 'csv');
     $importCustomersBillingAttributes = $this->writerManager->createWriter('customers_billing_attributes', 'csv');
     $this->createProgressBar($number);
     for ($customerCounter = 0; $customerCounter < $number; $customerCounter++) {
         $this->advanceProgressBar();
         $id = $this->getUniqueId('customer');
         $customerNumber = $this->getUniqueId('customerNumber');
         $group = $customerCounter % 2 === 1 ? "EK" : "H";
         $sex = $customerCounter % 2 === 1 ? "mr" : "ms";
         $importCustomers->write("{$id},a256a310bc1e5db755fd392c524028a8,user_{$id}@example.org,1,0,,5,2013-01-11,2015-01-01 00:00:00,,0,,0,{$group},0,1,1,,\\N,,0,\\N");
         $importCustomersAttributes->write("{$id}");
         $importCustomersBillingAttributes->write("{$id}");
         $importCustomersBillingAttributes->write("{$id}");
         $customerAttributeValues[] = "{$id}";
         $importCustomersBilling->write("{$id}, {$id}, , , {$sex}, {$customerNumber}, {$this->generator->getRandomFirstName()}, {$this->generator->getRandomLastName()}, {$this->generator->getRandomWord()} " . rand(1, 500) . "' , " . rand(42000, 50000) . ", {$this->generator->getRandomCity()}, " . rand(9999, 99999) . ", , 2, 0, , 1992-04-03");
     }
     $writer->write($this->loadDataInfile->get('s_user', $importCustomers->getFileName()));
     $writer->write($this->loadDataInfile->get('s_user_attributes', $importCustomersAttributes->getFileName()));
     $writer->write($this->loadDataInfile->get('s_user_billingaddress', $importCustomersBilling->getFileName()));
     $writer->write($this->loadDataInfile->get('s_user_billingaddress_attributes', $importCustomersBillingAttributes->getFileName()));
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function create(WriterInterface $writer)
 {
     $number = $this->config->getNumberArticles();
     $this->loadDataInfile = new LoadDataInfile();
     $urls = $this->writerManager->createWriter('article_urls', 'csv');
     $articles = $this->writerManager->createWriter('articles', 'csv');
     $details = $this->writerManager->createWriter('articles_details', 'csv');
     $prices = $this->writerManager->createWriter('articles_price', 'csv');
     $attributes = $this->writerManager->createWriter('articles_attributes', 'csv');
     $configuratorSets = $this->writerManager->createWriter('articles_configurator_set', 'csv');
     $configuratorGroups = $this->writerManager->createWriter('articles_configurator_group_values', 'csv');
     $configuratorOptions = $this->writerManager->createWriter('articles_configurator_option_values', 'csv');
     $configuratorSetOptionRelations = $this->writerManager->createWriter('articles_configurator_set_option_relation', 'csv');
     $configuratorSetGroupRelations = $this->writerManager->createWriter('articles_configurator_set_group_relation', 'csv');
     $articleCategories = $this->writerManager->createWriter('articles_categories', 'csv');
     $articlesCategoriesRO = $this->writerManager->createWriter('s_articles_categories_ro', 'csv');
     $filterArticles = $this->writerManager->createWriter('filter_articles', 'csv');
     $articleConfiguratorRelations = $this->writerManager->createWriter('article_configurator_option_relations', 'csv');
     if ($this->config->getNumberOrders() > 0) {
         $maxDetails = $this->config->getNumberArticles() * $this->config->getMaxVariants();
         $this->articleDetailsFlat = new \SplFixedArray($maxDetails);
     }
     if (!$this->categoryResource->categoriesFlat) {
         throw new \RuntimeException('Category resource not found');
     }
     $categoriesFlat = $this->categoryResource->categoriesFlat;
     $validCategoryIds = array_filter(array_keys($categoriesFlat), function ($item) {
         return $item >= 1000000;
     });
     $categoriesPerArticle = min(count($validCategoryIds), $this->config->getCategoriesPerArticle());
     if (count($validCategoryIds) < $this->config->getCategoriesPerArticle()) {
         $this->ioService->writeln('<comment>Number of categories per article will be lower than specified</comment>');
     }
     $this->createProgressBar($number);
     $images = array();
     for ($articleCounter = 0; $articleCounter < $number; $articleCounter++) {
         $this->advanceProgressBar();
         $id = $this->getUniqueId('article');
         $createConfigurator = $id === 1 ? 1 : rand(0, 1);
         // Force the first article to be a configurator
         $createFilter = rand(0, 3);
         $urls->write("/detail/index/sArticle/{$id}");
         // Get the id of the first articleDetail in advance on order to set the main_detail_id properly
         $articleDetailId = $this->getUniqueId('articleDetail');
         $detailIDs = array($articleDetailId);
         $configuratorSetId = $createConfigurator === 1 ? $id : "NULL";
         $numberOfVariants = $createConfigurator === 1 ? rand($this->config->getMinVariants(), $this->config->getMaxVariants()) : 1;
         //            $numberOfVariants = $id === 1 ? 500 : $numberOfVariants;
         $numberOfOptions = rand(2, 4);
         $numberGroups = floor(pow($numberOfVariants, 1 / $numberOfOptions));
         if ($createConfigurator === 1) {
             $numberOfVariants = $numberOfOptions * $numberGroups;
         }
         #
         # Configurator
         #
         if ($createConfigurator) {
             $configuratorSets->write("{$id}, Test-Configurator-Set Article {$id})");
             // Create configurator groups and options
             $groups = array();
             $options = array();
             for ($g = 1; $g <= $numberGroups; $g++) {
                 $groupId = $this->getUniqueId('group');
                 $configuratorGroups->write("{$groupId}, Configurator-Group #{$groupId}, NULL, {$g}");
                 $groups[$groupId] = array();
                 // Create options for this group
                 for ($o = 1; $o <= $numberOfOptions; $o++) {
                     $optionId = $this->getUniqueId('option');
                     $configuratorOptions->write("{$optionId}, {$groupId}, Option G{$groupId}-O{$optionId}, {$o}");
                     $options[] = $optionId;
                     $groups[$groupId][] = $optionId;
                 }
             }
             /**
              * create a cartesian product of the available options in order to simply assign them to articles later
              */
             $allOptions = $this->createCartesianProduct($groups);
             // Create relations
             // set-group-relations
             foreach (array_keys($groups) as $groupId) {
                 $configuratorSetGroupRelations->write("{$id}, {$groupId}");
             }
             // set-option-relations
             foreach ($options as $optionId) {
                 $configuratorSetOptionRelations->write("{$id}, {$optionId}");
             }
         }
         shuffle($validCategoryIds);
         for ($i = 0; $i < $categoriesPerArticle; $i++) {
             $articleCategories->write("{$id}, {$validCategoryIds[$i]}");
             $categoryIds = $this->getCategoryPath($validCategoryIds[$i], $categoriesFlat);
             if (empty($categoryIds)) {
                 continue;
             }
             $last = $categoryIds[0];
             foreach ($categoryIds as $categoryId) {
                 $articlesCategoriesRO->write("{$id}, {$categoryId}, {$last}");
             }
         }
         if ($this->config->getCreateImages()) {
             throw new \Exception("Not implemented, yet");
             // Images
             for ($i = 1; $i <= $numImagesPerArticle; $i++) {
                 $mediaId = $this->getUniqueId('media');
                 $name = $physicallyCreateEachImage ? $baseName . $id : $baseName;
                 $images[] = $name;
                 $mediaValues[] = "({$mediaId}, -1, {$name}, media/image/{$name}.jpg, IMAGE, jpg, 2012-08-15 )";
                 $main = $i === 1 ? 1 : 2;
                 $articlesImgValues[] = "({$id},{$name}, {$main}, jpg, {$mediaId} )";
             }
         }
         $filterOptions = $this->config->getArticleFilterOptions();
         $filterValues = $this->config->getArticleFilterValues();
         // Filters
         $filterGroupId = 1;
         if ($createFilter === 0) {
             $filterGroupId = rand(1, $filterOptions);
             for ($option = 1; $option <= $filterOptions; $option++) {
                 $optionId = $option * $filterGroupId;
                 $valueId = rand(1, $filterValues) * $optionId;
                 $filterArticles->write("{$id}, {$valueId}");
             }
         }
         #
         # Article / -details
         #
         $articles->write("{$id}, 2, {$this->generator->getSentence(3)}, SHORT DESCRIPTION, LONG DESCRIPTION, NULL, 2012-08-15, 1, 1, 20, 0, , 2012-08-30 16:57:00, 1, 0, {$filterGroupId}, 0, 0, 0, , 0, {$articleDetailId}, NULL, NULL, {$configuratorSetId}");
         // Create article details / variants
         for ($i = 1; $i <= $numberOfVariants; $i++) {
             if ($this->config->getNumberOrders() > 0) {
                 $this->articleDetailsFlat[$articleDetailId] = "{$id}|sw-{$id}-{$i}|{$articleDetailId}";
             }
             $kind = $i === 1 ? 1 : 2;
             $details->write("{$articleDetailId}, {$id}, sw-{$id}-{$i}, , {$kind}, , 0, 1, 25, 0, 0.000, 0, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0.7000, 1.000, Flasche(n), 2012-06-13, 0, ");
             $prices->write("EK, 1, beliebig, {$id}, {$articleDetailId}, 47.90 , 0, 0, 0 ");
             $attributes->write("{$id}, {$articleDetailId}");
             // don't get a new id after the last detail
             if ($i < $numberOfVariants) {
                 $articleDetailId = $this->getUniqueId('articleDetail');
                 $detailIDs[] = $articleDetailId;
             }
         }
         // Set articleDetail-option relation
         if ($createConfigurator) {
             foreach ($detailIDs as $detailID) {
                 $options = array_pop($allOptions);
                 foreach ($options as $option) {
                     $articleConfiguratorRelations->write("{$detailID}, " . $option);
                 }
             }
         }
     }
     if ($this->config->getCreateImages()) {
         $this->copyImages($this->config->getImageDir(), $images, $thumbs = $this->config->getThumbnailSizes(), $useSmallImage = 1);
     }
     $writer->write($this->loadDataInfile->get('s_articles', $articles->getFileName()));
     $writer->write($this->loadDataInfile->get('s_articles_details', $details->getFileName()));
     $writer->write($this->loadDataInfile->get('s_articles_prices', $prices->getFileName()));
     $writer->write($this->loadDataInfile->get('s_articles_categories', $articleCategories->getFileName()));
     $writer->write($this->loadDataInfile->get('s_articles_categories_ro', $articlesCategoriesRO->getFileName()));
     $writer->write($this->loadDataInfile->get('s_articles_attributes', $attributes->getFileName()));
     $writer->write($this->loadDataInfile->get('s_article_configurator_sets', $configuratorSets->getFileName()));
     $writer->write($this->loadDataInfile->get('s_article_configurator_option_relations', $articleConfiguratorRelations->getFileName()));
     $writer->write($this->loadDataInfile->get('s_article_configurator_groups', $configuratorGroups->getFileName()));
     $writer->write($this->loadDataInfile->get('s_article_configurator_options', $configuratorOptions->getFileName()));
     $writer->write($this->loadDataInfile->get('s_article_configurator_set_group_relations', $configuratorSetGroupRelations->getFileName()));
     $writer->write($this->loadDataInfile->get('s_filter_articles', $filterArticles->getFileName()));
     $this->createFilterGroupSQL($writer);
     $this->finishProgressBar();
 }