예제 #1
0
 /**
  * Signs user up.
  *
  * @return Member|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $connection = yii::$app->db;
         $transaction = $connection->beginTransaction();
         $pw = $this->password;
         try {
             $member = new Member();
             $member->email = $this->email;
             $member->setPassword($pw);
             $member->generateAuthKey();
             $member->beforeSave(TRUE);
             $member->save();
             $member_profile = new MemberProfile();
             $member_profile->name = $this->name;
             $member_profile->address = $this->address;
             $member_profile->contact_number = $this->contact_number;
             $member_profile->member_id = $member->id;
             $member_profile->beforeSave(TRUE);
             $member_profile->save();
             if (1 == $this->is_affiliate) {
                 $affiliate = new ApMembers();
                 $affiliate->email = $member->email;
                 $affiliate->fullname = $this->name;
                 $affiliate->balance = '0.00';
                 $affiliate->terms = '1';
                 $affiliate->password = password_hash($pw, PASSWORD_DEFAULT, ["cost" => 10]);
                 $affiliate->admin_user = '******';
                 $affiliate->browser = $_SERVER['HTTP_USER_AGENT'];
                 $affiliate->referrar_id = $this->referrar_id;
                 $affiliate->save();
             }
             $transaction->commit();
             return $member;
         } catch (Exception $exc) {
             $transaction->rollBack();
             throw $e;
         }
     }
     return null;
 }
예제 #2
0
 public function actionCart()
 {
     $user_id = 0;
     if (!Yii::$app->user->isGuest) {
         $user_id = Yii::$app->user->identity->id;
         $email = Yii::$app->user->identity->email;
     }
     $cart_json = [];
     if (isset($_COOKIE['cart_' . $user_id])) {
         $cart_json = Json::decode($_COOKIE['cart_' . $user_id]);
     }
     if (isset($_COOKIE['cart_0'])) {
         $cart_json = Json::decode($_COOKIE['cart_0']);
     }
     $ar_product_id = array_keys($cart_json);
     $cart_items = Product::find()->where(['in', 'id', $cart_json])->all();
     $affiliate = \frontend\models\ApMembers::find()->getAffiliateByEmail(Yii::$app->user->identity->email)->one();
     // add a new cookie to track affiliate sale
     $cookies = Yii::$app->response->cookies;
     $cookies->add(new \yii\web\Cookie(['name' => 'ap_ref_tracking', 'value' => $affiliate->id]));
     return $this->render('cart', ['cart_items' => $cart_items, 'cart_json' => $cart_json]);
 }