Author Topic: SMFShop Inventory Post Modification  (Read 96700 times)

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #15 on: September 20, 2007, 09:28:58 pm »
Great item, thanks for your hard work! I am just wondering, if the user has more than 10 items, which ones get shown? Can the user choose the items to display?

I am planing to use it with Feeble's changes (i.e. nothing gets shown if they have nothing). But I was wondering about which items get displayed and if there is a choice for it. Also, is there a demo forum with this running that I can see?

Thanks again!!

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #16 on: September 20, 2007, 09:58:01 pm »
Great item, thanks for your hard work! I am just wondering, if the user has more than 10 items, which ones get shown? Can the user choose the items to display?

I am planing to use it with Feeble's changes (i.e. nothing gets shown if they have nothing). But I was wondering about which items get displayed and if there is a choice for it. Also, is there a demo forum with this running that I can see?

Thanks again!!

they get displayed in order of purchase, but if you wanted to display them in order of a certain condition you could add this bit of code

ORDER BY ****** ****

with the first set of asterix being the condition and the second set of asterix being whether read in ASC (ascending) or DESC (descending) so say you wanted to order by price you could go

ORDER BY it.price ASC which would go 1st least expensive > 10th most expensive in the users inventory

and DESC would change flip the order so most expensive to 10th least expensive in the users inventory

and just put that order code in this statement

