public function afterUninstall() { Yii::app()->settings->clear('shop'); Yii::app()->unintallComponent('currency'); $db = Yii::app()->db; $tablesArray = array(ShopTypeAttribute::model()->tableName(), ShopAttribute::model()->tableName(), ShopAttributeOption::model()->tableName(), ShopAttributeOptionTranslate::model()->tableName(), ShopAttributeTranslate::model()->tableName(), ShopCategory::model()->tableName(), ShopCategoryTranslate::model()->tableName(), ShopCurrency::model()->tableName(), ShopManufacturer::model()->tableName(), ShopManufacturerTranslate::model()->tableName(), ShopProduct::model()->tableName(), ShopProductCategoryRef::model()->tableName(), ShopProductImage::model()->tableName(), ShopProductTranslate::model()->tableName(), ShopProductType::model()->tableName(), ShopProductVariant::model()->tableName(), ShopRelatedProduct::model()->tableName(), ShopSuppliers::model()->tableName(), $db->tablePrefix . 'shop_product_attribute_eav', $db->tablePrefix . 'shop_product_configurable_attributes', $db->tablePrefix . 'shop_product_configurations'); foreach ($tablesArray as $table) { $db->createCommand()->dropTable($table); } CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.product'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.categories'), array('traverseSymlinks' => true)); CFileHelper::removeDirectory(Yii::getPathOfAlias('webroot.uploads.manufacturer'), array('traverseSymlinks' => true)); return parent::afterUninstall(); }
/** * 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 ShopAttribute(); $model->name = CMS::translit($attribute->{"Наименование"}); $model->name = str_replace('-', '_', $model->name); $model->title = $attribute->{"Наименование"}; $model->type = ShopAttribute::TYPE_DROPDOWN; $model->use_in_filter = $useInFilter; $model->display_on_front = true; if ($model->save(false, false)) { // Add to type $typeAttribute = new ShopTypeAttribute(); $typeAttribute->type_id = self::DEFAULT_TYPE; $typeAttribute->attribute_id = $model->id; $typeAttribute->save(false, false); $this->createExternalId(C1ExternalFinder::OBJECT_TYPE_ATTRIBUTE, $model->id, $attribute->{"Ид"}); } } // Update attributes $model->name = CMS::translit($attribute->{"Наименование"}); $model->use_in_filter = $useInFilter; $model->save(); } }
public function afterDelete() { // Clear type attribute relations ShopTypeAttribute::model()->deleteAllByAttributes(array('type_id' => $this->id)); return parent::afterDelete(); }
/** * @param $name * @return ShopAttribute */ public function getAttributeByName($name) { if (isset($this->attributesCache[$name])) { return $this->attributesCache[$name]; } $attribute = ShopAttribute::model()->findByAttributes(array('name' => $name)); if (!$attribute) { // Create new attribute $attribute = new ShopAttribute(); $attribute->name = $name; $attribute->title = ucfirst(str_replace('_', ' ', $name)); $attribute->type = ShopAttribute::TYPE_DROPDOWN; $attribute->display_on_front = true; $attribute->save(false, false, false); // Add to type $typeAttribute = new ShopTypeAttribute(); $typeAttribute->type_id = $this->model->type_id; $typeAttribute->attribute_id = $attribute->id; $typeAttribute->save(false, false, false); } $this->attributesCache[$name] = $attribute; return $attribute; }
public function afterDelete() { // Delete options foreach ($this->options as $o) { $o->delete(); } // Delete relations used in product type. ShopTypeAttribute::model()->deleteAllByAttributes(array('attribute_id' => $this->id)); // Delete attributes assigned to products $conn = $this->getDbConnection(); $command = $conn->createCommand("DELETE FROM `{{shop_product_attribute_eav}}` WHERE `attribute`='{$this->name}'"); $command->execute(); return parent::afterDelete(); }