Jump to content

Is there any way to change product before provisioning based on configurable option?


Mechanic

Recommended Posts

Hi!

Here is the scenario. I have two groups of products - one group is hidden. Both groups have the exact name, price, configurable options, and automatic provisioning. The user selects a configuration on the product configure page.

Is there a way to change the product to one from the hidden group, based on the configurable option, so that the one from the hidden group is provisioned after payment?

My goal is to automatically provision a product from the hidden group, so the product can be changed on the view cart, checkout or somewhere before adding the order information into the DB.

I have very basic experience with PHP, Smarty, and Hooks but don't know enough regarding WHMCS. I would appreciate any help or at least guidance on where to look at.

 

Link to comment
Share on other sites

Two options basically:

  • You could potentially do this via the WHMCS\Service\Service internal class and change the packageid to the hidden package
  • Or use the updateclientproduct API call with just pid provided, but that may require passing configurable options also

Either would be triggered via shoppingcartcheckoutcompletepage hook.

What is your use case for this type of setup?   I could see it different locations for example.

Edited by steven99
Link to comment
Share on other sites

22 minutes ago, steven99 said:

Two options basically:

  • You could potentially do this via the WHMCS\Service\Service internal class and change the packageid to the hidden package
  • Or use the updateclientproduct API call with just pid provided, but that may require passing configurable options also

Either would be triggered via shoppingcartcheckoutcompletepage hook.

What is your use case for this type of setup?   I could see it different locations for example.

Edited 21 minutes ago by steven99

Thanks a lot for the heads up. I have experience with basic hooks like changing menu items or sidebars. Never used a class or API call.

Would it be possible to guide me a bit more about how to use the API call/class?

Link to comment
Share on other sites

https://docs.whmcs.com/Using_Models has some information using the internal classes / models. Most (if not all) models represent a table within the database.   So WHMCS\User\Client is for tblclients.

And with that information in hand, head over to https://docs.whmcs.com/classes/7.6/index.html that shows what classes are officially available and what their properties are.  To get a class object of an item already stored, you would do the following for most of them

$VarName = WHMCS\CLASS_NAME\subclass::find(id);

(may want to use a try/catch also)

Then you edit the item you want to change just like any other object and do the following to save those changes:

$VarName->save();

(note, not 100% sure if hooks trigger when doing save when otherwise would have been, should test that out one day)

Personally have been moving towards using the internal classes and moving away from the API if possible for at least editing and fetching of related items.  By related items, I mean like invoices or products of a client for example.

$Client = WHMCS\User\Client::find(1);
if ($Client)
{
    $Services = $Client->services();
    $domains = array();
    foreach($Services as $service)
    {
       $domains[] = $service->domain;
    }
}

 

Link to comment
Share on other sites

2 hours ago, steven99 said:

https://docs.whmcs.com/Using_Models has some information using the internal classes / models. Most (if not all) models represent a table within the database.   So WHMCS\User\Client is for tblclients.

Well, what you said still went over my head. But thank you for showing where to start. I'll try it once I finish my conversation with you 🙂

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