Jump to content

Recover domain price list in Smarty


Walther

Recommended Posts

Hello.

The API GetTLDPricing ( https://developers.whmcs.com/api-reference/gettldpricing/ )   gives as response an array with all available prices for every available extension domain; and this array may be available in Smarty, getting in Smarty something like:

$tldpricing2
Origin: "Smarty object"	
Value
Array (3)
result => "success"
currency => Array (6)
  id => "1"
  code => "USD"
  prefix => "$"
  suffix => " USD"
  format => "1"
  rate => "1.00000"
pricing => Array (13)
  com => Array (8)
    categories => Array (2)
      0 => "gTLD"
      1 => "Popular"
    addons => Array (3)
      dns => false
      email => false
      idprotect => false
    group => ""
    register => Array (1)
      1 => "14.95"
    transfer => Array (1)
      1 => "14.95"
    renew => Array (1)
      1 => "14.95"
    grace_period => Array (2)
      days => 30
      price => WHMCS\View\Formatter\Price Object (0)
    redemption_period => null
  net => Array (8)
    categories => Array (2)
      0 => "gTLD"
      1 => "Popular"
    addons => Array (3)
      dns => false
      email => false
      idprotect => false
    group => ""
    register => Array (1)
      1 => "14.95"
    transfer => Array (1)
      1 => "14.95"
    renew => Array (1)
      1 => "14.95"
    grace_period => Array (2)
      days => 30
      price => WHMCS\View\Formatter\Price Object (0)
    redemption_period => null

I have two different issues about this...

1 - what's the right syntax to recover, i.e.,  the registration price for a certain domain?
I tried almost every possible syntax (but obviously missed the right one...)
I defined the the extension using      

{$tld2=$tld|ltrim:'.'}

and it works, so i.e. $tld2 gives "net" ...

But if I try   $tldpricing2[pricing][$tld2] [register][1] , or using -> , or any other possible PHP/smarty syntax, I'm getting garbage instead of the desired value... 😕

So, what's the right Smarty syntax to recover that value? 

 

2 - about grace period renewal...WTF is "   WHMCS\View\Formatter\Price Object (0) " ?!
Why is it now given as any other price for registration, transfer or renew?
And how can I convert it into a number (hopely, the right one) ?

  

 

Link to comment
Share on other sites

On 20/10/2020 at 15:37, Walther said:

So, what's the right Smarty syntax to recover that value? 

in Smarty, it would be...

{$tldpricing2.pricing.$tld2.register[1]}

to return a 1 year registration price, in the current currency.

On 20/10/2020 at 15:37, Walther said:

2 - about grace period renewal...WTF is "   WHMCS\View\Formatter\Price Object (0) " ?!

https://classdocs.whmcs.com/8.0/WHMCS/View/Formatter/Price.html

On 20/10/2020 at 15:37, Walther said:

Why is it now given as any other price for registration, transfer or renew?

probably because they can be more flexible to manipulate than if they were strings.

On 20/10/2020 at 15:37, Walther said:

And how can I convert it into a number (hopely, the right one) ?

in Smarty, it would be...

{$tldpricing2.pricing.$tld2.register[1]->toNumeric()}
Link to comment
Share on other sites

On 10/22/2020 at 6:00 PM, brian! said:

probably because they can be more flexible to manipulate than if they were strings.

What is crazy and misleading is that in the very same array you can find values as normal string (register, renew, transfer), and just redemption fee is in form of  "Price Object"...

Apart from this, thank you for your precious support!

Link to comment
Share on other sites

On 10/22/2020 at 6:00 PM, brian! said:

in Smarty, it would be...


{$tldpricing2.pricing.$tld2.register[1]->toNumeric()}

Precisely, it's 

{$tldpricing2.pricing.$tld2.grace_period.price->toNumeric()}

(grace period price and redemption price are the only values got as Price Object; other prices,  as registration, renew and trasfer, are provided as string)

This thread gave me an idea... news will follow shortly  😉

Link to comment
Share on other sites

On 24/10/2020 at 10:42, Walther said:

What is crazy and misleading is that in the very same array you can find values as normal string (register, renew, transfer), and just redemption fee is in form of  "Price Object"...

that's mainly a legacy issue where in ye olde days, Price Objects weren't used and everything was either a string or an integer... new pricing values now tend to use the new format, so you end up with mixed arrays containing  the results of various methods.

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