/** * @param Attribute $attribute * @param AttributeOption $option * @param int $localeId * @return AttributeDefaultValue */ protected function generateOptionDefaultValue(Attribute $attribute, AttributeOption $option, $localeId) { $defaultValue = null; if ($option->getId()) { $defaultValue = $attribute->getDefaultValueByLocaleIdAndOptionId($localeId, $option->getId()); } if (!$defaultValue) { $defaultValue = new AttributeDefaultValue(); if ($localeId) { $defaultValue->setLocale($this->databaseHelper->findLocale($localeId)); } } $defaultValue->setOption($option); return $defaultValue; }
/** * @param int|null $localeId * @param string|null $fallback * @return AttributeDefaultValue */ protected function createDefaultValue($localeId, $fallback = null) { $locale = null; if ($localeId) { $locale = $this->getLocale($localeId); } $defaultValue = new AttributeDefaultValue(); $defaultValue->setLocale($locale)->setFallback($fallback); return $defaultValue; }
/** * @expectedException \LogicException * @expectedExceptionMessage Several attribute default values found by the same locale ID and option ID. */ public function testGetDefaultValueByLocaleIdAndOptionIdException() { $locale = $this->createLocale(1); $option = $this->createAttributeOption(2); $firstValue = new AttributeDefaultValue(); $firstValue->setLocale($locale)->setOption($option); $secondValue = new AttributeDefaultValue(); $secondValue->setLocale($locale)->setOption($option); $attribute = new Attribute(); $attribute->resetDefaultValues([$firstValue, $secondValue]); $attribute->getDefaultValueByLocaleIdAndOptionId(1, 2); }