/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->appState->setAreaCode('catalog'); /** @var ProductCollection $productCollection */ $productCollection = $this->productCollectionFactory->create(); $productIds = $productCollection->getAllIds(); if (!count($productIds)) { $output->writeln("<info>No product images to resize</info>"); return; } try { foreach ($productIds as $productId) { try { /** @var Product $product */ $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { continue; } /** @var ImageCache $imageCache */ $imageCache = $this->imageCacheFactory->create(); $imageCache->generate($product); $output->write("."); } } catch (\Exception $e) { $output->writeln("<error>{$e->getMessage()}</error>"); return; } $output->write("\n"); $output->writeln("<info>Product images resized successfully</info>"); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->appState->setAreaCode('catalog'); /** @var ProductCollection $productCollection */ $productCollection = $this->productCollectionFactory->create(); $productIds = $productCollection->getAllIds(); if (!count($productIds)) { $output->writeln("<info>No product images to resize</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } try { foreach ($productIds as $productId) { try { /** @var Product $product */ $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { continue; } /** @var ImageCache $imageCache */ $imageCache = $this->imageCacheFactory->create(); $imageCache->generate($product); $output->write("."); } } catch (\Exception $e) { $output->writeln("<error>{$e->getMessage()}</error>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $output->write("\n"); $output->writeln("<info>Product images resized successfully</info>"); }
/** * Test for `save` method for duplicated product */ public function testSaveAndDuplicate() { $this->imageCache->expects($this->once())->method('generate')->with($this->model); $this->imageCacheFactory->expects($this->once())->method('create')->willReturn($this->imageCache); $this->model->setIsDuplicate(true); $this->configureSaveTest(); $this->model->beforeSave(); $this->model->afterSave(); }