/** * 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 dataIsTextSwatch */ public function testIsTextSwatch($swatchType, $boolResult) { $this->attributeMock->method('hasData')->with('swatch_input_type')->willReturn(true); $this->attributeMock->expects($this->once())->method('getData')->with('swatch_input_type')->willReturn($swatchType); $result = $this->swatchHelperObject->isTextSwatch($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; }