My First Plugin: SimpleCart
January 26, 2009So, here it is. The tutorial I wrote a couple of weeks ago on putting Mal’s into WordPress with some functions is now a plugin. This is totally my first plugin – I’ve never written one before. I fully expect to be lambasted with “this sucks!” and…stuff like that.
I really think you should read the info below, but if you’re like me, you just want the files.
IMPORTANT UPDATE: August 10, 2009: Someone pointed out a GRAVE error in the files. It’s not a security thing, but it is VERY important that you re-download the files (if you downloaded them before today) and use the new ones. Apparently, I had used code for a working *major* upgrade to this plugin within these theme files, and inadvertently added a bit of code that gives ME credit to the design of any website that uses this plugin. THIS IS A MAJOR OVERSIGHT on my part, and I apologize to anyone who used this and saw *me* getting credit for their hard work. This was NOT my intent at all – it was a stupid mistake on my part, and I really really apologize for it. The offending code has been removed from these files, so please re-download and use these new files so that credit link is removed from your site.
So I’ll give some simple information here – there’s a lot more detail in the “readme.txt” file. Basically, the Zipped file has a folder in it that contains the directory tree you need to upload. DON’T upload the “SimpleCart” flder you see as soon as you Unzip – upload the files *in* the “SimpleCart” folder to the root level of your WordPress installation (where wp-admin, wp-content and wp-includes are located). If you do this, the files will upload to where they need to go (just be sure you rename the “YOUR THEME” folder to your actual theme folder’s name). Once they are uploaded, just activate and set it up under “Settings>SimpleCart.”
This does write some stuff to your database. It adds 6 new tables to your wp-options area. All 6 sections begin with “sc_” – so if you ever want to uninstall this, you can just remove those tables via phpMyAdmin. It also writes custom fields to your posts (the ones that actually use the product listing stuff).
This is for the FREE version of Mal’s. (I don’t have access to the paid-for version yet. One step at a time, okay?) This plugin DOES NOT set up Mal’s for you. You have to go into your Mal’s account and set up that end the way you want it to be. If you plan to use the remote callback feature (for right now, this will only help with stock levels, and nothing more), then you want to point the remote callpack URL to point to the sc-call.php file that you placed in the root of your WordPress install. It’s up to you to make sure the remote callback actually connects to your database and works – that’s all dependent on your host’s setup and whether or not they allow it (and by what method – GET or POST). I tried to help as much as I could on this end: within the sc-call.php file, you can uncomment a section that will place an “error log” on your server. So if it doesn’t connect, it’ll place the errors in that file. Mals’ also allows you to check to see if it’s working by sending you a “Debug” email with any errors it receives. but all hat script does is take the callback (once it’s working and connecting properly) and parse it to output the values needed for your products, and it’ll alter your stock levels when someone buys something.
This plugin will also not stop a purchase if someone is buying more than is available. meaning, if you have 3 of an item left, and someone adds it to their cart and then alters the amount to “7″, then they will pay for 7. You will have to contact them manually and ask what they would like you to do for the 4 items they purchased above and beyond what was available. For the record, though – they will have been warned. The plugin *does* put a (stylable) message on the product page when your low-level hits 5 or less. So it’s not like they will go into it blindly.
Right now, it’s set up to use buttons located in the images folder of your theme files. I have supplied these images for you – but you will have to change the name of the “YOUR THEME” folder to whatever your theme is before you upload. If you don’t like the buttons, you can obviously make new ones of your own – just replace the ones in the folder.
Once you have everything uploaded, activated, and configured, you’ll want your theme files to actually display the content. So in your single.php file, you’ll want to REPLACE <?php the_content(); ?> with <?php product_display('full'); ?>. This will pull in all of the custom field information, as well as the content you wrote for the post (use the post content area as your product description).
On your category.php and/or archive.php files, you will want to do the same thing, except use <?php product_display('summary'); ?> to display the item for the product listing pages.
I think that’s it – it’s late and that’s really all I can think of to tell you. If I missed anything, don’t forget to read the “readme.txt” file – it’s probably in there if I didn’t hit it here.
If you do download and install this, PLEASE give me feedback! I already have planned improvements for it – but I don’t want to “improve” anything if this is garbage. If it’s great, that’s great. If there’s something you’d like to see – some feature, or something that needs clarification to make it better – PLEASE tell me. I’d really like to make this work well for those who need it.
Thanks, and don’t forget to let me know how it goes!
Download SimpleCart [.zip]










