MinerPL Posted June 30, 2021 Share Posted June 30, 2021 Hello I am writing with a problem related to creating a custom hook. I have already written all the ready code but unfortunately not everything works in it as it should. Below I send the code and the error. In the screenshot I send what logModuleCall returns.Code: <?php use WHMCS\Database\Capsule; add_hook('AfterShoppingCartCheckout', 1, function($vars) { $orders = Capsule::table('tblorders') ->where('id', $vars['OrderID']) ->get() ->first(); logModuleCall('BetterAffilance', 'Sended data', json_encode($orders), json_encode($vars)); $partners = [ 'minerpl' => 2, ]; if($partners[$orders->promocode]) { logModuleCall('BetterAffilance', 'User use partner code!', $partners[$orders->promocode], $vars['ServiceIDs'][0]); try { Capsule::connection()->transaction( function ($connectionManager) { /** @var \Illuminate\Database\Connection $connectionManager */ $connectionManager->table('tblaffiliatesaccounts')->insert( [ 'affiliateid' => $partners[$orders->promocode], 'relid' => $vars['ServiceIDs'][0], ] ); } ); } catch (\Exception $e) { logModuleCall('BetterAffilance', 'Error when inserting data to database', $e->getMessage(), $e->getMessage()); } } }); Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'affiliateid' cannot be null (SQL: insert into `tblaffiliatesaccounts` (`affiliateid`, `relid`) values (?, ?)) 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.