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(); }
/** * Запустить действие */ public function run() { if (isset($_REQUEST)) { if (Yii::app()->request->isPostRequest) { $model = call_user_func(array($_REQUEST['model'], 'model')); $entry = $model->findAllByPk($_REQUEST['id']); if (!empty($entry)) { foreach ($entry as $page) { $page->updateByPk($_REQUEST['id'], array('switch' => $_REQUEST['switch'])); } Yii::app()->timeline->set('SWITCH_RECORD', array('{model}' => $_REQUEST['model'], '{pk}' => $_REQUEST['id'], '{switch}' => $_REQUEST['switch'] ? Yii::t('app', 'ON', 0) : Yii::t('app', 'OFF', 0), '{htmlClass}' => $_REQUEST['switch'] ? 'success' : 'danger')); } if ($model instanceof ShopProduct) { ShopProductCategoryRef::model()->updateAll(array('switch' => $_REQUEST['switch']), 'product=:p', array(':p' => $_REQUEST['id'])); } } } }
/** * Set product categories and main category * @param array $categories ids. * @param integer $main_category Main category id. */ public function setCategories(array $categories, $main_category) { $dontDelete = array(); if (!ShopCategory::model()->countByAttributes(array('id' => $main_category))) { $main_category = 1; } if (!in_array($main_category, $categories)) { array_push($categories, $main_category); } foreach ($categories as $c) { $count = ShopProductCategoryRef::model()->countByAttributes(array('category' => $c, 'product' => $this->id)); if ($count == 0) { $record = new ShopProductCategoryRef(); $record->category = (int) $c; $record->product = $this->id; $record->switch = $this->switch; // new param $record->save(false, false, false); } $dontDelete[] = $c; } // Clear main category ShopProductCategoryRef::model()->updateAll(array('is_main' => 0, 'switch' => $this->switch), 'product=:p', array(':p' => $this->id)); // Set main category ShopProductCategoryRef::model()->updateAll(array('is_main' => 1, 'switch' => $this->switch), 'product=:p AND category=:c', array(':p' => $this->id, ':c' => $main_category)); // Delete not used relations if (sizeof($dontDelete) > 0) { $cr = new CDbCriteria(); $cr->addNotInCondition('category', $dontDelete); ShopProductCategoryRef::model()->deleteAllByAttributes(array('product' => $this->id), $cr); } else { // Delete all relations ShopProductCategoryRef::model()->deleteAllByAttributes(array('product' => $this->id)); } }
public function afterDelete() { //Remove all products with this category set as main. $products = ShopProductCategoryRef::model()->findAllByAttributes(array('category' => $this->id, 'is_main' => '1')); foreach ($products as $p) { $productModel = ShopProduct::model()->findByPk($p->product); if ($productModel) { $productModel->delete(); } } // Remove all category-product relations ShopProductCategoryRef::model()->deleteAllByAttributes(array('category' => $this->id, 'is_main' => '0')); $this->clearRouteCache(); return parent::afterDelete(); }