Custom Products for MarketPress

Hi All!

I wanted to share with the community a little plugin I designed to allow a product to be 'customized', then added to the cart, then checked-out, and then have those customizations (or personalized products) to be noted on the actual order for fulfillment purposes.

This is by no means, a complete solution there are some pieces left to develop (documented below) that I may tackle in the near future, OR, the Marketpress developers are more than welcome to taylor and "professionalize" for their next releases.

BACKGROUD: (Specifically, why this was developed):
I needed a way to pass information through the marketpress shopping cart and end up on my customers' orders. I only had a small amount of actual products, but each one of them needed to be designated to person. For instance, my customer was buying flowers for "Susan". I needed my customer to specify this person. Now, in my case, i did this progammically and "Susan" was being stored in a $variable on one of my pages- (aka. susan's page). On Susan's page, I had a section that said "products available for Susan" - in this section the user clicked the add-to-cart button next to the flowers they wanted to buy and the checkout process would begin. By design, Marketpress does not currently have the ability to pass any kind of customer chosen/generated input through the shopping cart and then eventually onto the order. You can only add this kind of custom data at the end of the checkout process, which was not applicable, and a-bit clunky for my needs. So... I wrote this plugin that actually clones an existing marketpress product on-the-fly (when the add-to-cart button is clicked) and adds the customized information to the new product. You are welcome to adapt for your specific needs:

MarketPress Custom Products Plugin

IMPORTANT NOTES TO UNDERSTAND:
This plugin works by cloning a product just before the cart is updated, using this newly cloned product you can add custom information to an item. NO CHANGES to the MarketPress plugin need to be made! I use a filter hook on line 2502 to return the new cloned product ID in place of the original.

USAGE / INSTALLATION:
1) place the marketpress_custom_products.php file into a folder and upload it to your plugin's folder within wordpress, activate the plugin from the wordpress admin.
2) modify your wordpress theme/post/page to populate the session variable "$_SESSION['custom_data']" with AJAX prior to the add-to-cart button being clicked.

NOTES:
1) A product will only be cloned if $_SESSION['custom_data'] exists in the current session. (This could be adapted to accept a user input for something like a person's name that will be embroidered onto an hat ... or any other type of custamizable product, but you will most likely need to use AJAX)
2) The cloned product is immediately placed into the trash bin so that it cannot be seen in the front-end (and so there is still a record created).

TODO / KNOWN ISSUES:
1) Create a function to handle inventory adjustments of the cloned products - as of now, inventory is not adjusted at all.
2) Create new a post_status specifically for custom products instead of using the 'trash', OR, marketpress developers can create a custom post type just for custom products for future releases, or they can dream up a better solution all together! :slight_smile:

We would love to hear your specific needs and feedback! If you need help implementing, we will try our best to help.

