common/components/CartFunctionality.php
/*
     * This function add product to wishlist
     * parameeter @product_id
     * Only add to tha wishlist when the user loged in
     */
This function add product to wishlist
parameeter @product_id
Only add to tha wishlist when the user loged in
This function add product to wishlist parameeter @product_id Only add to tha wishlist when the user loged in
public function AddToWishlist($product_id) {
        $flag = 0;
        if (isset(Yii::$app->user->identity->id)) {
            $model = WishList::find()->where(['product' => $product_id, 'user_id' => Yii::$app->user->identity->id])->one();
            if (empty($model)) {
                $model = new WishList();
                $model->user_id = Yii::$app->user->identity->id;
                $model->product = $product_id;
                $model->date = date('Y-m-d');
            } else {
                $model->date = date('Y-m-d');
            }
            if ($model->save()) {
                $flag = 1;
            } else {
                $flag = 3;
            }
        } else {
            $flag = 2;
        }
        return $flag;
    }
public function AddToWishlist ( $ product_id ) { $ flag = 0 ; if ( isset ( Yii :: $ app -> user -> identity -> id ) ) { $ model = WishList :: find ( ) -> where ( [ 'product' => $ product_id , 'user_id' => Yii :: $ app -> user -> identity -> id ] ) -> one ( ) ; if ( empty ( $ model ) ) { $ model = new WishList ( ) ; $ model -> user_id = Yii :: $ app -> user -> identity -> id ; $ model -> product = $ product_id ; $ model -> date = date ( 'Y-m-d' ) ; } else { $ model -> date = date ( 'Y-m-d' ) ; } if ( $ model -> save ( ) ) { $ flag = 1 ; } else { $ flag = 3 ; } } else { $ flag = 2 ; } return $ flag ; }
This function add product to wishlist
 parameeter @product_id
 Only add to tha wishlist when the user loged in
This function add product to wishlist parameeter @product_id Only add to tha wishlist when the user loged in