Jump to content

OrderDomainPricingOverride hook error


So, who am I ?

Recommended Posts

Hello ^_^

 

I use OrderDomainPricingOverride hook to change some domain price manually, I need two registrars to use this hook, but when I add hook file to the second registrar's folder I get blank page and the whole site shuts down.

 

I don't use any registrar function in the file, I just check domain's sld and tld and generate price, how can I manage to use the hook for both registrars ?

this is my whole hook file:

<?php
/**
 * WHMCS SDK Sample Registrar Module Hooks File
 *
 * Hooks allow you to tie into events that occur within the WHMCS application.
 *
 * This allows you to execute your own code in addition to, or sometimes even
 * instead of that which WHMCS executes by default.
 *
 * WHMCS recommends as good practice that all named hook functions are prefixed
 * with the keyword "hook", followed by your module name, followed by the action
 * of the hook function. This helps prevent naming conflicts with other addons
 * and modules.
 *
 * For every hook function you create, you must also register it with WHMCS.
 * There are two ways of registering hooks, both are demonstrated below.
 *
 * @see https://developers.whmcs.com/hooks/
 *
 * @copyright Copyright (c) WHMCS Limited 2016
 * @license https://www.whmcs.com/license/ WHMCS Eula
 */

// Require any libraries needed for the module to function.
// require_once __DIR__ . '/path/to/library/loader.php';
//
// Also, perform any initialization required by the service's library.

/**
 * Register a hook with WHMCS.
 *
 * add_hook(string $hookPointName, int $priority, string|array|Closure $function)
 */
add_hook('AdminHomeWidgets', 1, function() {
    return new SampleRegistrarModuleWidget();
});


add_hook('OrderDomainPricingOverride', 1, function($vars) {
    // Perform operations to determine price

    // logActivity('OrderDomainPricingOverride 900', 0);
    

    $domain  = explode('.', $vars['domain']);
    $sld     = $domain[0];
    $tld     = '.' . $domain[1];


    $domain_name = explode('.', $vars['domain']);
    

    if(count($domain_name)==2 && strlen($domain_name[0])==2 && $domain_name[1]=='ge'){
        return 900.00;
    }
});


/**
 * Sample Registrar Module Admin Dashboard Widget.
 *
 * @see https://developers.whmcs.com/addon-modules/admin-dashboard-widgets/
 */
class SampleRegistrarModuleWidget extends \WHMCS\Module\AbstractWidget
{
    protected $title = 'Sample Registrar Module';
    protected $description = '';
    protected $weight = 150;
    protected $columns = 1;
    protected $cache = false;
    protected $cacheExpiry = 120;
    protected $requiredPermission = '';

    public function getData()
    {
        return array();
    }

    public function generateOutput($data)
    {
        return <<<EOF
<div class="widget-content-padded">
    Your widget output goes here...
</div>
EOF;
    }
}

 

 

Edited by So, who am I ?
Link to comment
Share on other sites

1 hour ago, So, who am I ? said:

I use OrderDomainPricingOverride hook to change some domain price manually, I need two registrars to use this hook, but when I add hook file to the second registrar's folder I get blank page and the whole site shuts down.

I don't use any registrar function in the file, I just check domain's sld and tld and generate price, how can I manage to use the hook for both registrars ?

the registrars should be irrelevant as this just updates the domain price in the cart - there's no communication, or dependency upon, the registrars.

also, i'd remove that widget code from the hook as that's complicating it more than it needs to, plus there's some duplication in there too...

<?php

add_hook('OrderDomainPricingOverride', 1, function($vars) {
	
	$domain  = explode('.', $vars['domain'], 2);
	$sld = $domain[0];
	$tld = $domain[1];
	
	if(strlen($sld) == 2 && $tld == 'ge'){
		return 900.00;
	}
});

the hook should just go in /includes/hooks and then it will be ran on all domains, but only 2-character .ge domains will trigger the price override.

btw - if you're running a multi-currency site, you may need to expand the hook to check for the current currency because this hook just passes a numeric amount back to the cart (900) - depending on the users currency, it could be seen as $900, €900 or 900 Lari. 9_9

Link to comment
Share on other sites

6 hours ago, brian! said:

the registrars should be irrelevant as this just updates the domain price in the cart - there's no communication, or dependency upon, the registrars.

 

I know that, when I first saw site shut down I thought it was cuz of a duplicate function declaration or something like that since the two registrars I refer to, is the same registrar but with the different name and accounts, so basically they have the same files and functions, changed functions' name for one of them but still got error cuz of hook and was a bit confused cuz there was no any registrar function call in hook file.

 

6 hours ago, brian! said:

also, i'd remove that widget code from the hook as that's complicating it more than it needs to, plus there's some duplication in there too...

1

thought to remove it after I left office, will give it a try tomorrow, but I don't think it will solve the problem. oops yeah the duplication, I do explode two times, forgot to delete unnecessary code :$

 

6 hours ago, brian! said:

 


<?php

add_hook('OrderDomainPricingOverride', 1, function($vars) {
	
	$domain  = explode('.', $vars['domain'], 2);
	$sld = $domain[0];
	$tld = $domain[1];
	
	if(strlen($sld) == 2 && $tld == 'ge'){
		return 900.00;
	}
});

 

 

on the other hand, my code is correct cuz I need to change the price for 2-character .ge domains but domains can also be .com.ge,  .net.ge etc and I don't need a different price for them. 

 $domain_name = explode('.', $vars['domain']);
    

    if(count($domain_name)==2 && strlen($domain_name[0])==2 && $domain_name[1]=='ge'){
        return 900.00;
    }

 with count($domain_name)==2, I make sure I catch 2-element array that will be .ge domains only and it won't be .com.ge/.net.ge etc that create 3-element array after exploding.

 

6 hours ago, brian! said:

the hook should just go in /includes/hooks and then it will be ran on all domains, but only 2-character .ge domains will trigger the price override.

1

oh, so it means I can't have the same hook multiple times in different registrars folders...

6 hours ago, brian! said:

btw - if you're running a multi-currency site, you may need to expand the hook to check for the current currency because this hook just passes a numeric amount back to the cart (900) - depending on the users currency, it could be seen as $900, €900 or 900 Lari. 9_9

1

yeah, I know that. will add it later cuz I'm still working on multi-currency site, since I couldn't find the product with a good review and kinda not sure it won't mess up the billings I'm thinking to find the way around it myself and hope it will work ^_^

Link to comment
Share on other sites

5 minutes ago, So, who am I ? said:

on the other hand, my code is correct cuz I need to change the price for 2-character .ge domains but domains can also be .com.ge,  .net.ge etc and I don't need a different price for them. 

there was a reason why I added a limit to the explode function in my hook... :)

if the domain is 'brian.com.ge', that limited explode function will split it into $sld = 'brian' and $tld = 'com.ge'... therefore, you only need to do a check to see if $tld =='ge" and it will only match .ge and not .com.ge :idea:

Link to comment
Share on other sites

7 minutes ago, brian! said:

there was a reason why I added a limit to the explode function in my hook... :)

if the domain is 'brian.com.ge', that limited explode function will split it into $sld = 'brian' and $tld = 'com.ge'... therefore, you only need to do a check to see if $tld =='ge" and it will only match .ge and not .com.ge :idea:

ah lol just noticed the limit in your code, my bad :D 

$domain  = explode('.', $vars['domain'], 2);
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated