diff --git a/Component/CustomerGroups.php b/Component/CustomerGroups.php index 2072451..d9dc006 100644 --- a/Component/CustomerGroups.php +++ b/Component/CustomerGroups.php @@ -60,9 +60,8 @@ public function execute($data = null) if ($taxClassId) { foreach ($taxClass['groups'] as $group) { try { - if (isset($group['name'])) { - $this->createCustomerGroup($group['name'], $taxClassId); - } + $this->validateGroupName($group); + $this->createCustomerGroup($group['name'], $taxClassId); } catch (ComponentException $e) { $this->log->logError($e->getMessage()); } @@ -100,6 +99,26 @@ private function createCustomerGroup($groupName, $taxClassId) ); } + /** + * perform customer group name validation + * + * @param array $group + * @return null + * @throw ComponentException + */ + private function validateGroupName(array $group) + { + if (!isset($group['name'])) { + throw new ComponentException(__('The customer group name is mandatory')); + } + + if (strlen($group['name'])>32) { + throw new ComponentException( + __('The customer group name "%1" is too long (maximum length is 32 characters)', $group['name']) + ); + } + } + /** * Return tax class id when given name * diff --git a/Component/Product/Image.php b/Component/Product/Image.php index a47196b..978ed93 100644 --- a/Component/Product/Image.php +++ b/Component/Product/Image.php @@ -5,8 +5,10 @@ use Magento\Framework\Filesystem; use Magento\Framework\App\Filesystem\DirectoryList; use FireGento\FastSimpleImport\Model\Config; -use Magento\Framework\HTTP\ZendClient; -use Magento\Framework\HTTP\ZendClientFactory; +use GuzzleHttp\Client; +use GuzzleHttp\ClientFactory; +use GuzzleHttp\Exception\GuzzleException; +use Magento\Framework\Webapi\Rest\Request; class Image { @@ -15,11 +17,6 @@ class Image */ protected $log; - /** - * @var ZendClientFactory - */ - protected $httpClientFactory; - /** * @var Filesystem */ @@ -36,21 +33,25 @@ class Image private $separator = ';'; /** - * Image constructor. + * @var ClientFactory + */ + private ClientFactory $clientFactory; + + /** * @param Filesystem $filesystem * @param Config $importerConfig - * @param ZendClientFactory $httpClientFactory + * @param ClientFactory $clientFactory * @param LoggerInterface $log */ public function __construct( Filesystem $filesystem, Config $importerConfig, - ZendClientFactory $httpClientFactory, + ClientFactory $clientFactory, LoggerInterface $log ) { $this->filesystem = $filesystem; $this->importerConfig = $importerConfig; - $this->httpClientFactory = $httpClientFactory; + $this->clientFactory = $clientFactory; $this->log = $log; } @@ -90,19 +91,17 @@ public function isValueURL($url) public function downloadFile($value) { /** - * @var ZendClient $client + * @var Client $client */ - $client = $this->httpClientFactory->create(); - $response = ''; + $client = $this->clientFactory->create(); try { - $response = $client - ->setUri($value) - ->request('GET') - ->getBody(); - } catch (\Exception $e) { + $response = $client->request(Request::HTTP_METHOD_GET, $value)->getBody(); + } catch (GuzzleException $e) { + $response = ''; $this->log->logError($e->getMessage()); } + return $response; } @@ -114,12 +113,17 @@ public function downloadFile($value) */ public function getFileName($url) { - // phpcs:ignore Magento2.Functions.DiscouragedFunction - $imageName = basename((string) $url); - // Remove any URL entities - $imageName = urldecode($imageName); - // Replace spaces with - - $imageName = preg_replace('/\s+/', '-', $imageName); + if (preg_match('/http:\/\/placehold\.it\/(.*)\/jpg$/', $url, $match)) { + $imageName = sprintf('%s.jpg', $match[1]); + } else { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $imageName = basename((string) $url); + // Remove any URL entities + $imageName = urldecode($imageName); + // Replace spaces with - + $imageName = preg_replace('/\s+/', '-', $imageName); + } + return $imageName; } @@ -207,11 +211,12 @@ public function getImage($value) */ public function getFileDirectory(\Magento\Framework\Filesystem\Directory\WriteInterface $file) { - $configurationValue = $this->importerConfig->getImportFileDir(); - if (!empty($configurationValue)) { - return $file->getRelativePath($configurationValue); + try { + $configurationValue = $this->importerConfig->getImportFileDir(); + return $file->getRelativePath($configurationValue); + } catch (\TypeError $e) { + return $file->getRelativePath('import'); } - return $file->getRelativePath('import'); } /** diff --git a/Component/Product/Validator.php b/Component/Product/Validator.php index 8b793d6..b53474d 100644 --- a/Component/Product/Validator.php +++ b/Component/Product/Validator.php @@ -125,7 +125,7 @@ public function getImportRowFailures(Importer $import, $importLines) { $failedRows = []; // Creates a validation model and runs the import data through so we can find which rows would fail - $validation = $import->createImportModel(); + $validation = $import->getImportModel(); $validationSource = $this->importAdapterFactory->create([ 'data' => $importLines, 'multipleValueSeparator' => Products::SEPARATOR diff --git a/Model/Logging.php b/Model/Logging.php index fe7dd41..8911424 100644 --- a/Model/Logging.php +++ b/Model/Logging.php @@ -35,6 +35,9 @@ public function log($message, $level, $nest = 0) for ($i = 0; $i < $nest; $i++) { $prepend .= "| "; } + if (is_array($message)) { + $message = 'Log array: ' . print_r($message, 1); + } $this->output->writeln($prepend . '<' . $level . '>' . $message . ''); } diff --git a/Model/Processor.php b/Model/Processor.php index 679401f..e52b58e 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -180,6 +180,7 @@ private function runAllComponents() // Loop through components and run them individually in the master.yaml order foreach ($master as $componentAlias => $componentConfig) { + if ($componentConfig['enabled'] === 0) continue; // Run the component in question $this->state->emulateAreaCode( Area::AREA_ADMINHTML, diff --git a/composer.json b/composer.json index 4ec781a..b7851fe 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "phpunit/phpunit": "^6.2", "magento/magento-coding-standard": "5" }, - "version": "3.2.0", + "version": "3.2.1", "autoload": { "files": [ "registration.php" ], "psr-4": {