[DEV] Product Bundle/Clone Stock Control mod'

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Ok... I've got most of the code written now, but I'm very aware that testing this on a live site is a seriously bad idea...

I may just have to go ahead with a backup of the store database and pray! but if someone has a test account setup with 5.0.6 or even the latest 5.5.4 that I can modify and debug on that'd be useful.


Anyway, progress... After a few false starts, rewriting of the structure, adding then removing functions, I've pretty much thrashed out the core code...

As it stands it will now:
(Note: stock/inventory will be referred to as "stock" throughout for ease as it's the same thing)
  • Accept the "Parts" custom field as a string of component product SKU's
  • The sting includes a quantity variable so your "set" can consist of say 10 units of one component (eg: 20xFoo)
    ..or a combination of different products in multiples or singles (eg: 10xFoo + 2xFii + (1)Fum = 1 x fooSet)
  • Sanity checking of the string so that the field can't be used to pollute or inject code
  • Update a product "set" listing stock level according to the availability of component parts
  • Update the component products stock when changes are made to a "set" product (ie: purchase, stock change, etc..)
  • Identify and update stock levels for product listings with the same SKU (clones)
  • Identify "clone" products that have different stock levels (as a further sanity check) and standardise the stock level according to the lowest value. This function also:
    • Adds an error to the stores system log
    • Fires off an email to the inventory manager email address describing the inconsistency, products concerned and the original stock levels
It's important to note that while you can't have a variation that is a "set", you can have component parts that are a variation provided the variation has a SKU (product code).. In fact SKU's are required for this to work...

Still to write (immediate):
  • Check for component status (ie: is a product a component of a set)
  • Update related set product(s) stock when a component product is purchased
  • Sanity check of a "set" parts field to ensure that all SKU's have been entered properly before allowing the "set" product to be saved
  • Mod code to hook into system (relatively simple or should be)
  • Mod code to hide custom field if it is labelled "Parts"
What it will not do:
  • Update set listings whenever an SKU is altered for a component part
  • Provide a neat GUI from which to select the products you wish to include as components (I don't need one but if anyone wants to write one be much guest)
  • Make tea/coffee/breakfast/love-to-your-significant-other... etc...
babyREFLUX
Posts: 337
Joined: Thu Jun 18, 2009 9:38 am

Re: Multi-part product stock control

Post by babyREFLUX »

Martin wrote: Make tea/coffee/breakfast/love-to-your-significant-other... etc...
...and there we have the deal breaker :o
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

babyREFLUX wrote:
Martin wrote: Make tea/coffee/breakfast/love-to-your-significant-other... etc...
...and there we have the deal breaker :o
... the latter one was it Jon? ... My wife would like to point out I can't help with that either :)
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Outstanding Items:
  • Check for component status (ie: is a product a component of a set) [done]
  • Update related set product(s) stock when a component product is purchased [done]
  • Sanity check of a "set" parts field to ensure that all SKU's have been entered properly before allowing the "set" product to be saved
  • Mod code to hook into system (relatively simple or should be)
  • Mod code to hide custom field if it is labelled "Parts"
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Right...
  • Test site setup
  • Initial MOD code implemented in ISC code file
  • Bed!
I'll be returning to this tomorrow morning when my brain is less addled and I've had some sleep... Looking through the code though it should all work pretty darned well and do as expected... which would be nice.. :)
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Oh the joys of debugging..

Not bad code although a bit rough in places and oh {deity} what was I thinking with some of the logic I employed... Luckily nothing too serious and easily resolved..

Anyway, back to the test, fix, test, fix, punch air, test some more, make tea, curse screen, test, fix, test, fix... Blah, blah, blah... ;)
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Well, not managed to quite finish this off but after the day of checking, debugging, fixing, hacking, slashing and generally trying not to cry into cups of tea, etc... I'm very close to having a working solution.

The only part remaining that needs to be tested is when stock changes due to a customer order.

Given that this is really using the exact same code functions used by the admin order page and add/edit product pages, and the hooks couldn't get much simpler, well it should all work fine.


I've had to disable one aspect of the code though which is the initial sanity check that makes sure all the stock levels are the same across single SKU's and associated sets. It was disabled because I couldn't figure a way to stop it firing before an update set had completed across products and to be honest I'm rationalising its removal. After all, anyone installing this mod is going to want to update their stock levels anyway so it'll update to that level then.


It's still not "perfect" but for my purposes it's going to work just fine... although if there's time I'm going to rewrite the whole thing as a class because there's a fair amount of duplication of Queries, etc... which I haven't quite figured out how to remove yet. Ah well...

Anyhoo... bed for me... Christening to attend tomorrow and then schools to support from Monday, so doubtful I'll be back to this before Wednesday.
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Well, I've just finished debugging the code and it's working perfectly (well for me anyway)...

I'm leaving it to mature overnight and I'll probably have a major hack/slash to remove a load of unnecessary junk in due course but version #1 is now complete and works sufficiently for my purposes.

