osCmax v2.5 User Manual
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Attribute Stock

This is a discussion on Attribute Stock within the osCMax v2 Features Discussion forums, part of the osCmax v2.0 Forums category; I am selling t-shirts and using attribute stock quantities for sizes. Example 20 in Medium, 26 in Large and 26 ...

      
  1. #1
    New Member
    Join Date
    Oct 2005
    Posts
    20
    Rep Power
    0


    Default Attribute Stock

    I am selling t-shirts and using attribute stock quantities for sizes. Example 20 in Medium, 26 in Large and 26 in X-large. When i a shirt is purchased the total quantity in the info window is adjusted but when i go select the stock button i go to the page showing the attribute quantities and nothing has changed.

    How do i go about fixing this, i've tried to search here but come up with nothing.

    Thanks

  2. #2
    New Member
    Join Date
    Oct 2005
    Posts
    20
    Rep Power
    0


    Default RE: Attribute Stock

    nobody else having this problem?

  3. #3
    Lurker
    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0


    Default RE: Attribute Stock

    You may be having the same problem as me.

    I've got a heavily modified oscommerce store (only found oscmax yesterday and am playing with it) and have found that when someone purchases using their credit card (worldpay), the attribute stock is reduced. When someone uses paypal, it's not.

    This is because when the Paypal IPN module returns to the site, it goes to catalog/includes/modules/payment/paypal/checkout_process.php instead of catalog/checkout_process.php (which is the next logical step when paying by cheque for example). You'll need to add the code relating to the attribute stock reduction into one of the paypal files. I've not seriously tried to debug it yet but it's probably checkout_update.php.

    Mike

  4. #4
    New Member
    Join Date
    Oct 2005
    Posts
    20
    Rep Power
    0


    Default RE: Attribute Stock

    Hey Mike, Thanks for the response. That sounds logical and i haven't tested with anything other than paypal so again makes perfect sense. The Coding thing however is beyond my skill level i think, i will see what i can work out. If anyone has any knowledge they can throuw my way it will be greatly appreciated.

  5. #5
    Lurker
    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0


    Default RE: Attribute Stock

    I'm glad I could point you in the right direction. It's a bug I've been meaning to fix for so long. I'm going to put a couple of hours to one side this weekend to sort it out. If I manage to fix it I'll post the fixes here.

    Mike

  6. #6
    Lurker
    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0


    Default RE: Attribute Stock

    I've just done a bit of digging, and the paypal IPN I'm using, and the OSCMax version are two different modules so the files I mentioned above aren't applicable.

    But this one is: /includes/modules/payment/paypal_ipn.php

    You need to add the code in there.

    BACKUP PAYPAL_IPN.PHP BEFORE TRYING THIS.

    Open up /includes/modules/payment/paypal_ipn.php and search for

    Code:
    // Stock Update - Joao Correia
        if (STOCK_LIMITED == 'true') {
    After that, add the line
    Code:
            $products_attributes = $order->products[$i]['attributes'];
    You'll find that same line about 10 lines down. You can remove it from there.

    Next find (a few lines further down)
    Code:
                if (is_array($products_attributes)) {
                    $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
                } 
                $stock_query = tep_db_query($stock_query_raw);
            } else {
    and add after

    Code:
                if (is_array($products_attributes)) {
                    $allspecial = true;
                    $products_stock_attributes_array = array();
                    For($k = 0, $n3 = sizeof($products_attributes); $k < $n3; $k++) {
                        if ($products_attributes[$k]['special'] == 0) {
                            $products_stock_attributes_array[] = $products_attributes[$k]['option_id'] . "-" . $products_attributes[$k]['value_id'];
                            $allspecial = false;
                        }
                    } 
                    if (!$allspecial) {
                      asort($products_stock_attributes_array, SORT_NUMERIC);
                      reset($products_stock_attributes_array);
                      $products_stock_attributes = implode(",", $products_stock_attributes_array);
                      $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                      if (tep_db_num_rows($attributes_stock_query) > 0) {
                          $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);
                          $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];
                          if ($attributes_stock_left < 1) {
                              tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '0' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                              $actual_stock_bought = $attributes_stock_values['products_stock_quantity'];
                          } else {
                              tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                              $actual_stock_bought = $order->products[$i]['qty'];
                          } 
                      } else {
                          $actual_stock_bought = 0;
                      }
                   }  else {
                     $actual_stock_bought = $order->products[$i]['qty'];
                   }
                } else {
                    $actual_stock_bought = $order->products[$i]['qty'];
                }
    That should be it. Save it and give it a go. I've not tested it yet but that's the code I've added into my live site and it works!

    Mike

  7. #7
    New Member
    Join Date
    Oct 2005
    Posts
    20
    Rep Power
    0


    Default RE: Attribute Stock

    OK first let me say you are AWESOME, got it modified and it all seems to be working like a charm. Thanks again.

  8. #8
    Lurker
    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0


    Default RE: Attribute Stock

    Not a problem.

  9. #9
    New Member
    Join Date
    Nov 2005
    Posts
    28
    Rep Power
    0


    Default

    homersbrain, I did the same change but my file looks like this:
    Code:
     if (is_array($products_attributes)) { 
    $allspecial = true; 
    $products_stock_attributes_array = array(); 
    For($k = 0, $n3 = sizeof($products_attributes); $k < $n3; $k++) { 
    if ($products_attributes[$k]['special'] == 0) { 
    $products_stock_attributes_array[] = $products_attributes[$k]['option_id'] . "-" . $products_attributes[$k]['value_id']; 
    $allspecial = false; 
    } 
    } 
    if (!$allspecial) { 
    asort($products_stock_attributes_array, SORT_NUMERIC); 
    reset($products_stock_attributes_array); 
    $products_stock_attributes = implode(",", $products_stock_attributes_array); 
    $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 
    if (tep_db_num_rows($attributes_stock_query) > 0) { 
    $attributes_stock_values = tep_db_fetch_array($attributes_stock_query); 
    $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty']; 
    if ($attributes_stock_left < 1) { 
    tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '0' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 
    $actual_stock_bought = $attributes_stock_values['products_stock_quantity']; 
    } else { 
    tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); 
    $actual_stock_bought = $order->products[$i]['qty']; 
    } 
    } else { 
    $actual_stock_bought = 0; 
    } 
    } else { 
    $actual_stock_bought = $order->products[$i]['qty']; 
    } 
    } else { 
    $actual_stock_bought = $order->products[$i]['qty']; 
    }
    Is this okay or should it look like the rest of the code with normal spaces etc. All I did was copy and paste from your post.
    Nootkan

    Update: I understand why you didn't answer, after reading the first two chapters of Php for the World Wide Web I understand. Oh well before I bought the book I had to ask, if you don't know ask right?

  10. #10
    New Member
    Join Date
    May 2006
    Posts
    14
    Rep Power
    0


    Default Re: RE: Attribute Stock

    Quote Originally Posted by homersbrain
    I've just done a bit of digging, and the paypal IPN I'm using, and the OSCMax version are two different modules so the files I mentioned above aren't applicable.

    But this one is: /includes/modules/payment/paypal_ipn.php

    You need to add the code in there.

    BACKUP PAYPAL_IPN.PHP BEFORE TRYING THIS.

    Open up /includes/modules/payment/paypal_ipn.php and search for

    Code:
    // Stock Update - Joao Correia
        if (STOCK_LIMITED == 'true') {
    After that, add the line
    Code:
            $products_attributes = $order->products[$i]['attributes'];
    You'll find that same line about 10 lines down. You can remove it from there.

    Next find (a few lines further down)
    Code:
                if (is_array($products_attributes)) {
                    $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
                } 
                $stock_query = tep_db_query($stock_query_raw);
            } else {
    and add after

    Code:
                if (is_array($products_attributes)) {
                    $allspecial = true;
                    $products_stock_attributes_array = array();
                    For($k = 0, $n3 = sizeof($products_attributes); $k < $n3; $k++) {
                        if ($products_attributes[$k]['special'] == 0) {
                            $products_stock_attributes_array[] = $products_attributes[$k]['option_id'] . "-" . $products_attributes[$k]['value_id'];
                            $allspecial = false;
                        }
                    } 
                    if (!$allspecial) {
                      asort($products_stock_attributes_array, SORT_NUMERIC);
                      reset($products_stock_attributes_array);
                      $products_stock_attributes = implode(",", $products_stock_attributes_array);
                      $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                      if (tep_db_num_rows($attributes_stock_query) > 0) {
                          $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);
                          $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];
                          if ($attributes_stock_left < 1) {
                              tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '0' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                              $actual_stock_bought = $attributes_stock_values['products_stock_quantity'];
                          } else {
                              tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                              $actual_stock_bought = $order->products[$i]['qty'];
                          } 
                      } else {
                          $actual_stock_bought = 0;
                      }
                   }  else {
                     $actual_stock_bought = $order->products[$i]['qty'];
                   }
                } else {
                    $actual_stock_bought = $order->products[$i]['qty'];
                }
    That should be it. Save it and give it a go. I've not tested it yet but that's the code I've added into my live site and it works!

    Mike


    I've implemented this code change, and now stock(attributes) is updating through the paypal IPN but only if the customer returns to merchant...anybody know a way around this?

Page 1 of 2 12 LastLast

Similar Threads

  1. Needing: Attribute Weight, Hide Price if 0, Actual Attribute
    By crystina in forum osCmax v2 Customization/Mods
    Replies: 0
    Last Post: 11-22-2006, 04:08 PM
  2. Maximum Stock Quantity on Stock Page?
    By Dubious in forum osCMax v2 Features Discussion
    Replies: 0
    Last Post: 08-18-2006, 02:17 PM
  3. Yet another attribute stock question
    By landshark in forum osCMax v2 Features Discussion
    Replies: 6
    Last Post: 01-25-2006, 04:31 AM
  4. Yet another attribute stock level updating question
    By kc_davis in forum osCMax v2 Features Discussion
    Replies: 0
    Last Post: 01-22-2006, 08:50 PM
  5. attribute "out of stock"
    By nootkan in forum osCMax v2 Features Discussion
    Replies: 24
    Last Post: 01-02-2006, 08:17 PM

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
  •