Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing taxes:');
     $fixtureFile = 'Tax/tax_rate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $taxRate = $this->rateFactory->create();
         $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
         $this->taxRateRepository->save($taxRate);
         $this->logger->logInline('.');
     }
     $fixtureFile = 'Tax/tax_rule.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
         $taxRule = $this->ruleFactory->create();
         $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
         $this->taxRuleRepository->save($taxRule);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing orders:');
     foreach ($this->fixtures as $file) {
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         $isFirst = true;
         foreach ($csvReader as $row) {
             if ($isFirst) {
                 $customer = $this->customerRepository->get($row['customer_email']);
                 if (!$customer->getId()) {
                     continue;
                 }
                 /** @var \Magento\Sales\Model\Resource\Collection $orderCollection */
                 $orderCollection = $this->orderCollectionFactory->create();
                 $orderCollection->addFilter('customer_id', $customer->getId());
                 if ($orderCollection->count() > 0) {
                     break;
                 }
             }
             $isFirst = false;
             $orderData = $this->converter->convertRow($row);
             $this->orderProcessor->createOrder($orderData);
             $this->logger->logInline('.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog rules:');
     $file = 'CatalogRule/catalog_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         /** @var \Magento\CatalogRule\Model\Resource\Rule\Collection $ruleCollection */
         $ruleCollection = $this->ruleCollectionFactory->create();
         $ruleCollection->addFilter('name', $row['name']);
         if ($ruleCollection->count() > 0) {
             continue;
         }
         $row['customer_group_ids'] = $this->getGroupIds();
         $row['website_ids'] = $this->getWebsiteIds();
         $row['conditions_serialized'] = $this->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->convertSerializedData($row['actions_serialized']);
         $ruleModel = $this->ruleFactory->create();
         $ruleModel->loadPost($row);
         $ruleModel->save();
         $this->logger->logInline('.');
     }
     $ruleJob = $this->jobFactory->create();
     $ruleJob->applyAll();
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing MAP:');
     $this->configWriter->save('sales/msrp/enabled', 1);
     $fixtureFile = 'Msrp/products_msrp.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $productId = $this->getProductIdBySku($row['sku']);
         if (!$productId) {
             continue;
         }
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $this->productCollection->getItemById($productId);
         $product->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_ON_GESTURE);
         if (!empty($row['msrp'])) {
             $price = $row['msrp'];
         } else {
             $price = $product->getPrice() * 1.1;
         }
         $product->setMsrp($price);
         $product->save();
         $this->logger->logInline('.');
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Widgets:');
     $pageGroupConfig = ['pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'all_pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'anchor_categories' => ['entities' => '', 'block' => '', 'for' => 'all', 'is_anchor_only' => 0, 'layout_handle' => 'catalog_category_view_type_layered', 'template' => 'widget/static_block/default.phtml', 'page_id' => '']];
     foreach ($this->fixtures as $file) {
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $block = $this->cmsBlockFactory->create()->load($row['block_identifier'], 'identifier');
             if (!$block) {
                 continue;
             }
             $widgetInstance = $this->widgetFactory->create();
             $code = $row['type_code'];
             $themeId = $this->themeCollectionFactory->create()->getThemeByFullPath($row['theme_path'])->getId();
             $type = $widgetInstance->getWidgetReference('code', $code, 'type');
             $pageGroup = [];
             $group = $row['page_group'];
             $pageGroup['page_group'] = $group;
             $pageGroup[$group] = array_merge($pageGroupConfig[$group], unserialize($row['group_data']));
             if (!empty($pageGroup[$group]['entities'])) {
                 $pageGroup[$group]['entities'] = $this->getCategoryByUrlKey($pageGroup[$group]['entities'])->getId();
             }
             $widgetInstance->setType($type)->setCode($code)->setThemeId($themeId);
             $widgetInstance->setTitle($row['title'])->setStoreIds([\Magento\Store\Model\Store::DEFAULT_STORE_ID])->setWidgetParameters(['block_id' => $block->getId()])->setPageGroups([$pageGroup]);
             $widgetInstance->save();
             $this->logger->logInline('.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing sales rules:');
     $file = 'SalesRule/sales_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     $attribute = $this->eavConfig->getAttribute('catalog_product', 'sku');
     if ($attribute->getIsUsedForPromoRules() == 0) {
         $attribute->setIsUsedForPromoRules('1')->save();
     }
     foreach ($csvReader as $row) {
         /** @var \Magento\SalesRule\Model\Resource\Rule\Collection $ruleCollection */
         $ruleCollection = $this->ruleCollectionFactory->create();
         $ruleCollection->addFilter('name', $row['name']);
         if ($ruleCollection->count() > 0) {
             continue;
         }
         $row['customer_group_ids'] = $this->catalogRule->getGroupIds();
         $row['website_ids'] = $this->catalogRule->getWebsiteIds();
         $row['conditions_serialized'] = $this->catalogRule->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->catalogRule->convertSerializedData($row['actions_serialized']);
         /** @var \Magento\SalesRule\Model\Rule $rule */
         $rule = $this->ruleFactory->create();
         $rule->loadPost($row);
         $rule->save();
         $this->logger->logInline('.');
     }
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing product links:');
     $entityFileAssociation = ['related', 'upsell', 'crosssell'];
     foreach ($this->postInstaller->getInstalledModuleList() as $moduleName) {
         foreach ($entityFileAssociation as $linkType) {
             $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/Links/' . $linkType . '.csv';
             $fileName = $this->fixtureHelper->getPath($fileName);
             if (!$fileName) {
                 continue;
             }
             /** @var \Magento\SampleData\Helper\Csv\ReaderFactory $csvReader */
             $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
             foreach ($csvReader as $row) {
                 /** @var \Magento\Catalog\Model\Product $product */
                 $product = $this->productFactory->create();
                 $productId = $product->getIdBySku($row['sku']);
                 if (!$productId) {
                     continue;
                 }
                 $product->setId($productId);
                 $links = [$linkType => []];
                 foreach (explode("\n", $row['linked_sku']) as $linkedProductSku) {
                     $linkedProductId = $product->getIdBySku($linkedProductSku);
                     if ($linkedProductId) {
                         $links[$linkType][$linkedProductId] = [];
                     }
                 }
                 $this->linksInitializer->initializeLinks($product, $links);
                 $product->getLinkInstance()->saveProductRelations($product);
                 $this->logger->logInline('.');
             }
         }
     }
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing orders:');
     foreach ($this->fixtures as $file) {
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $orderData = $this->converter->convertRow($row);
             $this->orderProcessor->createOrder($orderData);
             $this->logger->logInline('.');
         }
     }
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing CMS pages:');
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $this->pageFactory->create()->load($row['identifier'], 'identifier')->addData($row)->setStores([\Magento\Store\Model\Store::DEFAULT_STORE_ID])->save();
             $this->logger->logInline('.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing taxes:');
     $fixtureFile = 'Tax/tax_rate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         if ($this->rateFactory->create()->loadByCode($data['code'])->getId()) {
             continue;
         }
         $taxRate = $this->rateFactory->create();
         $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
         $this->taxRateRepository->save($taxRate);
         $this->logger->logInline('.');
     }
     $fixtureFile = 'Tax/tax_rule.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $filter = $this->filterBuilder->setField('code')->setConditionType('=')->setValue($data['code'])->create();
         $criteria = $this->criteriaBuilder->addFilters([$filter])->create();
         $existingRates = $this->taxRuleRepository->getList($criteria)->getItems();
         if (!empty($existingRates)) {
             continue;
         }
         $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
         $taxRule = $this->ruleFactory->create();
         $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
         $this->taxRuleRepository->save($taxRule);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Tablerate:');
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
     $connection = $this->resource->getConnection('core');
     $fixtureFile = 'OfflineShipping/tablerate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     $regions = $this->loadDirectoryRegions();
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
         try {
             $connection->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
         } catch (\Zend_Db_Statement_Exception $e) {
             if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) {
                 // In case if Sample data was already installed we just skip duplicated records installation
                 continue;
             } else {
                 throw $e;
             }
         }
         $this->logger->logInline('.');
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing product reviews:');
     $fixtureFile = 'Review/products_reviews.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $storeId = [$this->storeManager->getStoreId()];
         $review = $this->prepareReview($row);
         $this->createRating($row['rating_code'], $storeId);
         $productId = $this->getProductIdBySku($row['sku']);
         if (empty($productId)) {
             continue;
         }
         /** @var \Magento\Review\Model\Resource\Review\Collection $reviewCollection */
         $reviewCollection = $this->reviewCollectionFactory->create();
         $reviewCollection->addFilter('entity_pk_value', $productId)->addFilter('entity_id', $this->getReviewEntityId())->addFieldToFilter('detail.title', ['eq' => $row['title']]);
         if ($reviewCollection->getSize() > 0) {
             continue;
         }
         if (!empty($row['email']) && $this->getCustomerIdByEmail($row['email']) != null) {
             $review->setCustomerId($this->getCustomerIdByEmail($row['email']));
         }
         $review->save();
         $this->setReviewRating($review, $row);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing related product rules:');
     $this->postInstaller->removeSetupResourceType('Magento\\SampleData\\Module\\Catalog\\Setup\\ProductLink');
     $entityFileAssociation = [\Magento\TargetRule\Model\Rule::RELATED_PRODUCTS => 'related', \Magento\TargetRule\Model\Rule::UP_SELLS => 'upsell', \Magento\TargetRule\Model\Rule::CROSS_SELLS => 'crosssell'];
     foreach ($entityFileAssociation as $linkTypeId => $linkType) {
         $fileName = 'TargetRule/' . $linkType . '.csv';
         $fileName = $this->fixtureHelper->getPath($fileName);
         if (!$fileName) {
             continue;
         }
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             /** @var \Magento\TargetRule\Model\Rule $rule */
             $rule = $this->ruleFactory->create();
             if ($rule->getResourceCollection()->addFilter('name', $row['name'])->getSize() > 0) {
                 continue;
             }
             $sourceCategory = $this->getConditionFromCategory(array_filter(explode("\n", $row['source_category'])), 'Rule');
             $targetCategory = $this->getConditionFromCategory(array_filter(explode("\n", $row['target_category'])), 'Actions');
             if (!$sourceCategory || !$targetCategory) {
                 continue;
             }
             $targetCategory['value_type'] = TargetRuleActionAttributes::VALUE_TYPE_CONSTANT;
             $ruleConditions = $this->createConditions($sourceCategory, $targetCategory);
             $rule->setName($row['name'])->setApplyTo($linkTypeId)->setIsActive(1)->setSortOrder(0)->setPositionsLimit(empty($row['limit']) ? 0 : $row['limit']);
             $rule->loadPost($ruleConditions);
             $rule->save();
             $this->logger->logInline('.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing customers:');
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             // Collect customer profile and addresses data
             $customerData['profile'] = $this->convertRowData($row, $this->getDefaultCustomerProfile());
             if (!$this->accountManagement->isEmailAvailable($customerData['profile']['email'])) {
                 continue;
             }
             $customerData['address'] = $this->convertRowData($row, $this->getDefaultCustomerAddress());
             $customerData['address']['region_id'] = $this->getRegionId($customerData['address']);
             $address = $customerData['address'];
             $regionData = [RegionInterface::REGION_ID => $address['region_id'], RegionInterface::REGION => !empty($address['region']) ? $address['region'] : null, RegionInterface::REGION_CODE => !empty($address['region_code']) ? $address['region_code'] : null];
             $region = $this->regionFactory->create();
             $this->dataObjectHelper->populateWithArray($region, $regionData, '\\Magento\\Customer\\Api\\Data\\RegionInterface');
             $addresses = $this->addressFactory->create();
             unset($customerData['address']['region']);
             $this->dataObjectHelper->populateWithArray($addresses, $customerData['address'], '\\Magento\\Customer\\Api\\Data\\AddressInterface');
             $addresses->setRegion($region)->setIsDefaultBilling(true)->setIsDefaultShipping(true);
             $customer = $this->customerFactory->create();
             $this->dataObjectHelper->populateWithArray($customer, $customerData['profile'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
             $customer->setAddresses([$addresses]);
             $this->accountManagement->createAccount($customer, $row['password']);
             $this->logger->logInline('.');
         }
     }
 }