PS: This tread talks much about MarketPress handling of Customized products prior to checkout.
AND this thread was where this little plugin all started! BIG thanks @PaulM and @Aaron and the rest of the WPMU Dev team!

  • aecnu
    • WP Unicorn

    Greetings Sean,

    Thank you for this great contribution to the WPMU Dev Community, it is certainly appreciated.

    I will let the lead developer of Market Press know about your coding/plugin to see if he may have any suggestions or improvements to offer.

    I will also let this ticket float awhile for members to comment on as you have requested We would love to hear your specific needs and feedback! If you need help implementing, we will try our best to help.

    Thank you for being a WPMU Dev Member!

    Cheers, Joe

  • Sean Johnson
    • Site Builder, Child of Zeus

    Hi Aaron,

    Cool stuff, but have you taken a look at 2.6+? One of the main feature additions was per-product customization/personalization, it's pretty powerful.

    Yes. I've only used 2.6, and believe I have the latest version. Is there a better way implement customizations prior to adding-to-cart? The only purpose for this additional plugin is to allow users to supply custom information prior to adding an item to the cart.

    Please let me know if you know of a better way to implement this kind of functionality!

  • Dean Kaus
    • The Bug Hunter

    Hi @Sean Johnson I believe I had requested this as well as others in another thread when 2.6 came out. It's just easier and makes more sense to add the custom content as you select the item to add to the cart. If you have to add this information when your checking out it doesn't make as much sense and tends to have people either remove items from the cart or abandon the order all together.

    I haven't had a chance to try out your plugin as I'm hoping that we can get all of these features as well as some others enclosed with Marketpress. ultimately making Marketpress the all in one best e-commerce solution out there.

  • nick_denitto
    • New Recruit

    @Aaron this is bananas... it seems like it would be easy (and definitely necessary for a real store) to add variation drop downs to products via custom fields. I was hoping that Sean's plugin would work for what I need, but there's no way. I'm basically recreating this store for a client:

    http://www.marysiaswimstore.com/

    If you look at a product page, there are two dropdowns: one for color and one for size. If I could suggest what I feel like would be a relatively simple solution, you should allow customers to create custom field keys (size or color for example) and then parse the array for each variation (size => x-small, small, medium, large) on the product page and create a drop down. I mean, either that or allowing the creation of a super-product which combines simple products into one product page with drop downs to select variations. Are you familiar with how Magento handles products? I just mean from an organizational standpoint.

  • Sean Johnson
    • Site Builder, Child of Zeus

    @nick_denitto,

    I agree, it could be simple if Aaron (and other wpmu dev's) changed the way the shopping cart is built (unfortunately, that is not so simple - or I would have done it). The main problem with MarketPress's shopping cart is that it split into two: a simple array that builds a multidimensional (a small "$cart" that builds the "$full_cart")...

    If the cart would simply be built as ONE multidimensional array, then all of these custom product and multiple variation problems could be solved - or at least extended by developers/users.

    Unfortunately, I could not wait for this to be implemented by wpmu dev's and I cannot risk "hacking" the shopping cart, or taking the time to rebuilt it. So, I built this plugin to extend marketpress to meet my needs, unobtrusively, so I can benefit from future upgrades.

    Later this week, I will change this plugin to clone the products to a custom post type called something like "Custom Ordered Products" - this will eliminate the clunky trash bin junk (sorry, I was in a rush). This will also be very friendly and easy to implement for those using the CustomPress plugin.

    Nick, until wpmudev modifies their shopping cart to be one multidimensional array, the only way you would be able to accomplish this now would be to create a couple custom fields on your products to hold the size and color options, and then write a couple functions to display these options to be chosen by the user and then store/send these values to my plugin for a product to be cloned/modified with the chosen product variations.

    I wish there was a better option to my product cloning method, but besides re-writing the entire shopping cart, there no way... The cloning method works, but is by no means ideal.

    If you need some help implementing my plugin, I will try my best to help.

  • Sean Johnson
    • Site Builder, Child of Zeus

    @nick_denitto,

    Also, in regards to your comment about Magento and product organization. Unfortunately, I have not come across any wordpress shopping cart that organizes products effectively. This is because all the plugin developers keep trying to make a blog into an e-commerce engine.

    IMHO, they all need to abandon tying every product to it's own post. It could be much more powerful if they put the product fields back into database tables directly, then created vanilla page templates that pulled those fields dynamically. This would allow the plugin to be less of a blog plugin and more of a REAL e-commerce engine.

    Again, unfortunately, this is a huge undertaking and I don't think anyone is pursuing this approach.

  • Dean Kaus
    • The Bug Hunter

    Well said @Sean Johnson When I first joined WPMU Dev and first started using wordpress was due to a referral from another Wordpress Theme that seemed to fall short in the e-commerce department. Many years ago back in the x-base and dbase programming methods things seemed to be much more clear and seemed much easier to either program from scratch or modify to suit your needs.

    When I signed up originally back in December or so was so I could have more options available than what came with my theme. So after installing Marketpress (which was a huge improvement) I started looking into seeing what I could do to customize it for my personal store. Only problem was I couldn't find the database. That's when I discovered that WP and their themes, plugins etc... were a total different animal than I was accustomed to.

    I've learned a lot since I've joined here but still have a long way to go.

    One of the things that really puzzles me here, especially with Marketpress is the lack of compatibility with (not only premium themes purchased elsewhere) the majority of the themes that are available on this site.

    Seems like you have to add custom CSS so you can see certain things like the text within a box or header of shopping cart item descriptions etc...

    Personally I think that like many of the premium themes out there that offer a simple way to change the themes color scheme and style, that Marketpress should also offer similar options as well. This way we don't have to spend hours manually searching for the box or text color that needs to be changed. In addition I've ran into the problem where I've found the code to change the color only to find out that some of the box's that appear elsewhere in the cart or on other pages change and are unreadable. So it's almost like being in a catch 22 hell here.

    Even if market press (and maybe I'm missing something in the settings somewhere) had a CSS for Dark based Themes and one for Light based themes would be a big improvement.

    Again I agree with your concept that the e-commerce should be treated not as posts but as an actual shopping cart would greatly improve the functionality of MarketPress.

  • Dean Kaus
    • The Bug Hunter

    @Sean Johnson I just thought of a perfect example of how sometimes changes don't work globally. Not sure if the reason is that when a couple of the products (or I guess actually a post) were added before the CSS was changed or After. I don't recall, I ended up getting sick and back in the hospital so never got back to this problem. That's the other reason I switched over to the WP style pages is so I could have other people update content without having to know how to program. hasn't been the case so far.

    Anyway here's the screen shot. Hopefully @Aaron is rested up and getting back into the groove and some of your suggestions as well as others will be taken into consideration.

  • Kerstin
    • WPMU DEV Initiate

    @Sean Johnson

    I am trying to implement your plugin, but I have no clue what you mean by

    2) modify your wordpress theme/post/page to populate the session variable "$_SESSION['custom_data']" with AJAX prior to the add-to-cart button being clicked.

    Could you possibly help me understand how to implement this, please?

    Thanks,
    Kerstin

  • MELONPUP
    • Design Lord, Child of Thor

    Hi Sean,

    I just wanted to say a huge Thank You for this plugin, it has really helped me out :slight_smile:

    You will see my issue that it has helped resolve over at this thread :slight_smile:

    If there is any chance you could have a look at the above thread, I have a few questions, that I would really appreciate your feedback on :slight_smile:

    Once again, thank you :slight_smile:

    Regards,
    Chrystopher

  • aecnu
    • WP Unicorn

    Greetings Chrystopher,

    Happy that you found this plugin to include choosing to use it and I have joined you in the other ticket to follow along with you folks to see what the final outcome is and if it is ready for prime time so to speak.

    Thank you Sean once again for this contribution.

    Thank you both for being WPMU Dev Community members!

    Cheers, Joe

  • karks88
    • Site Builder, Child of Zeus

    Is there a tutorial anywhere to explain exactly how to do this part?

    2) modify your wordpress theme/post/page to populate the session variable "$_SESSION['custom_data']" with AJAX prior to the add-to-cart button being clicked.

  • Sean Johnson
    • Site Builder, Child of Zeus

    @karks88, Sorry, I don't have instructions for this at the moment. Let me see what I can do.

    Do you need specific instructions on how to use AJAX in Wordpress? Or, would you just need an example of how to trigger an ajax event in the DOM?

  • karks88
    • Site Builder, Child of Zeus

    @Sean Thanks for your reply! I'm kind of green when it comes to AJAX. I guess if there were a sample template I could go off of, that would really help. I know that I can hack away at it until it does what I want, haha :slight_smile:

  • Sean Johnson
    • Site Builder, Child of Zeus

    I will be travelling tomorrow, but if I get enough time tonight, I will actually update the plugin shell to 0.0.3 and include everything you need to use AJAX in Wordpress easily. I will include an example use of grabbing the custom data from an input and setting it into the $_SESSION variable when the user clicks on the 'add to cart' button.

    I do apologize for not updating this plugin for a while; I've been very busy with other projects.

  • karks88
    • Site Builder, Child of Zeus

    That is so awesome, thank you! No worries about not updating the plugin, I just found it today :slight_smile:

    I really do like a lot of things about MarketPress, but having this functionality would really be a big plus.

  • Sean Johnson
    • Site Builder, Child of Zeus

    ATTENTION:
    Here is the latest version of the plugin - 0.0.3 (Still needs some work done to fix some holes. Also some of the code is still messy and redundant from when I was developing.)

    This latest version adds a custom data field next to the 'add to cart' button. When the button is clicked, a new product is created on the fly with the custom data in the title and also in post meta. The code should be pretty straightforward, but if anyone has any questions, just leave a comment.

    When I have more time, I will be addressing all the 'TODO' items listed inside the plugin file. I will post each new version on this thread.

  • MELONPUP
    • Design Lord, Child of Thor

    Hi All,

    Sorry for bumping this thread as well, as I have just updated this one, but I just wanted to let you know that the above link to the latest version is still the 0.0.2 and not 0.0.3.

    Also to let you know that you may experience an issue whilst using a Child Theme (or in particular GridMarket). I may also be wrong of course, as I believe it might be to do with how you are setting your $_SESSION variables. I have it working successfully with SimpleMarket and FrameMarket.

    If you have it working with GridMarket and or with AJAX (I'm currently only using Forms), I would really appreciate hearing from you.

    Thank you in advance.

    Regards,
    Chrystopher

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.