Busy weekend, now a busy week
At least, so far it's looking like a busy week ahead. Portions of this post for people in the 'friends' and 'crazy people' group only.
I felt like I didn't stop running at all all weekend long. This was even with taking Friday off from work to do work around the house and try to get caught up with everything. I guess I just stress too much when it comes to actually hosting a party, but I pretty much had to detail clean my house. I was also attempting to bake a vegan cake for the first time ever and that so that was a big project for me, getting all the stuff I needed to make the cake.
Oh, I guess it goes to mention if you're reading this and not my friend on facebook that it was my birthday this past Saturday. I had a party with a theme, which is kind of unusual for me. I don't really do parties at all, I'm bad enough going to a party and trying to be sociable with people let alone trying to host something.
And after that it was just nothing - I ended up just heading home and watching media all night.
Back at work today it was more work on our first real heavy project with eCommerce. We're working on an integration with a point of sale system for a local boutique store. The store carries all sorts of things, and they have a really specific design that calls for a carousel of products on the category and product pages at the bottom of each page that shows related products. In theory concrete 5 eCommerce would be great, it's got a flexible system for attributes that allows us to have a really wide variety of products and present them in a nice graphical system.
The devil turns out to be in the details. They need to integrate with the point of sale system to update their inventories - many items are luxury items and there may only be 2 or 3 in stock at a time and the inventory changes daily. So they want to by syncing up the inventory counts 3 or 4 times a day.
Turns out that's not how the import add on is supposed to be used. What happens when you import the products is that it will delete and re-add any attribute on each product. So the product data and id stays the same but it's attribute ids and attribute value ids all get deleted and recreated. This really wouldn't be a big deal, at least you wouldn't think it's a big deal. I mean, what's the problem if you have all the correct size options and color choices added as attributes and people can choose the ones they want to order then you have a working eCommerce system, right?
The answer is no, you can't do that with eCommerce for concrete 5. The problem comes in the reporting. The reports for your orders are also keyed on that attribute value and needed for order completion. Yet when you import new data and product inventory counts you delete the keys from the database and no longer have any information.
I filed support tickets and the response was basically 'yeah, it won't do that' which is not what we need 2 months into the project. We've been waiting for months on getting proper data out of the point of sale system, and now that we have that we were finding that the entire platform that we were building it on might not be workable. We could maybe change the reporting system to be logs of emails sent so you could read the inventory numbers from there but this seemed unworkable too. It's not a whole lot of time to recode it on another platform but it would be pretty shitty to redo everything at this point in the game because we find out that the platform doesn't support what we need for it to be doing.
So what could I do?
The first thing was that I figured out how to update the product attributes instead of deleting and re-adding them, and then gave that code back to the developer so that he could incorporate it in his add on. But then the customer pointed out that options were showing up that had zero quantity for sale, and wanted these options removed from the list of available options. I tried simply removing them, but again, you lose the index so it was the same problem with reporting.
The answer was pretty clear after a little thinking - extend the select product attribute a little bit. Concrete 5 does offer a very flexible attribute system for keeping track of extra data, and this is exactly the case where a custom attribute type makes the most sense. It wasn't even really that much of a change, really.
The select attribute in concrete 5 is made up of really 3 key parts. There is the attribute itself that displays the form, then there is a list object that lists off options, and then there are option objects. What I need to do is add a simple boolean field for status - on or off. Does this option currently display or not?
So the first part of changing it was to make my own copy of the select attribute and start copying and pasting new database table names in, then changing a few function names and adding a few new functions in the right places and wiff bang boom in a day's worth of programming I had my very own select attribute type that also honors the status of each option, and an import script that verifies the status of each individual option.
From here it's not honestly that far of a step to conceptualize how the core commerce product model could be extended to get inventory counts from a product option and you could have true multi-inventory for concrete 5 eCommerce. But I'm not going to be the guy to program that, I'm way too small time of a programmer to attempt anything crazy like a re-write of eCommerce. I'm just saying if you wanted to do product multi-inventory right, this is how you would want to do it.
I wonder how you could actually get cross-indexed multi-inventory working, that would be really interesting to do with concrete 5's attribute sytsem. You'd have to figure out some way of making a table that joins the two indexes. I don't know... Maybe you'd always be limited to only having single-level attribute/stock qty relationships. I'm sure someone could figure it out. That someone is not me.
Me, I felt pretty good for getting what I did accomplished. It was really tricky to get the product option import working. For some reason the select attribute is built so that at one point in it's saving of the attribute it has to pull in the values from the post array. So I have to fake the whole post array of the select attribute's type form options area in order to make sure that the proper options are saved. I now know way too much about how the select attribute works - it had been a little bit of voodoo sometimes trying to work with it before but now I feel like I really have a pretty good handle on it.
And I have a pretty good handle on csv import of a product database to a live inventory concrete 5 ecommerce installation. That seems like a good skill to have.
Of course it can't just all work, and when I finally went to test everything tonight after working all day on it another error started coming up. The client had tried to define a discount that is a percentage off the order, but left it disabled. When you go to check out on the very first page of the checkout process there are two errors listed, both saying invalid discount. I stepped through it with the debugger and can't figure out why it's throwing the error, I also checked our slightly modified version of eCommerce against the source in meld diff viewer and didn't see any changes that could be related to discounts - I didn't touch anything there or anything in the checkout process. My boss was going to look at it in the morning tomorrow and let me know if anything jumps out to him, hopefully he sees what I can't.
Now that that's done I can get back to the new theme that I was chomping at the bit to get last week. Isn't that always the way? Sitting around waiting for work and then the instant that you get the work some fire starts up with a completely unrelated project that was working just fine that has to be put out right away. They are chomping at the bit to go live with the new site and the product import so it was top priority both Thursday and today. I'm a little nervous to see it actually go live, I hope everything goes smoothly.