/** * @param AttributeInterface $attribute * * @throws \UnexpectedValueException */ public function addAttribute(AttributeInterface $attribute) { if (in_array($attribute->getCode(), static::$reservedCodes, true)) { throw new UnexpectedValueException("Attribute code '{$attribute->getCode()}' is a reserved code"); } $this->attributes[$attribute->getCode()] = $attribute; }
/** * @param AttributeInterface $attribute * @throws \Exception */ public function setAttributeDefaults(AttributeInterface $attribute) { $attribute->setMultiple(true); $attribute->setCollection(false); $attribute->addFormOption('attribute', $attribute); $attribute->addFormOption('inherit_data', true); }
/** * @param AttributeInterface $value * @return AttributeInterface * @throws UnexpectedValueException */ public static function normalizeVariantAttribute($value) { if (!$value instanceof AttributeInterface) { throw new UnexpectedValueException('"attribute" option must be an AttributeInterface'); } /** @var AttributeInterface $value */ if (!$value->getType() instanceof VariantAttributeType) { throw new UnexpectedValueException("Attribute's type must be a VariantAttributeType"); } return $value; }
/** * @param DataInterface $data * @param AttributeInterface $attribute */ public function __construct(DataInterface $data = null, AttributeInterface $attribute = null) { $this->data = $data; if ($attribute) { $this->attributeCode = $attribute->getCode(); } }
/** * Use label from formOptions or use translation or automatically create human readable one * * @param FamilyInterface $family * @param AttributeInterface $attribute * * @return string * @throws \InvalidArgumentException */ protected function getFieldLabel(FamilyInterface $family, AttributeInterface $attribute) { $tId = "eav.{$family->getCode()}.attribute.{$attribute->getCode()}.label"; return $this->tryTranslate($tId, [], ucfirst($attribute)); }
/** * @param AttributeInterface $attribute * * @throws UnexpectedValueException */ protected function checkAttribute(AttributeInterface $attribute) { if (!$this->getFamily()->hasAttribute($attribute->getCode())) { throw new UnexpectedValueException("Attribute {$attribute->getCode()} doesn't exists in family {$this->getFamilyCode()}"); } }
/** * @param FamilyInterface $family * @param AttributeInterface $attribute * @return bool */ protected function isAttributeInherited(FamilyInterface $family, AttributeInterface $attribute) { if (!$family->getParent()) { return false; } if ($family->getParent()->hasAttribute($attribute->getCode())) { return true; } return $this->isAttributeInherited($family->getParent(), $attribute); }
/** * Apply the join condition on the Query Builder */ protected function applyJoin() { $this->joinAlias = uniqid('join'); $qb = $this->eavQueryBuilder->getQueryBuilder(); $qb->leftJoin($this->eavQueryBuilder->getAlias() . '.values', $this->joinAlias, Join::WITH, "({$this->joinAlias}.attributeCode = '{$this->attribute->getCode()}')"); }
/** * @param AttributeInterface $attribute * @param string $type * * @return string * @throws \InvalidArgumentException */ protected function buildMessage(AttributeInterface $attribute, $type) { return $this->tryTranslate(["eav.attribute.{$attribute->getCode()}.validation.{$type}", "eav.attribute.validation.{$type}"], ['%attribute%' => $this->translator->trans((string) $attribute)], $type); }