/** * @param Attribute $attribute * @param string $field * @param array $values */ public function setPropertyValues(Attribute $attribute, $field, array $values) { foreach ($values as $websiteId => $value) { $attributeProperty = $attribute->getPropertyByFieldAndWebsiteId($field, $websiteId); if (!$attributeProperty) { $attributeProperty = new AttributeProperty(); $attributeProperty->setField($field); if ($websiteId) { $attributeProperty->setWebsite($this->databaseHelper->findWebsite($websiteId)); } $attribute->addProperty($attributeProperty); } if ($value instanceof FallbackType) { $attributeProperty->setValue(null)->setFallback($value->getType()); } else { $attributeProperty->setValue($value)->setFallback(null); } } }
/** * @expectedException \LogicException * @expectedExceptionMessage Several attribute properties found by the same field and locale ID. */ public function testGetPropertyByFieldAndWebsiteIdException() { $website = $this->createWebsite(1); $firstProperty = new AttributeProperty(); $firstProperty->setField(AttributeProperty::FIELD_USE_FOR_SEARCH)->setWebsite($website); $secondProperty = new AttributeProperty(); $secondProperty->setField(AttributeProperty::FIELD_USE_FOR_SEARCH)->setWebsite($website); $attribute = new Attribute(); $attribute->resetProperties([$firstProperty, $secondProperty]); $attribute->getPropertyByFieldAndWebsiteId(AttributeProperty::FIELD_USE_FOR_SEARCH, 1); }