0

I'm working on membership module. And, found that data saving twice for membership_record table.

What I'm doing is: After calculating total amount, tax etc. I'm saving it and redirecting it to payment gateway URL. From there, response coming to my controller function checkout(), where data is entering twice.

public function actionSubscription(){
  ..
  ..
  if($modelMemberships->load(Yii::$app->request->post())){
    /*
     * Ajax Validation Code
     */


    $validMembership = $modelMemberships->validate(['addTeamMember','is_free_trial']);
    if($validMembership){
      $postMemberships = Yii::$app->request->post('Membership');
      .
      .
      if($modelMemberships->save()){
        $redirectURL = Yii::$app->params['_URL'].'memberships/checkout?id='.$modelMemberships->getId();
        return $this->redirect($redirectURL); //This is redirecting to checkout function.
      }
    }

  }
}


public function actionCheckout($id){
  $payment_status = "Y";
  if($payment_status == "Y"){
    foreach($modelUsers as $modelUser){
      $modelMembershipUsers = new MembershipUsers();
      $modelMembershipUsers->membership_id = $modelMemberships->getId();
      $modelMembershipUsers->save();
    }

    //Update UC Settings
    if($modelUCSettings = UCSettings::findOne($UCSettingsId)){
      $modelUCSettings->updated_at = date("Y-m-d h:i:s");
      $modelUCSettings->save(false);
    }

    return $this->redirect(['@web/memberships/receipt?id='.$id]);
  }
}

And, there is no code duplication. So, from no where this code will get executed until it is redirected from subscription() function.

I don't know why data is saving twice only in membership_records table.

I Checked data is saved twice to the database. But, the answer provided doesn't resolved my problem.

Adding to it: In google chrome, there is no duplicate records. But, by using mozilla firefox, data is saving twice.

Any help/suggestions is appreciated.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
  • Hard to say if there's `. .` - missing code in `actionSubsciption()`. – Yupik Aug 11 '17 at 09:38
  • @Yupik: Relevant codes are entered only. Believe in me, there is no such lines of code written which will cause harm. – Nana Partykar Aug 11 '17 at 10:17
  • One thing i learned here: dont trust in 'believe me'. If this action is responsible for duplicate records, we need all code inside, otherwise we can just guessing. – Yupik Aug 11 '17 at 10:19
  • 1
    Using Ajax Validation? – Insane Skull Aug 11 '17 at 11:17
  • Hi @InsaneSkull, I think No.Because, If it happens also, then membership record will also get duplicated. But, only membership_records table having multiple record. It is happening only in mozilla not in chrome. Brother, you can help me. You helped me so many times. This time too, please. – Nana Partykar Aug 11 '17 at 11:30
  • Have you enabled Ajax Validation in form? Add full controller code. Probably your form submitted twice. – Insane Skull Aug 11 '17 at 12:42

0 Answers0