Ejemplo n.º 1
0
 public function afterUninstall()
 {
     $db = Yii::app()->db;
     $tablesArray = array(Wishlist::model()->tableName(), WishlistProducts::model()->tableName());
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     return parent::afterUninstall();
 }
Ejemplo n.º 2
0
 /**
  * Delete related data.
  */
 public function afterDelete()
 {
     // Delete related products
     $this->clearRelatedProducts();
     ShopRelatedProduct::model()->deleteAll('related_id=:id', array('id' => $this->id));
     // Delete categorization
     ShopProductCategoryRef::model()->deleteAllByAttributes(array('product' => $this->id));
     // Delete images
     $images = $this->images;
     if (!empty($images)) {
         foreach ($images as $image) {
             $image->delete();
         }
     }
     // Delete variants
     $variants = ShopProductVariant::model()->findAllByAttributes(array('product_id' => $this->id));
     foreach ($variants as $v) {
         $v->delete();
     }
     // Clear configurable attributes
     Yii::app()->db->createCommand()->delete('{{shop_product_configurable_attributes}}', 'product_id=:id', array(':id' => $this->id));
     // Delete configurations
     Yii::app()->db->createCommand()->delete('{{shop_product_configurations}}', 'product_id=:id', array(':id' => $this->id));
     Yii::app()->db->createCommand()->delete('{{shop_product_configurations}}', 'configurable_id=:id', array(':id' => $this->id));
     // Delete from wish lists if install module "wishlist"
     if (Yii::app()->hasModule('wishlist')) {
         Yii::import('mod.wishlist.models.*');
         $wishlistProduct = WishlistProducts::model()->findByAttributes(array('product_id' => $this->id));
         if ($wishlistProduct) {
             $wishlistProduct->delete();
         }
     }
     return parent::afterDelete();
 }
Ejemplo n.º 3
0
 /**
  * @param null $user_id if null will count for current user
  * @return mixed
  */
 public static function countByUser($user_id = null)
 {
     if ($user_id === null) {
         $user_id = Yii::app()->user->id;
     }
     $table = WishlistProducts::model()->tableName();
     return Yii::app()->db->createCommand("SELECT COUNT(id) FROM {$table} WHERE user_id=:user_id")->bindValue(':user_id', $user_id)->queryScalar();
 }