Trying to modifying a SMF mod (SMFShop)

I am very new to php and have been taking a weekly class here in town and messing around with some different smf mods for practice. I decided to work on creating a site for my local hobby shop and we settled on using the SMFShop mod. So far I have been able to do a few tweaks that we wanted (removing some options and creating an item), but I am stuck on this tweak. I am hoping somebody may be able to help, it seems to me that it should be pretty simple, I just don’t know the code needed…

When members visit the ‘buy stuff’ page it shows the [all] category by default, and in turn all of the items. We will have nearly 10000 items, which is simply overwhelming. I will be having a large array of categories, and would like to have the category list show [Uncategorized] instead of [All] by default. I am assuming that this would be in the Shop_buy.php file, someplace around here :

[php]
// Are we only displaying a certain category?
if (isset($_GET[‘cat’]) && $_GET[‘cat’] !=-1)
{
$context[‘shop_inv’][‘category’] = (int) $_GET[‘cat’];
$catClause = 'WHERE category = ’ . $context[‘shop_inv’][‘category’];
}
else
{
$context[‘shop_inv’][‘category’] = -1;
$catClause = ‘’;
}

// List of all categories
$context['shop_inv']['categories'] = getCatList();

[/php]

I see that the ‘Uncategorized’ category is ‘0’. I changed the ‘-1’ values in the code to ‘0’ but it didn’t work. It changes the category list to show [uncategorized], but it still loads all of the items, instead of the couple in the ‘uncategorized’ section. Essentially it causes the ‘Uncategorized’ section to be treated as the ‘All’ category. What is the -1 referencing then? And what does the ‘isset’ do? Or more specifically, why does it have the same part twice: ($_GET[‘cat’])

I could not find much at all about the isset code in my book…Thank you very much for any help you can offer.

isset checks that the variable that you are about to use exists. This is good practise when you’re not certain it will be set, for example when a user submits a form. If they visit the page directly or tamper with the form, fields will be missing.

It could also be used with keys in an array:

[php]$full_names = array(‘Bob’ => ‘Bob Bloggs’, ‘Dave’ => ‘Dave Jupp’);

if(isset($full_names[‘Bob’])) {

echo $full_names[‘Bob’];

} else {

echo ‘Bob’;

}[/php]

Enough of isset. Inside of your database table, are the categories set correctly? As a final check, please could you echo the full query once it is about to be used and post it here.

Thanks, jSherz, I was finally able to get this. I had to change some code in the shop.template.php file. Thank you very much for your willingness to help though. Perhaps you might be able to help me on my next issue.

I am now in the process of creating an item for the SMFShop Mod. Essentially, when it is used, the user is given three specific items (itemid 20, 21, and 22). I know that I have to use the INSERT INTO code. So this is what I did exactly:

[php]

<?php // This is just to make sure that the item is used through SMF, and people aren't accessing it directly // Additionally, this is used elsewhere in SMF (in almost all the files) if (!defined('SMF')) die('Hacking attempt...'); class item_DarkStarter extends itemTemplate { // When this function is called, you should set all the item's // variables (see inside this example) function getItemDetails() { // The author's name $this->authorName = 'Overlord'; // The author's website $this->authorWeb = 'http://www.acskirmish.com/'; // --- Values changeable from within the SMFShop admin panel --- // The name of the item $this->name = 'Darksiders Starter Pack'; // The item's description $this->desc = 'The Darksiders Starter Pack. This set contains 15 common e-figs.'; // The item's price $this->price = 35; // --- Unchageable values --- // These values can not be changed when adding the item, they are stuck on what you set them to here. // Whether the item requires input or not. In this case, we don't need // any input $this->require_input = false; // Set this to 'false' if the item is unusable. This is good for display // items, such as rocks :). $this->can_use_item = true; } // Since this item requires no input, we don't need to have a getUseInput function // here (see the testitem2.php file if you want to make an item that needs input) // This is where all the fun begins. This function is called when // the user actually uses the item. Return stuff, DON'T ECHO! function onUse() { // Put the following items into the user's inventory mysql_query("INSERT INTO smf_shop_inventory (ownerid, itemid) VALUES('1', '20' ) ") or die(mysql_error()); mysql_query("INSERT INTO smf_shop_inventory (ownerid, itemid) VALUES('1', '21' ) ") or die(mysql_error()); mysql_query("INSERT INTO smf_shop_inventory (ownerid, itemid) VALUES('1', '22' ) ") or die(mysql_error()); ; return 'You have opened your Darksiders Starter Pack! You received the following e-figs: Angry Farmer Culhaven Lancer Battle Mage'; } } ?>

[/php]

This works perfect, except that it gives the items to ownerid ‘1’ (my account) instead of to the person using the item. From what I see, I should be able to use {$ID_MEMBER} as the ownerid VALUE, but if I do that, the item does not work (just gives me a white/blank error page that says:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '20' )' at line 2

Why is that? Other files (such as shop_buy.php) use it as a value just fine when it adds an item you purchase to your inventory.

Also, it seems like all of the other files in the mod use {db_prefix)table_name, instead of smf_table_name. That also returns an error if I try that.

Can you echo the value of {$ID_MEMBER} and also the raw query before it’s executed? Just so we can see if the $ID_MEMBER is adding any weird characters.

I’m sorry, I am not sure what you mean by:

Can you echo the value of {$ID_MEMBER} and also the raw query before it's executed?

I know what echo is, but not sure how to do this? Just create a new php file with echo($ID_MEMBER)? I did that and just get an empty white page.

I tried to echo($ID_MEMBER) in the item as well, and it does not echo anything.

Do I have to tell it someplace that $ID_MEMBER = user id? I don’t see that in any other file…but I imagine it would work.

I figured it out, I needed a global = $ID_MEMBER added in there. Have to admit, I am getting a bit addicted to this :wink: Nice tutorial by the way, I ave been watching them this morning. Thanks again, jSherz, for the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service