Esempio n. 15
0
 /**
  * Add Link to Head
  *
  * @return void
  */
 protected function addHeadInclude()
 {
     $styleContent = '';
     foreach ($this->moduleList->getNames() as $moduleName) {
         $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/styles.css';
         $fileName = $this->fixtureHelper->getPath($fileName);
         if (!$fileName) {
             continue;
         }
         $style = file_get_contents($fileName);
         $styleContent .= preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', $style);
     }
     if (empty($styleContent)) {
         return;
     }
     $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
     file_put_contents("{$mediaDir}/styles.css", $styleContent);
     $linkTemplate = '<link  rel="stylesheet" type="text/css"  media="all" href="%sstyles.css" />';
     $baseUrl = $this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]);
     $linkText = sprintf($linkTemplate, $baseUrl);
     $miscScriptsNode = 'design/head/includes';
     $miscScripts = $this->scopeConfig->getValue($miscScriptsNode);
     if (!$miscScripts || strpos($miscScripts, $linkText) === false) {
         $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText);
         $this->configCacheType->clean();
     }
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log("Installing {$this->productType} products:");
     $product = $this->productFactory->create();
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']);
             $this->converter->setAttributeSetId($attributeSetId);
             $data = $this->converter->convertRow($row);
             $product->unsetData();
             $product->setData($data);
             $product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
             if (empty($data['visibility'])) {
                 $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
             }
             $this->prepareProduct($product, $data);
             $product->save();
             $this->gallery->install($product);
             $this->logger->logInline('.');
         }
     }
 }
