Jump to content

Domain categories access


Remitur

Recommended Posts

Since WHMCS 7.10 domain categories are no more available in a table in db, but in the file(s)  /resources/domains/dist.categories.json and /resources/domains/categories.json

https://docs.whmcs.com/Domain_Categories )

The question is: having to use this data in a PHP script, are this data yet available in some kind af PHP array variable in WHMCS environment, or do I need to read and import the data from the .json files?

 

Link to comment
Share on other sites

59 minutes ago, Remitur said:

The question is: having to use this data in a PHP script, are this data yet available in some kind of PHP array variable in WHMCS environment, or do I need to read and import the data from the .json files?

probably depends when and where you're doing this... I would have thought the array would be accessible on the domain register (and transfer I think) pages if you were hooking, but outside of there, it will be a case of checking for the existence and optionally combining the json files.

Link to comment
Share on other sites

  • 2 weeks later...

Just fo reference: the PHP code to recover new WHMCS categories and store them in $tldnewcategories is the following:

 

if (file_exists ("resources/domains/categories.json")) {
	$myjsonfile = file_get_contents("resources/domains/categories.json");
} else {
	$myjsonfile = file_get_contents("resources/domains/dist.categories.json");
}
$tldnewcategories=json_decode($myjsonfile, true);

 

Link to comment
Share on other sites

46 minutes ago, Remitur said:

Just fo reference: the PHP code to recover new WHMCS categories and store them in $tldnewcategories

that would work to some degree, except it implies that you are using categories.json to contain a full list of categories/tlds, whereas in reality, WHMCS would load the default dist. file first and then merge the custom categories.json file to the array.

e.g if we take a hypothetical case of categories.json just containing the "Popular" category with com/net/org not included, then because WHMCS loads the dist file first (which includes com/net/org) and appends with the content of categories.json, then com.net/org will still in there - but they wouldn't be with your code...

which is a long winded way of saying that what your code returns might not necessarily be the same as what WHMCS will be working with itself.

Link to comment
Share on other sites

16 hours ago, brian! said:

that would work to some degree, except it implies that you are using categories.json to contain a full list of categories/tlds, whereas in reality, WHMCS would load the default dist. file first and then merge the custom categories.json file to the array.

e.g if we take a hypothetical case of categories.json just containing the "Popular" category with com/net/org not included, then because WHMCS loads the dist file first (which includes com/net/org) and appends with the content of categories.json, then com.net/org will still in there - but they wouldn't be with your code...

 

Hummm ...

I did few tests, and (sadly) you're right...

And I'm writing "sadly" because this means that it's impossible to remove a .tld from a category, or remove a whole category, or rename a category (if you rename a category, you'll find both of them: the old and the new one...)

It would be much better if WHMCS would use just categories.json (if it exists), otherwise will use the default one...

 

Link to comment
Share on other sites

2 hours ago, Remitur said:

And I'm writing "sadly" because this means that it's impossible to remove a .tld from a category, or remove a whole category, or rename a category (if you rename a category, you'll find both of them: the old and the new one...)

indeed - it is sad! 😞

2 hours ago, Remitur said:

It would be much better if WHMCS would use just categories.json (if it exists), otherwise will use the default one...

yep - but it took them years from moving them from the database (where we too weren't supposed to modify them as WHMCS could overwrite with an update) to a json file where they still can't be realistically changed unless you go against the instructions in the docs.... to change it now, your back to square one of starting a feature request for (I assume) to fix a previous feature request that wasn't properly implemented.

you can't even delete the dist.categories.json file as that causes an error on the domain register & pricing pages.

I think the best you can do in the short-term is either empty dist.categories.json as I outlined in the above post, e.g just make it {}, or just edit dist.categories.json directly to make your changes - either way, you would have to watch out when updating as dist would be overwritten.

with regards to renaming a category - if you were doing this on the register/prices pages (or anywhere with a similar array), then the categories can use language strings - though they don't exist by default in the language files and you would therefore have to create them yourself using Language Overrides ...

WHMCS took, sorry embraced, that idea from me with code I posted back in April 2015 in the v6 beta forums (seems a lifetime ago lol)...

{if $LANG.{$tldCategory->category}} {$LANG.{$tldCategory->category}} {else} {$tldCategory->category} {$LANG.tldpricing}{/if} 

with changes to Smarty over the years, that has now become...

{lang key="domainTldCategory.$category" defaultValue=$category}

though I think it still took them a couple of years to get around to doing that.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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