/**
  * 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();
     }
 }
 public function afterDelete()
 {
     // Clear type attribute relations
     StoreTypeAttribute::model()->deleteAllByAttributes(array('type_id' => $this->id));
     return parent::afterDelete();
 }
 /**
  * @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;
 }
Beispiel #4
0
 public function afterDelete()
 {
     // Delete options
     foreach ($this->options as $o) {
         $o->delete();
     }
     // Delete relations used in product type.
     StoreTypeAttribute::model()->deleteAllByAttributes(array('attribute_id' => $this->id));
     // Delete attributes assigned to products
     $conn = $this->getDbConnection();
     $command = $conn->createCommand("DELETE FROM `StoreProductAttributeEAV` WHERE `attribute`='{$this->name}'");
     $command->execute();
     return parent::afterDelete();
 }