Esempio n. 17
0
 public function getPath($subPath)
 {
     $file = realpath(__DIR__ . '/../_files/fixtures/' . ltrim($subPath, '/'));
     if (file_exists($file)) {
         return $file;
     }
     return parent::getPath($subPath);
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog rules:');
     $file = 'CatalogRule/catalog_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $row['customer_group_ids'] = $this->getGroupIds();
         $row['website_ids'] = $this->getWebsiteIds();
         $row['conditions_serialized'] = $this->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->convertSerializedData($row['actions_serialized']);
         $ruleModel = $this->ruleFactory->create();
         $ruleModel->loadPost($row);
         $ruleModel->save();
         $this->logger->logInline('.');
     }
     $ruleJob = $this->jobFactory->create();
     $ruleJob->applyAll();
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing sales rules:');
     $file = 'SalesRule/sales_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     $attribute = $this->eavConfig->getAttribute('catalog_product', 'sku');
     if ($attribute->getIsUsedForPromoRules() == 0) {
         $attribute->setIsUsedForPromoRules('1')->save();
     }
     foreach ($csvReader as $row) {
         $row['customer_group_ids'] = $this->catalogRule->getGroupIds();
         $row['website_ids'] = $this->catalogRule->getWebsiteIds();
         $row['conditions_serialized'] = $this->catalogRule->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->catalogRule->convertSerializedData($row['actions_serialized']);
         $rule = $this->ruleFactory->create();
         $rule->loadPost($row);
         $rule->save();
         $this->logger->logInline('.');
     }
 }
 /**
  * Load data from fixtures
  * @return void
  */
 protected function loadFixtures()
 {
     $this->images = [];
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $this->images[$row['sku']][] = $row['image'];
         }
     }
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog attributes:');
     $attributeCount = 0;
     foreach ($this->moduleList->getNames() as $moduleName) {
         $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/attributes.csv';
         $fileName = $this->fixtureHelper->getPath($fileName);
         if (!$fileName) {
             continue;
         }
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $data) {
             $data['attribute_set'] = explode("\n", $data['attribute_set']);
             /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */
             $attribute = $this->eavConfig->getAttribute('catalog_product', $data['attribute_code']);
             if (!$attribute) {
                 $attribute = $this->attributeFactory->create();
             }
             $frontendLabel = explode("\n", $data['frontend_label']);
             if (count($frontendLabel) > 1) {
                 $data['frontend_label'] = [];
                 $data['frontend_label'][\Magento\Store\Model\Store::DEFAULT_STORE_ID] = $frontendLabel[0];
                 $data['frontend_label'][$this->storeManager->getStoreId()] = $frontendLabel[1];
             }
             $data['option'] = $this->getOption($attribute, $data);
             $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($data['frontend_input']);
             $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($data['frontend_input']);
             $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []];
             $data['backend_type'] = $attribute->getBackendTypeByInput($data['frontend_input']);
             $attribute->addData($data);
             $attribute->setIsUserDefined(1);
             $attribute->setEntityTypeId($this->getEntityTypeId());
             $attribute->save();
             $attributeId = $attribute->getId();
             if (is_array($data['attribute_set'])) {
                 foreach ($data['attribute_set'] as $setName) {
                     $setName = trim($setName);
                     $attributeCount++;
                     $attributeSet = $this->processAttributeSet($setName);
                     $attributeGroupId = $attributeSet->getDefaultGroupId();
                     $attribute = $this->attributeFactory->create();
                     $attribute->setId($attributeId)->setAttributeGroupId($attributeGroupId)->setAttributeSetId($attributeSet->getId())->setEntityTypeId($this->getEntityTypeId())->setSortOrder($attributeCount + 999)->save();
                 }
             }
             $this->logger->logInline('.');
         }
     }
     $this->eavConfig->clear();
 }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing wishlists:');
     $fixtureFile = 'Wishlist/wishlist.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         /** @var \Magento\Customer\Model\Customer $customer */
         $customer = $this->wishlistHelper->getCustomerByEmail($row['customer_email']);
         if (!$customer) {
             continue;
         }
         /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
         $wishlist = $this->wishlistFactory->create();
         $wishlist->loadByCustomerId($customer->getId(), true);
         if (!$wishlist->getId()) {
             continue;
         }
         $productSkuList = explode("\n", $row['product_list']);
         $this->wishlistHelper->addProductsToWishlist($wishlist, $productSkuList);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing categories:');
     $this->isMediaInstalled();
     foreach ($this->moduleList->getNames() as $moduleName) {
         $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/categories.csv';
         $fileName = $this->fixtureHelper->getPath($fileName);
         if (!$fileName) {
             continue;
         }
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $this->createCategory($row);
         }
     }
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Tablerate:');
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('core_write');
     $fixtureFile = 'OfflineShipping/tablerate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     $regions = $this->loadDirectoryRegions();
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
         $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
         $this->logger->logInline('.');
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing product reviews:');
     $fixtureFile = 'Review/products_reviews.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $storeId = [$this->storeManager->getStoreId()];
         $this->createRating($row['rating_code'], $storeId);
         if (!$this->getProductIdBySku($row['sku'])) {
             continue;
         }
         $review = $this->prepareReview($row);
         if (!empty($row['email']) && $this->getCustomerIdByEmail($row['email']) != null) {
             $review->setCustomerId($this->getCustomerIdByEmail($row['email']));
         }
         $review->save();
         $this->setReviewRating($review, $row);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing multiple wishlists:');
     $multipleEnabledConfig = 'wishlist/general/multiple_enabled';
     if (!$this->config->isSetFlag($multipleEnabledConfig)) {
         $this->configWriter->save($multipleEnabledConfig, 1);
         $this->configCacheType->clean();
     }
     $fixtureFiles = ['Wishlist/wishlist.csv', 'MultipleWishlist/wishlist.csv'];
     foreach ($fixtureFiles as $fixtureFile) {
         $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             /** @var \Magento\Customer\Model\Customer $customer */
             $customer = $this->wishlistHelper->getCustomerByEmail($row['customer_email']);
             if (!$customer) {
                 continue;
             }
             $wishlistName = $row['name'];
             /** @var \Magento\Wishlist\Model\Resource\Wishlist\Collection $wishlistCollection */
             $wishlistCollection = $this->wishlistColFactory->create();
             $wishlistCollection->filterByCustomerId($customer->getId())->addFieldToFilter('name', $wishlistName);
             /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
             $wishlist = $wishlistCollection->fetchItem();
             if ($wishlist) {
                 continue;
             }
             $wishlist = $this->wishlistEditor->edit($customer->getId(), $wishlistName, true);
             if (!$wishlist->getId()) {
                 continue;
             }
             $productSkuList = explode("\n", $row['product_list']);
             $this->wishlistHelper->addProductsToWishlist($wishlist, $productSkuList);
             $this->logger->logInline('.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Gift Registry:');
     $fixtureFile = 'GiftRegistry/gift_registry.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $giftRegistryData) {
         /** @var \Magento\GiftRegistry\Model\Resource\Entity\Collection $collection */
         $collection = $this->collectionFactory->create();
         $collection->addFilter('title', $giftRegistryData['title']);
         if ($collection->count() > 0) {
             continue;
         }
         $data = $this->generateData($giftRegistryData);
         /** @var \Magento\GiftRegistry\Model\Entity $giftRegistry */
         $giftRegistry = $this->giftRegistryFactory->create();
         $address = $this->addressFactory->create();
         $address->setData($data['address']);
         $giftRegistry->setTypeById($data['type_id']);
         $giftRegistry->importData($data);
         $giftRegistry->addData(['customer_id' => $data['customer_id'], 'website_id' => $this->storeManager->getWebsiteId(), 'url_key' => $giftRegistry->getGenerateKeyId(), 'created_at' => $this->dateFactory->create()->date(), 'is_add_action' => true]);
         $giftRegistry->importAddress($address);
         $validationPassed = $giftRegistry->validate();
         if ($validationPassed) {
             $giftRegistry->save();
             foreach ($data['items'] as $productId) {
                 $parentId = $this->productIndexer->getRelationsByChild($productId);
                 $itemProduct = $parentId ? $parentId[0] : $productId;
                 $itemOptions = $this->formItemOptions($productId);
                 $item = $this->itemFactory->create();
                 $item->setEntityId($giftRegistry->getId())->setProductId($itemProduct)->setQty(1)->setOptions($itemOptions)->save();
             }
         }
         $this->logger->logInline('.');
     }
 }