/** * Returns Configurable Products Collection with added swatch attributes * * @param ConfigurableProduct $subject * @param Collection $result * @return Collection * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetUsedProductCollection(ConfigurableProductType $subject, Collection $result) { $attributeCodes = ['image']; $entityType = $result->getEntity()->getType(); foreach ($this->eavConfig->getEntityAttributeCodes($entityType) as $code) { $attribute = $this->eavConfig->getAttribute($entityType, $code); if ($this->swatchHelper->isVisualSwatch($attribute) || $this->swatchHelper->isTextSwatch($attribute)) { $attributeCodes[] = $code; } } $result->addAttributeToSelect($attributeCodes); return $result; }
/** * Save all Swatches data * * @param Attribute $attribute * @return void */ protected function saveSwatchParams(Attribute $attribute) { if ($this->swatchHelper->isVisualSwatch($attribute)) { $this->processVisualSwatch($attribute); } elseif ($this->swatchHelper->isTextSwatch($attribute)) { $this->processTextualSwatch($attribute); } }
/** * @dataProvider dataForIsVisualSwatchType */ public function testIsVisualSwatchFalse($data, $count, $swatchType, $boolResult) { $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(false); $this->attributeMock->expects($this->exactly(2))->method('getData')->withConsecutive(['additional_data'], ['swatch_input_type'])->willReturnOnConsecutiveCalls($data, $swatchType); $this->attributeMock->expects($this->exactly($count['setData']))->method('setData'); $result = $this->swatchHelperObject->isVisualSwatch($this->attributeMock); if ($boolResult) { $this->assertTrue($result); } else { $this->assertFalse($result); } }
/** * Validate that attribute options exist * * @param Attribute $attribute * @return bool * @throws InputException */ protected function validateOptions(Attribute $attribute) { $options = null; if ($this->swatchHelper->isVisualSwatch($attribute)) { $options = $attribute->getData('optionvisual'); } elseif ($this->swatchHelper->isTextSwatch($attribute)) { $options = $attribute->getData('optiontext'); } if ($options && !$this->isOptionsValid($options, $attribute)) { throw new InputException(__('Admin is a required field in the each row')); } return true; }