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.