/** * Set attribute value (default) * * @param \XLite\Model\Repo\ARepo $repo Repository * @param \XLite\Model\Product $product Product * @param mixed $data Data * * @return \XLite\Model\AttributeValue\AttributeValueText */ protected function setAttributeValueDefault(\XLite\Model\Repo\ARepo $repo, \XLite\Model\Product $product, $data) { $editable = is_array($data) && self::TYPE_TEXT === $this->getType() ? !empty($data['editable']) : null; $value = is_array($data) ? $data['value'] : $data; if (is_array($value)) { $value = array_shift($value); } $delete = true; $attributeValue = null; if ('' !== $value || null !== $editable) { $attributeValue = $repo->findOneBy(array('product' => $product, 'attribute' => $this)); if (!$attributeValue) { $attributeValue = $this->createAttributeValue($product); $delete = false; } $attributeValue->setValue($value); if (null !== $editable) { $attributeValue->setEditable($editable); } } if ($delete) { foreach ($repo->findBy(array('product' => $product, 'attribute' => $this)) as $data) { if (!$attributeValue || $attributeValue->getId() != $data->getId()) { $repo->delete($data, false); } } } return $attributeValue; }