Jump to content

Stock #'s?


Digit9

Recommended Posts

Is there a way to display the number of items I have in stock for a specific item?

 

Say I wanna display a server packages stock. It's ID "0000000008". So if I could get a neat little script to say:

print $stock['0000000008'];

 

That would be awesome ;)

Link to comment
Share on other sites

(If you're rusty, you can polish up! :mrgreen:)

 

Not sure .. but you may want to see if {$product.qty} works first (that is if the $product array is available in the template you are trying to use).

 

otherwise, my recommended way is to add a smarty function (in whmcs_dir/libs/plugins), since you don't want to see connections strings to a db in your smarty templates.

 

It really depends on you you are doing, but you will need to connect to the db.

 

then do your select: (this will get a result for one GID only. $productpid is assumed passed to the function get it in the $params array ie: $params['pid'])

SELECT qty FROM tblproducts WHERE gid=$productpid

then pass it back to the template in the function by returning the result.

 

There are many tutorials on Smarty at smarty.php.net

Link to comment
Share on other sites

you don't want to see connections strings to a db in your smarty templates.

 

To be specific, you wouldn't need a connection string, but I can certainly understand not wanting to display your DB table info. It just depends. I personally would have no problem with it since I've done it before.

 

It's not like anyone else is going to see it, right?

 

Technically if you want to do it right you'll want to get much of your product info and display it as if the product array was already there.. like: {$product.qty}, etc..

 

Again, this isn't that hard. You'll be on smarty.php.net quite a bit, but also search this forum cause I know there's a few examples of getting from the DB and passing to smarty. Infact I did it just last night.. "Departments Dropdown"

Link to comment
Share on other sites

  • WHMCS CEO

I presume this is not in the templates that you are trying to do this so you would need to connect to the database using a normal connection routine and then use code such as the following:

 

$query = "SELECT qty FROM tblproducts WHERE id='1'";
$result=mysql_query($query);
$data = mysql_fetch_array($result);
$qty = $data['qty'];
if ($qty=="0") {
echo("Currently Out Of Stock");
} else {
echo("$qty Available");
}

 

Matt

Link to comment
Share on other sites

my whole dedicated server page on my site is straight from the database!

I'm impressed - very slick - is it limited to 6 and did you need to know the WHMCS pids or ... ?

 

Any chance of sharing, I'd like to see the php code you used for pulling all the details out.

 

No, those are the only stuff in that gid. Ya I'm going to be finishing up version 1.0 of Kayako to WHMCS integration (currently have it working on my WHMCS install). Once I finish up the docs and do some more testing I will work on getting that out as well.

 

From,

Adam

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