P.O. Box 46
Shelly, this is such an accomplishment! I can definitely see this being very useful in the future for many web developers out there!
Hi
the install instructions are good except for the ambiguous part about changing the two bits of code”
6. Open up your ‘category.php’ file and add in “ in place of “. This will cause your category listings to display a title, image and price for each product(post). If you would like to keep your blog/site in action, and have your cart relegated only to a single category, then use the category template for that particular category – the other categories will not be affected.
7. Open up your ’single.php’ file and add in “ in place of “. This will cause all information to show for that product (post), as well as the buy now/add to cart/view cart buttons. (If you only want certain categories affected, use conditionals for replacing the_content(); so the rest of your site is not affected.)
It would be best if the exact location and the total part of the code to be replaced could be included as currently I fin it a bit ambiguous and replacing what I think it right has no affect on the post – no price etc its shown.
Email me back if you like
Well, I *do* (as you’ve just stated) provide instructions. You must replace <?php the_content(); ?> with <?php product_display(‘full’); ?> on the single post template file (single.php). I can’t get any more exact than that. People have different themes, and this bit of code (that displays the content) could be *anywhere*. I can’t tell you exactly where it will be on every single theme there is, because it may not be there, and it may not be coded exactly the way the default theme is.
And I say it has “no effect on the post” in the *regular* categories for your normal blog, as long as you are using conditionals (or a category.php file) to separate the blog from your cart category. If your whole site will be a cart, there’s no need to use conditionals, and the product display will use your post content as the product description, and add in the other stuff you put in to the post. (If nothing is showing, then I can only assume you didn’t enter in a price or anything into your “Product Information” fields). if you are still going to use a blog, put the product stuff in a separate category, and/or use conditionals to force the theme to make the distinction between the cart and the rest of the site.
I also offer up quite a bit more documentation in the readme.txt file. What you are quoting are the simple instructions within the Settings area.
Thank you for your feedback, I really do appreciate it. It’s actually come a lot further than the link I’ve posted here – but unfortunately the files are on my main computer, which is “in the shop” right now, so I can’t upload them. (And actually, the “readme” and instructions are the *last* thing I’m working on – I’ve already rewritten them 6 times, and keep changing it as the plugin progresses!)
Yea! Funny – I went through the tutorial you wrote about integrating mal’s with wordpress, but didn’t get quite there. Then I saw your forum post on WP, and came back here! I’m trying it right now – I’ll tell you how it goes! Thank you!
Question: The mal shopping cart still appears in a blank page instead of in the wordpress page? Any way to get around that? Can you add links of where you have used this plugin so we can see it in action?
I’m not quite sure what you mean? You mean that the Mal’s cart (when you check out) shows up in a different page that’s NOT in the WP site? Well yes – that’s how Mal’s works. You can edit the appearance of that page through your Mal’s settings. it doesn’t *stay* on your site – it goes to the Mal’s site (basically) to do the sale, and then will return the end user to yours.
This version of the plugin is actually for testing purposes only. it’s also a bit older – I’ve since been working on it. The original client that this plugin was derived from has asked me NOT to post a link to his site – so that I cannot do. But I *can* show you the “testbed” site where I’m finishing it up: CakeShop. I had to rename it because i guess there’s already software out there called “Simple Cart” – so it’s now renamed to CakeShop. It’s still not finished, but I have a blog up telling you where I’m at and what I’m uncovering as I finish it. Hope that helps