示例#1
0
 /**
  * Import product properties
  */
 public function importProperties()
 {
     foreach ($this->xml->{"Классификатор"}->{"Свойства"}->{"Свойство"} as $attribute) {
         $model = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $attribute->{"Ид"});
         if ($attribute->{"ЭтоФильтр"} == 'false') {
             $useInFilter = false;
         } else {
             $useInFilter = true;
         }
         if (!$model) {
             // Create new attribute
             $model = new StoreAttribute();
             $model->name = SlugHelper::run($attribute->{"Наименование"});
             $model->name = str_replace('-', '_', $model->name);
             $model->title = $attribute->{"Наименование"};
             $model->type = StoreAttribute::TYPE_DROPDOWN;
             $model->use_in_filter = $useInFilter;
             $model->display_on_front = true;
             if ($model->save()) {
                 // Add to type
                 $typeAttribute = new StoreTypeAttribute();
                 $typeAttribute->type_id = self::DEFAULT_TYPE;
                 $typeAttribute->attribute_id = $model->id;
                 $typeAttribute->save();
                 $this->createExternalId(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $model->id, $attribute->{"Ид"});
             }
         }
         // Update attributes
         $model->name = SlugHelper::run($attribute->{"Наименование"});
         $model->use_in_filter = $useInFilter;
         $model->save();
     }
 }
 /**
  * @param $name
  * @return StoreAttribute
  */
 public function getAttributeByName($name)
 {
     if (isset($this->attributesCache[$name])) {
         return $this->attributesCache[$name];
     }
     $attribute = StoreAttribute::model()->findByAttributes(array('name' => $name));
     if (!$attribute) {
         // Create new attribute
         $attribute = new StoreAttribute();
         $attribute->name = $name;
         $attribute->title = ucfirst(str_replace('_', ' ', $name));
         $attribute->type = StoreAttribute::TYPE_DROPDOWN;
         $attribute->display_on_front = true;
         $attribute->save(false);
         // Add to type
         $typeAttribute = new StoreTypeAttribute();
         $typeAttribute->type_id = $this->model->type_id;
         $typeAttribute->attribute_id = $attribute->id;
         $typeAttribute->save(false);
     }
     $this->attributesCache[$name] = $attribute;
     return $attribute;
 }