Spruce interactive

Noise

WP e-Commerce and the “Alabama Problem” in Store Receipts

Posted: October 18th, 2012

Author: Ben Heller

Tags:

, , , ,

 Details

If you’ve been reading our blog over the last couple months, you might be aware that we have some experience “improving” (read: “fixing bugs in”) the WP e-Commerce (WPEC) platform. Lately we’ve received a number of inquiries from our clients as to why so many sales receipts read “Alabama” as the state. Could it be that customers are just lazy and are leaving the state dropdown at its default, or is there some deeper issue here? It turns out that WPEC is actually saving the correct data, but for international orders it’s displaying “Alabama” instead of the actual state or region. Very sloppy, WPEC! Let’s take a look at /wp-content/plugins/wp-e-commerce/wpsc-includes/purchaselogs.class.php. On version 3.8.7.4 it’s on line 457, at the start of the wpsc_display_purchlog_buyers_address() function. By default this function reads:

if(is_numeric($purchlogitem->extrainfo->billing_region))
   $state = wpsc_get_region($purchlogitem->extrainfo->billing_region);
else 
   $state = $purchlogitem->userinfo['billingstate']['value'];

It’s this top part that’s pulling the data using wpsc_get_region from the $purchlogitem object. We want to do this only for US orders, and throw all international orders to the ELSE statement. We’ll fix it by narrowing the parameters of their IF statement. Our revised function now reads:

if(is_numeric($purchlogitem->extrainfo->billing_region) && (($purchlogitem->extrainfo->billing_country == 'US')))
   $state = wpsc_get_region($purchlogitem->extrainfo->billing_region);
else 
   $state = $purchlogitem->userinfo['billingstate']['value'];

We now require the billing country to be ‘US’, or the ELSE statement is triggered to pull the state from WPEC’s userinfo object. We’ll be following this up with a post on how to implement this fix as a standalone upgrade (without editing the WPEC core files), but we wanted to share the code so folks can fix this up right now. Remember to leave the global $purchlogitem and return statement at the top and bottom of the function.

  • http://twitter.com/lkbgift Lenny Bogdonoff

    Love your site layout and found you through looking for information about ACF. Would you tell me why you decide to you WPEC? I started using WooCommerce when I was starting on WP development and decided to keep using it. I know the pay to use plugins is a turn off for many, but otherwise, I find it pretty solid. Any thoughts?

    • spruceit

      Hi Lenny, thanks for writing! To be honest, if we could encapsulate our relationship with WPEC as a Facebook status message, it would undoubtedly read “It’s Complicated”. We’ve been using WPEC since 2009, when our clients’ e-commerce needs were much simpler, and the available options were somewhat limited. We design all our themes completely from scratch, and like that WPEC allows us to access functions and hooks for deep customization. Its flaws are of course that it’s incredibly buggy and uses far to many database queries on each page load. However, it’s often the most efficient method for us to achieve advanced e-commerce functionality for clients on a budget. These days we prefer solutions like OpenCart or Magento for straight shopping cart installations, but we’ve grown into such WPEC experts that we turn back to it time and again for WordPress projects. Over the years we’ve patched many of WPEC’s most virulent bugs ourselves, and have developed a small concordance of obscure functions for template development. It’s a situation of “the devil you know versus the devil you don’t”. If someone were to talk us through WooCommerce, I think we could be swayed to at least give it a shot for a few projects. We’ve also been eyeing MarketPress for some time now.

      I hope that at least begins to explain our position, and why we return to WPEC despite its numerous flaws. If you’d like to show us WooCommerce as an alternative, we’d be happy to jump on a join.me session for a feature rundown!

  • Justin Sainton

    Hey guys,

    Glad to see you’re using WPeC and definitely appreciate the “It’s complicated” status. That’s how I began working with WPeC and I’m one of the lead developers for it now :)

    Just wanted to reach out and say that you’re always more than welcome to log these issues and submit patches on our GitHub repo – we’d love to incorporate your contributions!

    • spruceit

      Heya Justin,

      Great to (digitally) meet you! We’d love to help contribute our changes to the codebase. I didn’t fully realize that WPEC was a collaborative effort–has it always been? Looks like the repo is about 2 years old. Despite its flaws, it’s hands down the most flexible e-commerce plugin for WordPress. We’ve built countless sites on it, with all sorts of crazy functionality (recurring billing, membership tiers, alternate payment gateways, specialized reporting tabs, etc.).

      I’d love to hear a bit more about the community of developers currently working on it, and what features or fixes are under way. Our biggest ongoing gripe is how many database queries it runs, especially when add-ons are thrown into the mix. We had one site running 2000 queries per page with the wholesale pricing, membership, and gold cart add-ons, which we finally managed to trim down to 120 by hacking the crap out of a bunch of core files.

      Feel free to get in touch directly at team@spruce.it if you’d like to chat–WPEC is a tool we continue to use, so it’s definitely in our best interests to make it as robust as possible.

Talk to Us

Wise men have said, "All good things must come to an end", and so it was with Spruce. We began our first project in 2006, and completed our last in Fall 2013. It's been a wonderful experience, but now it's time to begin the next adventure.

Though...we wouldn't want to leave you hanging, now would we? Here are our top recommendations for world-class branding, design, and web development:

  • Kristina (KJ) Parish and Beam Collective:
    KJ provided the artistic vision that allowed Spruce to succeed, and we still think she's the greatest designer in the entire world. She's started a new collective with some talented developers, and is covering much the same territory as Spruce--design and development all under one roof, with a caliber of service and professionalism seldom seen in this business or any other. If you like what you see on the Spruce site, then definitely get in touch with KJ at kj@beamcollective.com
  • Permanent Art & Design
    Permanent is a nationally recognized design & branding firm out of Minneapolis, MN. They've been a long term collaborator and strategic partner over the past couple years, and we'd recommend them for medium to large sized businesses/organizations who are serious about putting their best foot forward. In addition to design, Permanent offers strategy and marketing services, plus in-house and networked developers. For more information contact Joseph Belk joseph@permanentadg.com
  • Nate Thompson
    A freelancer, Nate reminds us of ourselves back in the day. Smart, communicative, and skilled, Nate is our recommendation for small to medium sized businesses/organizations who have sites built on Wordpress or other open source content management solutions. With a background in both design and development, he's a one-stop shop for most web-related tasks. You can get in touch at nate.a.thompson@gmail.com
  • Kevin DeBernardi
    Designer turned developer, Kevin is embarking on a freelance web career after working as the in-house designer at the Museum of the City of New York. He's adept at translating his design ideas into custom PHP code, and is constantly expanding his technical palette. Kevin's a good choice for projects that don't quite fit into the Wordpress mold, and that would benefit from a consistency of presence and vision from design through execution. Kevin can be reached at kevin@analoglifestyle.com