Mechanic Posted March 30, 2019 Share Posted March 30, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted April 1, 2019 Share Posted April 1, 2019 (edited) 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 April 1, 2019 by steven99 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted April 1, 2019 Author Share Posted April 1, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted April 2, 2019 Share Posted April 2, 2019 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; } } 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted April 2, 2019 Author Share Posted April 2, 2019 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 🙂 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.