PDA

View Full Version : Attribute Stock



landshark
10-30-2005, 02:11 AM
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

landshark
11-03-2005, 11:06 PM
nobody else having this problem?

homersbrain
11-04-2005, 08:43 AM
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

landshark
11-04-2005, 08:51 AM
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.

homersbrain
11-04-2005, 10:38 AM
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

homersbrain
11-04-2005, 12:02 PM
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


// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {


After that, add the line

$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)

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


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

landshark
11-05-2005, 04:27 AM
OK first let me say you are AWESOME, got it modified and it all seems to be working like a charm. Thanks again.

homersbrain
11-05-2005, 07:45 AM
Not a problem. 8)

nootkan
11-27-2005, 02:58 PM
homersbrain, I did the same change but my file looks like this:

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? :oops:

jonnyl
06-09-2006, 04:09 PM
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


// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {


After that, add the line

$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)

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


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?

jonnyl
06-13-2006, 11:49 PM
anyone got a solution to this, it's been ages and i still haven't been able to correct it. I've even offered to pay someone to fix it.