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(); }
/** * Save attribute options * @param ShopAttribute $model */ protected function saveOptions($model) { $dontDelete = array(); if (!empty($_POST['options'])) { foreach ($_POST['options'] as $key => $val) { if (isset($val[0]) && $val[0] != '') { $index = 0; $attributeOption = ShopAttributeOption::model()->findByAttributes(array('id' => $key, 'attribute_id' => $model->id)); if (!$attributeOption) { $attributeOption = new ShopAttributeOption(); $attributeOption->attribute_id = $model->id; } $attributeOption->save(false, false, false); foreach (Yii::app()->languageManager->languages as $lang) { $attributeLangOption = ShopAttributeOption::model()->language($lang->id)->findByAttributes(array('id' => $attributeOption->id)); $attributeLangOption->value = $val[$index]; $attributeLangOption->save(false, false, false); ++$index; } array_push($dontDelete, $attributeOption->id); } } } if (sizeof($dontDelete)) { $cr = new CDbCriteria(); $cr->addNotInCondition('t.id', $dontDelete); $optionsToDelete = ShopAttributeOption::model()->findAllByAttributes(array('attribute_id' => $model->id), $cr); } else { // Clear all attribute options $optionsToDelete = ShopAttributeOption::model()->findAllByAttributes(array('attribute_id' => $model->id)); } if (!empty($optionsToDelete)) { foreach ($optionsToDelete as $o) { $o->delete(); } } }
/** * @param $attribute_id * @param $value * @return ShopAttributeOption */ public function addOptionToAttribute($attribute_id, $value) { // Add option $option = new ShopAttributeOption(); $option->attribute_id = $attribute_id; $option->value = $value; $option->save(false, false); return $option; }
/** * Add option to shop attribute * * @throws CHttpException */ public function actionAddOptionToAttribute() { $attribute = ShopAttribute::model()->findByPk($_GET['attr_id']); if (!$attribute) { throw new CHttpException(404, Yii::t('ShopModule.admin', 'ERR_LOAD_ATTR')); } $attributeOption = new ShopAttributeOption(); $attributeOption->attribute_id = $attribute->id; $attributeOption->value = $_GET['value']; $attributeOption->save(false, false, false); echo $attributeOption->id; }