validateRequest($req, [ 'priv_third_party', // 'priv_promo', ]); if (!$validity['is_valid']) { return new ApiResponse(false, $validity['error']); } // get customer $cust = $this->session->getCustomer(); if ($cust == null) { return new ApiResponse(false, 'No customer information found.'); } // set privacy settings $priv_promo = $req->request->get('priv_promo', false); $priv_third_party = $req->request->get('priv_third_party'); $cust->setPrivacyThirdParty($priv_third_party) ->setPrivacyPromo($priv_promo); // get the policy ids from .env $policy_promo_id = $_ENV['POLICY_PROMO']; $policy_third_party_id = $_ENV['POLICY_THIRD_PARTY']; // check if privacy settings are true // if true, set the private policy for the customer if ($priv_promo) { // find the promo policy $policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_promo_id); // set policy id if ($policy != null) { $cust->setPrivacyPolicyPromo($policy); } } if ($priv_third_party) { // find the third party policy $policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id); // set policy id if ($policy != null) { $cust->setPrivacyPolicyThirdParty($policy); } } $this->em->flush(); // response return new ApiResponse(); } }