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.
![Smiley :)](http://smfshop.com/forum/Smileys/alive/smiley.gif)
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:
$user_profile[$row['ID_MEMBER']] = $row;
You'd add something like:
// 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:
// 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'], '"> ';
}
}
// 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
![Smiley :)](http://smfshop.com/forum/Smileys/alive/smiley.gif)
. Please refer to the SMF Coding Guidelines as well, as these detail things like this (as well as other important things like coding styles).