View Full Version : Stock #'s?
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 ;)
skshost
04-08-07, 01:26 PM
it wouldn't be that hard, just have to pull it from the database really.
Do you have a little script snippet or something to show me how it's done? I tried doing it myself, but I'm rusty on my PHP skills.
(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
skshost
04-09-07, 02:47 PM
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"
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
skshost
04-09-07, 03:05 PM
I wonder where you want to display this info? There's not to many places I can imagine needing it outside the order form.
I wonder where you want to display this info? There's not to many places I can imagine needing it outside the order form.
On custom pages, like I my whole dedicated server page on my site is straight from the database!
Example:
http://www.eastsolid.com/dedicated/serverSale.php?gid=12&sale=8075-02
From,
Adam
othellotech
04-10-07, 03:02 AM
[quote=skshost]
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.
[quote=skshost]
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
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.