Esempio n. 1
0
 /**
  * Get attribute value data
  *
  * @param array                  $data      Import row data
  * @param \XLite\Model\Attribute $attribute Attribute object
  *
  * @return array
  */
 protected function getAttributeValueData($data, $attribute)
 {
     $option = \XLite\Core\Database::getRepo('XLite\\Model\\AttributeOption')->findOneByNameAndAttribute($data['value'], $attribute);
     if (!$option) {
         $option = new \XLite\Model\AttributeOption();
         $option->setAttribute($attribute);
         $option->setName($data['value']);
         \XLite\Core\Database::getEM()->persist($option);
     }
     return array('attribute_option' => $option);
 }
Esempio n. 2
0
 /**
  * Create attribute option
  *
  * @param string $value Option name
  *
  * @return \XLite\Model\AttributeOption
  */
 protected function createAttributeOption($value)
 {
     $attributeOption = new \XLite\Model\AttributeOption();
     $attributeOption->setAttribute($this);
     $attributeOption->setName($value);
     \XLite\Core\Database::getEM()->persist($attributeOption);
     return $attributeOption;
 }
Esempio n. 3
0
 /**
  * Import 'options' value
  *
  * @param \XLite\Model\Attribute $model  Attribute
  * @param array                  $value  Value
  * @param array                  $column Column info
  *
  * @return void
  */
 protected function importOptionsColumn(\XLite\Model\Attribute $model, array $value, array $column)
 {
     if ($value) {
         foreach ($value as $index => $val) {
             $option = $model->getAttributeOptions()->get($index);
             if (!$option) {
                 $option = new \XLite\Model\AttributeOption();
                 $option->setAttribute($model);
                 $model->getAttributeOptions()->add($option);
                 \XLite\Core\Database::getEM()->persist($option);
             }
             $this->updateModelTranslations($option, $val);
         }
         while (count($model->getAttributeOptions()) > count($value)) {
             $option = $model->getAttributeOptions()->last();
             \XLite\Core\Database::getRepo('\\XLite\\Model\\AttributeOption')->delete($option, false);
             $model->getAttributeOptions()->removeElement($option);
         }
     }
 }