/** * Given a Variant, return a list of the associated Attributes * * The Attribute is fetched from the "options" relation. In theory * each option in a Variant should belong to a different Attribute. * * @param VariantInterface $variant * * @return array */ protected function getUniqueAttributesFromVariant(VariantInterface $variant) { $variantAttributes = []; foreach ($variant->getOptions() as $option) { /** * @var AttributeInterface $attribute */ $attribute = $option->getAttribute(); if (!array_key_exists($attribute->getId(), $variantAttributes)) { $variantAttributes[$attribute->getId()] = $attribute; } } return $variantAttributes; }
/** * Resolve name for variant. * * @param VariantInterface $variant Variant * @param string $separator Separator string for product variant options * * @return string Resolve product name */ private function resolveVariantName(VariantInterface $variant, $separator = self::DEFAULT_SEPARATOR) { $variantName = $variant->getProduct()->getName(); foreach ($variant->getOptions() as $option) { /** * @var ValueInterface $option */ $variantName .= $separator . $option->getAttribute()->getName() . ' ' . $option->getValue(); } return $variantName; }