Right... bed for me... Exhausted... :ugeek:
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Multi-part product stock control

Post by Martin »

Ok... I've got a working system up, running and live on my site... Here's the skinny, as posted on the Interspire site:
This is really just an initial post to let folks know that I've developed this and just need to tidy the whole thing up, write documentation and then make it available for sale.

The Problem:
Two of the major problems with Interspires current inventory and stock control system are:
  • The inability to link products so that they share a common inventory/stock value. Instead the current system ignores SKU (stock codes) and you are forced to update multiple listings for the same product.
  • The other missing functionality has been the inability to bundle multiple products into a "set" and track inventory/stock for the component parts without, again long hours manually updating everything.
In both instances the potential for wasted hours and overselling creates a major headache for you the store owner and discourages product listings and bundling that would otherwise increase your sales.


My Solution
The code I've written allows you to use the Stock Code (SKU) values to link products together and create bundled products so that your stock only needs to be updated once for each sale that you make or each time you update your stock levels.

Example #1 (Cloned products)
Canon Compatible ink CLI-8BK is the same ink used in the CLI-221BK cartridge so the stock code is the same, the ink is the same. Until now listing a separate product for each meant having two different products with two different stock levels that didn't interact.

Because both products use the same SKU the mod' automatically updates the stock levels automatically whenever a sale is made or stock is updated for just one of the products.

Note: Variations with the same SKU also work with this.. so if you sell a variation with the same SKU as a single product, both will have their stock levels adjusted together.


Example #2 (Bundled products)
Product Bundle "Cartridge set for the Canon iP4200" has five component products all listed as individual products. Before you would have to keep your bundled product stock separate from your individual product stock tying up potential stock if the bundled product outstrips it's designated inventory and you have to move stock across while updating five individual listings to account for it. Mistake waiting to happen? Oh yes!

Now, with the mod', you use a custom field "Parts" to list the SKU's for each component in a comma separated list. All your physical stock is together (not ringfenced) and you just keep your individual product (ie: individual colour cartridges) stock levels up to date. The mod' handles stock levels by setting the bundled product level to the maximum complete bundles/sets that the individual products can put together.
(eg: 3xBlack, 2xYellow, 5xCyan, 4xMagenta, 1xPhotoBlack = 1 set max).

The mod also updates stock levels for both bundles/sets and individual items, according to what sells. So, if a set sells, each component product gets reduced by one unit and the set stock level also gets reduced.

Likewise if you sell an individual product the available set level is checked and updated... eg: if 2 magenta cartridges were sold the available set stock still remains at 1.. but if the Photo black cart' goes, then the set/bundle stock is updated to zero.

Note: You can have a variation as a component product included in a bundle, but you can't have a variation as a product bundle as it doesn't have the custom field option.

What it doesn't do
It's easy to think this is nirvana for product listings and keeping everything up to date but a few things that need to be noted in terms of limitations:
  1. It doesn't automatically suggest pricing for bundled products
  2. Selecting component products has to be done manually (copy/paste) due to a lack of graphic interface (I simply don't have time)
  3. There are currently no sanity checks that update the values in the "Parts" field if a component products SKU is changed, so editing or deleting a component product used in a Bundled product will break that bundled product
  4. SKU's can only contain alpha-numeric values, full stops, underscore, hypen/dash and colon characters.
  5. SKU's must NOT contain a space either at the beginning or end of the SKU code.
  6. It does display the component product SKU's in the "Additional Information" tab, although a small hack for this could hide the field if needed.
  7. It doesn't allow nesting of product bundles, so you can't have a bundle of bed accessories and then try to add the bed accessories bundle to a bed + accessories bundle. (This functionality may be added in the future)
Perfect?
Well, not really... Perfect would be functionality already built into the Interspire product, complete with GUI... I'm settling for functional with less work overall.


Ultimately I've written this for my own purposes because stock control was driving me completely out of my skull... a GUI would be nice but is not on my list of to-do's as I don't have the knowledge of the ISC GUI code libraries or enough JQuery experience. (If you can/want to tackle this I'm all ears!)


Support
Will be limited to installation and general help. I will maintain the code through successive ISC releases until my maintenance runs out in mid 2011 or Interspire snap out of their current myopia...

Further Development
Will be limited to what I need and what time I have available. Running two businesses, and reprising the roles of Father to a baby boy plus husband to a wonderful/patient wife, my time is seriously limited. I can't (and will not!) make promises but if it makes financial sense and there is sufficient time I will consider polite/constructive suggestions.



I'll be putting together a camtasia demo when I get a bit more time so you can see how it works..

Cost will be £150

Installation will be £20 extra although it's simple enough for anyone with a reasonable text editor to do it.
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: Multi-part product stock control

Post by Tony Barnes »

£150?? :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:















Nah, only messing, for anyone who relies on the stock levels in ISC, this will be a godsend!
Post Reply