Jump to content
ukndoit

Product Stock Control - Multiple items - same Product - reducing stock upon orders

Recommended Posts

Okay, the title kind of says it.

I have the same sku listed on multiple items, because of having different payment options.

I have one where they can join with a deposit and then have the upgrade for when we are ready for them to (after they approve the design we do)

and so that is 2 different items, the first one is for the deposit, then the upgrade.

The 3rd one is the same as the deposit one, but is full payment up front, so we collect the same custom fields, for the data we need. but they won't need an upgrade.
 

The problem is, I need the stock control for the first one and third one to be the same.

If they order the deposit, then I want to have it reduce the stock of the full payment one, since someone already ordered that particular one.

If they do the full payment, I need it to reduce the deposit stock by 1.

 

Because these all have just 1 anyways, because it is a position on a particular mailer, they will always have a code of just 1.

So I'm wondering if someone knows what kind of hook I'd need to make and where I could put it, that if say "item 200 is ordered" then reduce stock control of item 201 after reducing stock control of the item 200 that was just ordered"...

 

I supposed I could add a field to the database, and if an item is ordered I could make a hook that after orders are processed, check if that field is set, if so, check which items they are and go minus 1 from the stock, right?

If I can do it that way, where would I put that hook? What database table would I have to add that field to? would it break something by adding that field to that database?

I'll do it all myself, just not sure where to go about putting all of this.

Thanks for any insight you can provide.

-Richard

 

 

Share this post


Link to post
Share on other sites
19 hours ago, ukndoit said:

So I'm wondering if someone knows what kind of hook I'd need to make and where I could put it, that if say "item 200 is ordered" then reduce stock control of item 201 after reducing stock control of the item 200 that was just ordered"...

there would be a few where it might be applicable... I suppose AcceptOrder would be a good one as I assume there is no point changing stock levels on other products until you accept the order..

19 hours ago, ukndoit said:

I supposed I could add a field to the database, and if an item is ordered I could make a hook that after orders are processed, check if that field is set, if so, check which items they are and go minus 1 from the stock, right?

If I can do it that way, where would I put that hook? What database table would I have to add that field to? would it break something by adding that field to that database?

I think that you might be overcomplicating this with the thought of additional database fields - if I understand your situation correctly, all you really need to do (after order acceptance, and possibly after cancellations too) is to get the stock level of one product, and update the stock level of another product with the same value.

the database table to look at is tblproducts and specifically the 'stockcontrol' and 'qty' fields - stockcontrol will be 1 if stock control is enabled on that product (0 if it's not)... and 'qty' will be the actual stock level for that product.

Share this post


Link to post
Share on other sites

Hi Brian, thank you for the response.

So I checked orders.php and it is fully encrypted.

Where would I find that to see about doing this?

I don't see an AcceptOrder.php script or any name like it.

Thank you sir!

-Richard

 

Share this post


Link to post
Share on other sites
21 hours ago, brian! said:

oh sorry, as you were asking about hooks, I assumed that you had already visited the hooks documentation pages.

https://developers.whmcs.com/hooks-reference/shopping-cart/#acceptorder

Excellent Brian, so as I see it, I would create a file in /hooks

and name it like:

AcceptOrder.php
and then create a hook therein:

 

<?php
add_hook('AcceptOrder', 1, function($vars) {
    // Perform hook code here...
});

now in AcceptOrder, does it have these already set as variables?

$pid // as the product id?
$gid // as the group id?

or do I have to go get those from the order or something?

If so, what would I be using to check those? Like do I have to pull it out of a particular table? etc.

Thank you much for your insight!!

-Richard

 

 

Share this post


Link to post
Share on other sites

Hi Richard,

5 hours ago, ukndoit said:

so as I see it, I would create a file in /hooks and name it like: AcceptOrder.php and then create a hook therein

you could call it whatever you like (as long as it ends with .php) - so give it a memorable name that reminds you what it does.

5 hours ago, ukndoit said:

now in AcceptOrder, does it have these already set as variables?

$pid // as the product id?
$gid // as the group id?

or do I have to go get those from the order or something?

it will give you the order ID - don't forget that an order could contain multiple products.

5 hours ago, ukndoit said:

If so, what would I be using to check those? Like do I have to pull it out of a particular table? etc.

grab a flask of something strong, we're going on a journey... 🐪

the orderID will give you the ID value for a row in the tblorders database table... from that row in tblorders, you can get the Invoice ID associated with the order... using that invoiceID, you can get the products in the order from tblinvoiceitems... using the 'relid' values from tblinvoiceitems for that invoice will give you id value(s) in either tblhosting, tbldomains or tblhostingaddons (depending if it's a product/domain/addon)... let's assume it's a product - in tblhosting, the 'packageid' value will be the PID value that you are familiar with... if you then needed to know the GID value, you would have to take that 'packageid' value as use it as the 'id' value in tblproducts to get the 'gid' value from the same table.

now take a drink from the flask as you've earned it. 🍾

another path would be to use the API, e.g GetOrders...

https://developers.whmcs.com/api-reference/getorders/

so there are any number of ways to get the information you want, you just need to decide what data you want and the easiest method to get it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines