/** * @return array */ public function getSwatchData() { if (false === $this->eavAttribute instanceof Attribute) { throw new \RuntimeException('Magento_Swatches: RenderLayered: Attribute has not been set.'); } $attributeOptions = []; foreach ($this->eavAttribute->getOptions() as $option) { if ($currentOption = $this->getFilterOption($this->filter->getItems(), $option)) { $attributeOptions[$option->getValue()] = $currentOption; } elseif ($this->isShowEmptyResults()) { $attributeOptions[$option->getValue()] = $this->getUnusedOption($option); } } $attributeOptionIds = array_keys($attributeOptions); $swatches = $this->swatchHelper->getSwatchesByOptionsId($attributeOptionIds); $data = ['attribute_id' => $this->eavAttribute->getId(), 'attribute_code' => $this->eavAttribute->getAttributeCode(), 'attribute_label' => $this->eavAttribute->getStoreLabel(), 'options' => $attributeOptions, 'swatches' => $swatches]; return $data; }