/** * {@inheritdoc} */ public function install(array $fixtures) { /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ $adapter = $this->resource->getConnection('core_write'); $regions = $this->loadDirectoryRegions(); foreach ($fixtures as $fileName) { $fileName = $this->fixtureManager->getFixture($fileName); if (!file_exists($fileName)) { continue; } $rows = $this->csvReader->getData($fileName); $header = array_shift($rows); foreach ($rows as $row) { $data = []; foreach ($row as $key => $value) { $data[$header[$key]] = $value; } $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0; try { $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsite()->getId(), '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->configWriter->save('carriers/tablerate/active', 1); $this->configWriter->save('carriers/tablerate/condition_name', 'package_value'); $this->cacheTypeList->cleanType('config'); }
/** * Return import condition full name by condition name code * * @param string $conditionName * @return string */ protected function _getConditionFullName($conditionName) { if (!isset($this->_conditionFullNames[$conditionName])) { $name = $this->carrierTablerate->getCode('condition_name_short', $conditionName); $this->_conditionFullNames[$conditionName] = $name; } return $this->_conditionFullNames[$conditionName]; }