/**
  * @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);
         }
     }
 }
 /**
  * @param int|null $websiteId
  * @param string $field
  * @param bool $value
  * @param string|null $fallback
  * @return AttributeProperty
  */
 protected function createProperty($websiteId, $field, $value, $fallback = null)
 {
     $website = null;
     if ($websiteId) {
         $website = $this->getWebsite($websiteId);
     }
     $property = new AttributeProperty();
     $property->setWebsite($website)->setField($field)->setValue($value)->setFallback($fallback);
     return $property;
 }
Example #3
0
 /**
  * @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);
 }