Code: [Select]
$result = db_query("
SELECT it.desc, it.image, inv.id
FROM {$db_prefix}shop_inventory AS inv, {$db_prefix}shop_items AS it
WHERE inv.ownerid = {$message['member']['id']} AND inv.itemid = it.id
                        ORDER BY it.price ASC
LIMIT 10", __FILE__, __LINE__);

and if you wanted to change how many items you display just change the LIMIT 10 to whatever number you want.

on that note all of this will be added into the new version which will have an admin section and allow you to switch from sig to post view and order of items how many to show etc but i haven't finished it yet so if you want to do those in the interim that's cool. just bare in mind any changes in code will result in the item not uninstalling unless you make the changes in the actual packages xml file before installing.

hope that helps.
« Last Edit: September 20, 2007, 09:59:44 pm by inkstains »

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #17 on: September 20, 2007, 10:23:34 pm »
Hi, thanks for the reply!

Is there a code I can use now to display items only from certain categories? I want to only show items from the "collectibles" and "toys" categories. The rest such as steal item are put in other categories which I don't want to show up... I don't mind which order they appear in, but I would rather have miscellaneous items like that hidden...

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #18 on: September 20, 2007, 11:16:37 pm »
something like this

Code: [Select]
//BEGIN SMFShop Inventory Signature MOD
//get the inventory
$result = db_query("
SELECT it.desc, it.image, it.category, inv.id
FROM {$db_prefix}shop_inventory AS inv, {$db_prefix}shop_items AS it
WHERE inv.ownerid = {$message['member']['id']} AND inv.itemid = it.id
LIMIT 10", __FILE__, __LINE__);
if(mysql_num_rows($result) == 0){
echo '<fieldset><legend><a href="', $scripturl, '?action=shop;do=invother2;member=', $message['member']['username'], '">View Entire Inventory</a></legend>
<img src="{$boardurl}/Sources/shop/item_images/blank.gif">&nbsp;&nbsp;
</fieldset>';
}
else{
echo '<fieldset><legend><a href="', $scripturl, '?action=shop;do=invother2;member=', $message['member']['username'], '">View Entire Inventory</a></legend>';
while ($row = mysql_fetch_assoc($result)){
if (($row['category']) == 1){
echo "<img src='{$boardurl}/Sources/shop/item_images/{$row['image']}'title='{$row['desc']}'>&nbsp;&nbsp;";
}
elseif (($row['category']) == 2){
echo "<img src='{$boardurl}/Sources/shop/item_images/{$row['image']}'title='{$row['desc']}'>&nbsp;&nbsp;";
}
}
echo '</fieldset>';
}
//END SMFShop Inventory Signature MOD

and just change the if elseif statements comparison value to your category id's

and that should work
« Last Edit: September 20, 2007, 11:36:33 pm by inkstains »

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #19 on: September 20, 2007, 11:39:51 pm »
I will give it a shot and let you know, thanks much :D

EDIT: I'm going to wait for the next version actually. I like the idea of only displaying once per page :) Also, that way I won't have to hack anything and hopefully it will install smoothly! I'm keeping an eye on this thread.
« Last Edit: September 21, 2007, 01:18:19 am by sc2 »

Offline Daniel15

Re: SMFShop Inventory Post Modification
« Reply #20 on: September 21, 2007, 10:02:50 am »
Hey inkstains, nice work. This has been requested heaps, and it's great to know that someone's finally worked on it. Again, this was one of the things I was going to work on, but never had any time to. :)

I've got a few suggestions for you. The main thing is that with SMF, it's usually suggested that no queries should be added to the templates. Basically, the Source files (in Sources directory) contain all the "business logic" (database queries, etc.), and the Templates are responsible for formatting it all nicely. Yes, I used queries in the templates in older versions of SMFShop, but this has been fixed in the current version (compare the SMFShop 3.0 Display.template.php edit with previous versions).

So, how do you do this properly? The best way is to edit the loadMemberData and loadMemberContext functions in Sources/Load.php. These are the functions that load all the member data (group, post count, karma, etc.) for member profiles, as well as the "postbit" (the bit to the left of posts). You'd need to add your own query here.

Basically, underneath the bit that says:
Code: [Select]
$user_profile[$row['ID_MEMBER']] = $row;You'd add something like:
Code: [Select]
// BEGIN SMFShop Inventory Signature MOD
// Get their inventory.
$result = db_query("
SELECT it.desc, it.image, inv.id
FROM {$db_prefix}shop_inventory AS inv, {$db_prefix}shop_items AS it
WHERE inv.ownerid = {$row['ID_MEMBER']} AND inv.itemid = it.id
LIMIT 10", __FILE__, __LINE__);

// Start with an empty list.
$user_profile[$row['ID_MEMBER']]['shop_items'] = array();
// Loop through all their items.
while ($row = mysql_fetch_assoc($result))
{
// Add this item to the list.
$user_profile[$row['ID_MEMBER']]['shop_items'][] = array(
'image' => $row['image'],
'desc' => $row['desc'],
);
}
// END SMFShop Inventory Signature MOD

Then, your code in Display.template.php would look a little like:
Code: [Select]
// BEGIN SMFShop Inventory Signature MOD
// Are there any inventory items?
if (count($message['member']['shop_items']) != 0)
{
echo '<fieldset><legend><a href="', $scripturl, '?action=shop;do=invother2;member=', $message['member']['username'], '">View Inventory</a></legend>';
// Loop through all the items
foreach ($message['member']['shop_items'] as $shop_item)
{
echo '<img src="', $boardurl, '/Sources/shop/item_images/', $shop_item['image'], '" title="', $row['desc'], '">&nbsp;&nbsp;';
}
}
// END SMFShop Inventory Signature MOD
A lot neater, wouldn't you say? Also, you can now display the same stuff on their profile, by editing Profile.template.php ;)

Disclaimer: I have not tested this code, and have not looked at your mod (other than the code posted in this topic). This would need minor tweaks to get it to work.

Hope this helps you :). Please refer to the SMF Coding Guidelines as well, as these detail things like this (as well as other important things like coding styles).

Offline Licorne

Re: SMFShop Inventory Post Modification
« Reply #21 on: September 21, 2007, 01:44:14 pm »
Is it possible to set a limited number of items to show?

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #22 on: September 21, 2007, 01:54:28 pm »
the versions in the first post will only show 10 of a users items, but you can change that if you want by changing LIMIT 10 to LIMIT "insert number"

but i'll have the new version up some time later today so i'd recommend waiting for that you can set everything through admin and it's alot cleaner.

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #23 on: September 21, 2007, 03:38:46 pm »
Oh wow, so soon. I can wait then :)

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #24 on: September 22, 2007, 11:04:52 pm »
been a little busy, it'll be up some time tomorrow. it probably won't include sort functions in the admin section at this stage but a small edit will make it possible for what you're looking for sc2.  :)

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #25 on: September 22, 2007, 11:37:02 pm »
Sure, no problems :) I don't need an admin section at all, just the code for things like showing their items for trade, etc. But I understand other's might want an admin section for everything.

Take your time, no rush  :D

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #26 on: September 23, 2007, 02:58:23 pm »
updated. please check first post.  :)

Offline sc2

Re: SMFShop Inventory Post Modification
« Reply #27 on: September 24, 2007, 12:44:24 pm »
Thanks for your work!

Offline inkstains

Re: SMFShop Inventory Post Modification
« Reply #28 on: September 25, 2007, 09:06:36 pm »
no problem if you want a hand setting it up so it'll only show from those to categories like you were saying earlier in this thread just send me an IM

also package updated
« Last Edit: September 25, 2007, 10:12:26 pm by inkstains »

Offline Licorne

Re: SMFShop Inventory Post Modification
« Reply #29 on: September 28, 2007, 08:52:32 am »
Yay! The admin configuration is a definite lifesaver! Thank you!