Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2017
    Location
    bristol
    Posts
    2
    Plugin Contributions
    0

    Default Create Master Product Stock Level For Mulitple Products Code Help :)

    Hi

    I am a novice when it comes to programming but understand the logic to an extent but this piece of code is slightly beyond me.

    We sell variations of the same item under multiple product names and are unable to keep track of stock properly and we have the issue of running out of stock quite often or over ordering.

    To get around this I have created a master item which is marked as out of stock on the website but has the correct stock level.

    What I would like is to have this stock level of this item reduce by the quantity purchased whenever a variation of this item is purchased so for example say I have a yellow T shirt which is printed on with 20 different designs, whenever one of these is purchased the master quantity of my hidden item will reduce.

    I'm looking at editing /includes/classes/order.php

    To link the variation of products I have assigned these to the same manufacture code.

    This is my code which doesn't work as it's not looping over the items in the shopping cart on confirmation of order properly:

    //deduct for master product pid=1389

    $ALLIANCEPINT = 1389;

    if ($manufacturers_name =="ALLIANCE-PINT"){
    $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty'];}
    $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . $ALLIANCEPINT . "'");


    I think i need some more code to query the shopping cart to loop through items and check if the item code has a manufacture code of "ALLIANCEPINT" and then if so reduce the item 1389 which is the product id of the master product i.e the yellow t-shirt..

    Could someone help me with the querys i need... I'm still learning and trying to figure this out and the code i need i'm sure i need some code to loop through $_SESSION['cart'] and pull out the ids and check if it's associated with the manufacturer code and if so deduct master stock.

    Any help kindly appreciated.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Create Master Product Stock Level For Mulitple Products Code Help :)

    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.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. No stock level on certain products
    By sabe in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 1 Aug 2010, 01:37 AM
  2. Common stock level for multiple products
    By Phil020782 in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 6 Mar 2010, 10:04 AM
  3. Stock level indicator, for stock by attributes controller
    By vandiermen in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 13 Nov 2008, 09:49 AM
  4. Mulitple Quantities for One Product
    By rcarlyle in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 23 Mar 2008, 07:24 PM
  5. Code to Get Master Category ID of a Product
    By gems14k in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 23 Dec 2006, 04:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR