Jump to content

LocalApi call overrides currency


Recommended Posts

Hi. I'm trying to change price on product upgrade. So here is my little hook:

 

add_hook('OrderProductUpgradeOverride', 1, function($vars) {
    $return = [];

    if ($vars['oldproductid'] == 111) {

        $results = localAPI('GetProducts', array('pid' => $vars['newproductid']), '');

        if ($results['result'] == 'success') {
            $price = $results['products']['product'][0]['pricing']['UAH'][$vars['newproductbillingcycle']];
            $return['price'] = $price;
        } 
    }

    return $return;
});

If client is trying to change product with ID = 111 - I'm searching for the full price for selected new period of new product and returning it instead of recalculated price which depends on days and etc.

Client has UAH (грн in local language) currency in profile , but in this case he is getting prices in USD  (Screenshot_1)

 

If I'm not calling LocalAPI and overriding, for example, like this:

add_hook('OrderProductUpgradeOverride', 1, function($vars) {
    $return = [];

    if ($vars['oldproductid'] == 111) {
        $price = 1;
        $return['price'] = $price;
    }

    return $return;
});

Currency displayed correctly (Screenshot_2)

 

Can someone help with this?

Screenshot_1.jpg

Screenshot_2.jpg

Link to comment
Share on other sites

it's probably worth mentioning that during product upgrades, the next due date does not change.

so let's say I upgrade the Package One service today, but the next due date is 1st June... WHMCS calculates the upgrade price based on the formula in the docs to upgrade the service to Package Two up until 1st June - you are NOT upgrading the service for another full YEAR/MONTH or whatever the new billingcycle is.... on the 1st June (or whenever automation settings permit it), a renewal invoice would be generated for the upgraded service (Package 2) for the full amount.

so knowing that now, do you still need the hook to work in the above way?

personally, I would first get the client's currency ID value (unless you're saying that all your clients are using UAH ?) and then query the database direct for the relevant price value (capsule query to tblpricing or using the model method).

Link to comment
Share on other sites

Thank you for your answer. But the main question is - why currency changed on client side?

I have used API call to “read only” function GetProducts to get some float value. I didn’t call any function which updates something or changes something. 

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