So your limiting "object" is the yellow shirt correct, not one of the 20ish designs?
Well, normally something like this would/could be addressed through the use of attributes and then you could stick the one object (yellow shirt) into as many categories as you wish, even such that only the "one" applicable design was all that was presented when in a particular category...
Also, as you have found out, zc does not directly support such "master product quantity" tracking without doing what you are describing.
But, that said...
In includes/classes/order.php there is a section of code that is specifically supposed to reduce the stock quantity based on a few factors. If you search for decrement_begin, you should be close to or within that area.
What is being done in this area is to loop through each product that has been purchased and as applicable to adjust the quantity available of that specific product.
In your case, you will want to identify a few things:
1) does this product have the manufacturer's name of interest.
2) if it does, what is the current quantity of stock of my master product?
3) what is the result of the final stock quantity after removing the "child's" stock quantity and set it in the database.
4) have I now run out?
5) if not, keep processing. Unfortunately at this point it is also a little late to tell the customer, thanks for requesting and paying for x items, but we only have x-1. Which means that this type of comparison/review needs to be performed in several other places as well: add-to-cart, shopping_cart, transition to checkout_shipping, checkout_success, etc....
So anyways, the database lookup for say the manufacturer's identifier would be:
Code:
$manufacturer_id = $db->Execute('SELECT p.products_manufacturer FROM ". TABLE_PRODUCTS. " p WHERE p.products_id = ". zen_get_prid($this->products[$i]['id']));
Then you'll need an update to your master product's quantity which you somewhat have already but instead of setting the quantity to the calculated $final_quantity currently obtained in the code, there are a couple of ways you could go: obtain the current total of the master product (by products_id), set a different variable to the difference of the current and purchased amount, then update the product with this new final quantity or could update the quantity such that it equals the current quantity minus the sold quantity.
Anyways, it's an adventurous move, though still has some things to be worked out in order to fully work with a store.
Bookmarks