コード例 #1
0
ファイル: ShopModule.php プロジェクト: buildshop/bs-common
 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();
 }
コード例 #2
0
 /**
  * @param ShopProduct $product
  * @param CUploadedFile $image
  */
 public function __construct(ShopProduct $product, CUploadedFile $image)
 {
     $name = ShopUploadedImage::createName($product, $image);
     $fullPath = ShopUploadedImage::getSavePath() . '/' . $name;
     $image->saveAs($fullPath);
     @chmod($fullPath, 0666);
     // Check if product has main image
     $is_main = (int) ShopProductImage::model()->countByAttributes(array('product_id' => $product->id, 'is_main' => 1));
     $imageModel = new ShopProductImage();
     $imageModel->product_id = $product->id;
     $imageModel->name = $name;
     $imageModel->is_main = $is_main == 0 ? true : false;
     $imageModel->uploaded_by = Yii::app()->user->id;
     //$imageModel->date_uploaded = date('Y-m-d H:i:s');
     $imageModel->save(false, false);
     $this->resize($fullPath);
     $this->watermark($fullPath);
 }
コード例 #3
0
 /**
  * @param ShopProduct $model
  */
 public function updateMainImage(ShopProduct $model)
 {
     if (Yii::app()->request->getPost('mainImageId')) {
         // Clear current main image
         ShopProductImage::model()->updateAll(array('is_main' => 0), 'product_id=:pid', array(':pid' => $model->id));
         // Set new main image
         ShopProductImage::model()->updateByPk(Yii::app()->request->getPost('mainImageId'), array('is_main' => 1));
     }
 }
コード例 #4
0
 /**
  * Delete file, etc...
  */
 public function afterDelete()
 {
     // Delete file
     if (file_exists($this->filePath)) {
         unlink($this->filePath);
     }
     // If main image was deleted
     if ($this->is_main) {
         // Get first image and set it as main
         $model = ShopProductImage::model()->find();
         if ($model) {
             $model->is_main = 1;
             $model->save(false, false, false);
         }
     }
     return parent::afterDelete();
 }