Linuc82 Posted January 27, 2020 Share Posted January 27, 2020 Hi Guys, I am writing a hook that uses "AfterModuleCreate" point. This point will only return the actual domain name parameter "domain" as per https://developers.whmcs.com/provisioning-modules/module-parameters/ I actually need the domainid parameter. Any ideas? I cannot find a function for the local API to get the domainid from a domain parameter. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 27, 2020 Share Posted January 27, 2020 (edited) SELECT t1.id FROM tbldomains AS t1 LEFT JOIN tblhosting AS t2 ON t1.domain = t2.domain AND t1.userid = t2.userid WHERE t2.domain = '{DOMAIN_NAME}' LIMIT 1 Replace {DOMAIN_NAME} with domain name. The reason why I'm joining by userid is to avoid situations where two customers have the same domain name (one Active and the other Pending). This way you don't risk to get the ID of the "Pending" domain that is owned by a different customer. I think that you should consider also the status of the domain in question. In fact a customer can have following configuration: Pending example.com (abandoned cart) Transfered Away example.com (he registered the domain with you but he switched to another provider 3 years ago) Active example.com (he's now back with you) Here we have the same domain name with 3 different IDs and the one that you want to get is the Active one. That's why you should probably filter by tbldomains.status. Edited January 27, 2020 by Kian 0 Quote Link to comment Share on other sites More sharing options...
Linuc82 Posted January 27, 2020 Author Share Posted January 27, 2020 Thanks, this is the way I was doing it. I was looking for a way using the local API. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted January 27, 2020 Share Posted January 27, 2020 You could use GetClientsDomains filtering by "domain" but you'll need iterate over the array (results) to get the right ID. IMO this approach is less efficient. With raw SQL you can get what you need in a single query meanwhile via API you get N number of records that need to be checked in a foreach statement. 0 Quote Link to comment Share on other sites More sharing options...
Linuc82 Posted January 28, 2020 Author Share Posted January 28, 2020 Perhaps I should give you some more information here. See, our company situation is a bit unique. All new domains registered on our system has "Auto Renew" Disabled by default. BUT when a hosting service is ordered, we want the associated domain to have Auto Renew Enabled. To accomplish this, I have created the following hook: <?php #WHMCS DB Connection Manager use Illuminate\Database\Capsule\Manager as Capsule; add_hook('AfterModuleCreate', 1, function ($vars) { $domain = $vars['params']['domain']; try { $updateAutorenew = Capsule::table('tbldomains') ->where('domain', $domain) ->update( [ 'donotrenew' => 0, ] ); echo "Updated {updateAutorenew} domain renewal status"; } catch (\Exception $e) { echo "I was unable to update the domain renewal status. {$e->getMessage()}"; } }); This issue we have is that when a manual payment is added to an order, the page hangs on "Unpaid" and does not forward to "Paid". I've narrowed the issue down to this hook, but cannot determine why it is doing that. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 28, 2020 Share Posted January 28, 2020 9 hours ago, Linuc82 said: All new domains registered on our system has "Auto Renew" Disabled by default. BUT when a hosting service is ordered, we want the associated domain to have Auto Renew Enabled. "auto renew" in this sense (with WHMCS) is really a do not generate a renewal invoice and not auto renew in the sense of automatically renewing it with the registrar - so for domains, are you not wanting to generate renewal invoices, but when purchased with a product, you want them to generate an invoice.... or are you assuming that the auto renew option is about renewing with the registrar ?? 0 Quote Link to comment Share on other sites More sharing options...
Linuc82 Posted January 29, 2020 Author Share Posted January 29, 2020 13 hours ago, brian! said: Since we have Domain Resellers on our system with credit on their accounts, who do not want to renew domains unless their clients pay them, we cannot have the system generate invoices for them automatically, then subsequently renew at the registrar. As mentioned, our situation is unique and requires that Auto Renewal (Invoice Generation) be disabled by default for all domains registered on the system, except if someone orders a Hosting Plan, then the domain linked to that Hosting Plan must have Auto Renewal (Invoice Generation) Enabled. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 29, 2020 Share Posted January 29, 2020 fair enough - I mentioned it only as "auto renew" has two different meanings within WHMCS which does cause confusion. 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.