40 private $swatchHelper;
45 private $imagesGeneratorFactory;
50 private $imagesGenerator;
57 \
Magento\Swatches\Helper\Media $swatchHelper,
58 \
Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory $imagesGeneratorFactory
60 $this->swatchHelper = $swatchHelper;
61 $this->imagesGeneratorFactory = $imagesGeneratorFactory;
79 $attribute[
'swatchvisual'][
'value'] = array_reduce(
80 range(1, $optionCount),
82 if (
$type ===
'image') {
85 if (
$type ===
'color') {
92 $attribute[
'optionvisual'][
'value'] = array_reduce(
93 range(1, $optionCount),
112 private function generateSwatchColor(
$index)
114 return '#' . str_repeat(dechex(255 *
$index), 3);
126 private function generateSwatchImage(
$data)
128 if ($this->imagesGenerator ===
null) {
129 $this->imagesGenerator = $this->imagesGeneratorFactory->create();
132 $imageName = md5(
$data) .
'.jpg';
133 $this->imagesGenerator->generate([
134 'image-width' => self::GENERATED_SWATCH_WIDTH,
135 'image-height' => self::GENERATED_SWATCH_HEIGHT,
136 'image-name' => $imageName
139 $imagePath = substr($this->swatchHelper->moveImageFromTmp($imageName), 1);
140 $this->swatchHelper->generateSwatchVariations($imagePath);
const GENERATED_SWATCH_HEIGHT
const GENERATED_SWATCH_WIDTH
const GENERATED_SWATCH_TMP_NAME
generateSwatchData($optionCount, $data, $type)
const SWATCH_INPUT_TYPE_VISUAL
__construct(\Magento\Swatches\Helper\Media $swatchHelper, \Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory $imagesGeneratorFactory)