Example #1
0
 public function addWishList($post_id, $user_id, $album_id)
 {
     //        $check = Wishlist::model()->findByAttributes(array('post_id' => $post_id, 'user_id' => $user_id));
     //        if ($check) {
     //            return FALSE;
     //        } else {
     $check_album = PostAlbum::model()->findByAttributes(array('post_id' => $post_id, 'album_id' => $album_id));
     $check = Wishlist::model()->findByAttributes(array('post_id' => $post_id, 'user_id' => $user_id));
     if (!$check_album && !$check) {
         $alb_post = new PostAlbum();
         $alb_post->post_id = $post_id;
         $alb_post->album_id = $album_id;
         $alb_post->created_at = time();
         $alb_post->updated_at = time();
         $model = new Wishlist();
         $model->post_id = $post_id;
         $model->user_id = $user_id;
         $model->album_id = $album_id;
         $model->status = 1;
         $model->created_at = time();
         $model->updated_at = time();
         if ($model->save(FALSE) && $alb_post->save(FALSE)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * @param $user_id
  */
 public function create($user_id)
 {
     $model = new Wishlist();
     $model->user_id = $user_id;
     $model->key = $this->createSecretKey();
     $model->save(false);
     return;
 }
Example #3
0
 public function setUp()
 {
     parent::setUp();
     $this->setUpData();
     $this->setUpRating();
     $wishlist = new Wishlist();
     $wishlist->id = 1;
     $wishlist->user_id = $this->_user_id;
     $wishlist->wine_unique_id = "1_2009";
     $wishlist->save();
 }
Example #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Wishlist();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Wishlist'])) {
         $model->attributes = $_POST['Wishlist'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->wishlist_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #5
0
 public function addWishList($post_id, $user_id)
 {
     $check = Wishlist::model()->findByAttributes(array('post_id' => $post_id, 'user_id' => $user_id));
     if ($check) {
         return FALSE;
     } else {
         $model = new Wishlist();
         $model->post_id = $post_id;
         $model->user_id = $user_id;
         $model->status = 1;
         $model->created_at = time();
         $model->updated_at = time();
         if ($model->save(FALSE)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Example #6
0
 public static function createNewWishlist($input)
 {
     $user_id = Session::get('user_id');
     $error_code = ApiResponse::OK;
     $wishlist = new Wishlist();
     $wishlist->user_id = $user_id;
     if (!empty($input['wine_unique_id'])) {
         $wishlist->wine_unique_id = $input['wine_unique_id'];
         $wine_wishlist = Wishlist::where('wine_unique_id', $wishlist->wine_unique_id)->where('user_id', $user_id)->first();
         if ($wine_wishlist) {
             $error_code = ApiResponse::DUPLICATED_WISHLIST_ADD;
             $data = ApiResponse::getErrorContent(ApiResponse::DUPLICATED_WISHLIST_ADD);
         } else {
             $wishlist->save();
             $data = $wishlist->toArray();
         }
     } else {
         $error_code = ApiResponse::MISSING_PARAMS;
         $data = $input;
     }
     return array("code" => $error_code, "data" => $data);
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate()
 {
     $model = new Wishlist();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     //echo "<pre>";var_dump($_POST[Wishlist]); echo "</pre>"; die();
     $flag = 0;
     if (isset($_POST['product_id'], $_POST['wishlist_flag'])) {
         $model = $model->loadWishlistModel($_POST['product_id']);
         //$model->attributes=$_POST['Wishlist'];
         if ($model == null) {
             $model = new Wishlist();
             $model->setIsNewRecord(TRUE);
         }
         $model->wishlist_flag = $_POST['wishlist_flag'] ? 0 : 1;
         $model->product_id = $_POST['product_id'];
         if ($model->save()) {
             // echo "</pre>";                            echo "post"; var_dump($model); die();
             //echo "saved";
             //$this->redirect(array('view','id'=>$model->wishlist_id));
         }
     }
     $this->render('update', array('model' => $model, 'productId' => $model->product_id, 'wishlist_flag' => $flag));
 }
 public function actionAdd()
 {
     if (Yii::app()->user->isGuest) {
         echo Yii::t('wishlist', "You must be logged in to add to a wish list. Please sign in and try again.");
         return;
     }
     if (Yii::app()->request->isAjaxRequest) {
         $model = new WishlistAddForm();
         // collect user input data
         if (isset($_POST)) {
             if (isset($_POST['WishlistAddForm'])) {
                 $model->attributes = $_POST['WishlistAddForm'];
             } else {
                 $model->attributes = $_POST;
             }
             if ($model->validate()) {
                 $intProductId = $model->id;
                 $intQty = $model->qty;
                 $strSize = $model->size;
                 $strColor = $model->color;
                 $objProduct = Product::model()->findByPk($intProductId);
                 if (!$objProduct instanceof Product) {
                     return;
                 }
                 if ($objProduct->IsMaster) {
                     if (isset($strSize) || isset($strColor)) {
                         $objProduct = Product::LoadChildProduct($intProductId, $strSize, $strColor);
                         if (!$objProduct instanceof Product) {
                             echo Yii::t('wishlist', "Please choose options before selecting {button}", array('{button}' => Yii::t('product', 'Add to Wish List')));
                             return;
                         }
                         $model->id = $intProductId = $objProduct->id;
                     } else {
                         echo Yii::t('wishlist', "Please choose options before selecting {button}", array('{button}' => Yii::t('product', 'Add to Wish List')));
                         return;
                     }
                 }
                 //If we don't have a wish list, create one and add. If we only have one wish list, add it. If we have more than
                 //one, we need to prompt for which one to add
                 $objWishLists = Wishlist::LoadUserLists();
                 switch (count($objWishLists)) {
                     case 0:
                         //We don't have a wish list, so let's create one
                         $objWishList = new Wishlist();
                         $objWishList->registry_name = Yii::t('wishlist', 'My Wish List');
                         $objWishList->visibility = Wishlist::PERSONALLIST;
                         $objWishList->after_purchase = Wishlist::LEAVEINLIST;
                         $objWishList->customer_id = Yii::app()->user->id;
                         $objWishList->gift_code = md5(uniqid());
                         $objWishList->ship_option = 0;
                         if (!$objWishList->save()) {
                             Yii::log("Error creating Wish List " . print_r($objWishList->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                         }
                         $objWishLists = array();
                         $objWishLists[0] = $objWishList;
                         // No break so we drop to the next set of instructions
                     // No break so we drop to the next set of instructions
                     case 1:
                         $objWishList = $objWishLists[0];
                         $objWishItem = new WishlistItem();
                         $objWishItem->registry_id = $objWishList->id;
                         $objWishItem->product_id = $intProductId;
                         $objWishItem->qty = $intQty;
                         if ($objWishItem->save()) {
                             echo Yii::t('wishlist', 'Item has been added to your Wish List.');
                         } else {
                             Yii::log("error saving wishlist item " . print_r($objWishItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                             echo Yii::t('wishlist', 'An error occurred adding this item to your Wish List.');
                         }
                         break;
                     default:
                         $Wishlistadd = new WishlistAddForm();
                         if (isset($_POST['WishlistAddForm'])) {
                             $Wishlistadd->attributes = $_POST['WishlistAddForm'];
                         }
                         if ($Wishlistadd->validate()) {
                             $objWishList = Wishlist::model()->findByAttributes(array('gift_code' => $Wishlistadd->gift_code));
                             $objWishItem = new WishlistItem();
                             $objWishItem->registry_id = $objWishList->id;
                             $objWishItem->product_id = $intProductId;
                             $objWishItem->qty = $Wishlistadd->qty;
                             if ($objWishItem->save()) {
                                 echo Yii::t('global', 'Item has been added to your Wish List.');
                             } else {
                                 Yii::log("error saving wishlist item " . print_r($objWishItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                                 echo Yii::t('global', 'An error occurred adding this item to your Wish List.');
                             }
                         } else {
                             echo "multiple";
                         }
                         break;
                 }
             } else {
                 echo print_r($model->getErrors(), true);
             }
         } else {
             echo "Error missing POST";
         }
     } else {
         echo "Error not AJAX";
     }
 }
Example #9
0
 public function setUpWishlist()
 {
     $wishlist = new Wishlist();
     $wishlist->wine_unique_id = '1_2009';
     $wishlist->user_id = $this->_user_id;
     $wishlist->save();
 }