Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

helpneeder

Archived
  • Posts

    13
  • Joined

  • Last visited

Everything posted by helpneeder

  1. Integrating PayPal Shopping Cart IPN v3.1.5 with QT Pro 4.2 - Revision Several people have messaged me asking about my post on Apr 6 2006, 02:07 PM, post # 832874, saying it is unclear where the changes need to be made. Here is a revised version of my post that shows you more clearly were in the code the changes are (I couldn't see a way to edit or delete the post itself). A few people have asked me if I got my QTPro to work with Paypal IPN. I've only got it to work partially, but I did get stock attribute quantities to decrement, with the help of another user on this forum. I used the steps below, and keep in mind this is when integrating PayPal Shopping Cart IPN v3.1.5 with QT Pro 4.2, and NOT the OsCommerce team's PayPal IPN (though who knows, it may work for that too). What I still have no answer to is how to get the stock attribute quantities to properly increment again if an order is cancelled and "restock" is checked. This is all I can provide, sorry. Please don't message me asking for more because I simply don't have it. FILES AFFECTED: catalog/includes/modules/payment/paypal/classes/osC/Order.class.php catalog/includes/classes/order.php CHANGES TO PAYPAL SHOPPING CART IPN CODE _____________________________________________________________________ _____________________________________________________________________ IN catalog/includes/modules/payment/paypal/classes/osC/Order.class.php _____________________________________________________________________ _____________________________________________________________________ ====================================================================== AROUND LINE 73 (code is similar to checkout_process.php line 111) REPLACE: // Stock Update - Joao Correia if (STOCK_LIMITED == 'true') { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename WITH: // Stock Update - Joao Correia // BEGIN QT PRO/Paypal IPN $products_stock_attributes=null; if (STOCK_LIMITED == 'true') { $products_attributes = $order->products[$i]['attributes']; // if (DOWNLOAD_ENABLED == 'true') { // END QT PRO/Paypal IPN $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename ====================================================================== AROUND LINE 89 (code is similar to checkout_process.php line 130) REPLACE: // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $order->products[$i]['attributes']; WITH: // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop // BEGIN QT PRO/Paypal IPN // $products_attributes = $order->products[$i]['attributes']; // END QT PRO/Paypal IPN ====================================================================== AROUND LINE 96 REPLACE: } else { $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); } if (tep_db_num_rows($stock_query) > 0) { $stock_values = tep_db_fetch_array($stock_query); // do not decrement quantities if products_attributes_filename exists if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) { $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty']; } else { $stock_left = $stock_values['products_quantity']; } tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); } } } WITH: // BEGIN QT PRO/Paypal IPN // } else { // $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); // } // END QT PRO/Paypal IPN if (tep_db_num_rows($stock_query) > 0) { $stock_values = tep_db_fetch_array($stock_query); // BEGIN QT PRO/Paypal IPN $actual_stock_bought = $order->products[$i]['qty']; $download_selected = false; if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) { $download_selected = true; $products_stock_attributes='$$DOWNLOAD$$'; } // If not downloadable and attributes present, adjust attribute stock if (!$download_selected && is_array($products_attributes)) { $all_nonstocked = true; $products_stock_attributes_array = array(); foreach ($products_attributes as $attribute) { if ($attribute['track_stock'] == 1) { $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; $all_nonstocked = false; } } if ($all_nonstocked) { $actual_stock_bought = $order->products[$i]['qty']; } else { asort($products_stock_attributes_array, SORT_NUMERIC); $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']; 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 = ($attributes_stock_left < 1) ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty']; } else { $attributes_stock_left = 0 - $order->products[$i]['qty']; tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')"); $actual_stock_bought = 0; } } } // $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); // } // if (tep_db_num_rows($stock_query) > 0) { // $stock_values = tep_db_fetch_array($stock_query); // do not decrement quantities if products_attributes_filename exists if (!$download_selected) { $stock_left = $stock_values['products_quantity'] - $actual_stock_bought; tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET products_quantity = products_quantity - '" . $actual_stock_bought . "' WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); // END QT PRO/Paypal IPN if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); } } } // BEGIN QT PRO/Paypal IPN } // END QT PRO/Paypal IPN ====================================================================== AROUND LINE 160 AFTER: // Update products_ordered (for bestsellers list) tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); AND BEFORE: //------insert customer choosen option to order-------- ADD: // BEGIN QT PRO/Paypal IPN tep_db_query("update " . TABLE_ORDERS_PRODUCTS . " SET products_stock_attributes = '" . $products_stock_attributes . "' WHERE orders_id = '" . $this->orderID . "' AND orders_products_id = '" . $order->products[i]['orders_products_id'] . "'"); // END QT PRO/Paypal IPN _____________________________________________________________________ _____________________________________________________________________ IN catalog/includes/classes/order.php _____________________________________________________________________ _____________________________________________________________________ ====================================================================== AROUND LINE 149 or possibly 127 (where Paypal Shopping Cart IPN code exists) REPLACE: //begin PayPal_Shopping_Cart_IPN $attributes_query = tep_db_query("select products_options_id, products_options_values_id, products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); //end PayPal_Shopping_Cart_IPN if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], //begin PayPal_Shopping_Cart_IPN 'option_id' => $attributes['products_options_id'], 'value_id' => $attributes['products_options_values_id'], //end PayPal_Shopping_Cart_IPN 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']); WITH: //begin PayPal_Shopping_Cart_IPN // BEGIN QT PRO/Paypal IPN $attributes_query = tep_db_query("select opa.products_options_id, opa.products_options_values_id, opa.products_options, opa.products_options_values, opa.options_values_price, opa.price_prefix, popt.products_options_track_stock from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa, " . TABLE_PRODUCTS_OPTIONS . " popt where opa.orders_id = '" . (int)$order_id . "' and opa.orders_products_id = '" . (int)$orders_products['orders_products_id'] . "' and popt.products_options_id = opa.products_options_id and popt.language_id = '" . (int)$languages_id . "'"); // Old code from above line is on next line: //$attributes_query = tep_db_query("select products_options_id, products_options_values_id, products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); // END QT PRO/Paypal IPN //end PayPal_Shopping_Cart_IPN if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], //begin PayPal_Shopping_Cart_IPN 'option_id' => $attributes['products_options_id'], 'value_id' => $attributes['products_options_values_id'], //end PayPal_Shopping_Cart_IPN // BEGIN QT PRO/Paypal IPN 'track_stock' => $attributes['products_options_track_stock'], // END QT PRO/Paypal IPN 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']);
  2. Integrating PayPal Shopping Cart IPN v3.1.5 with QT Pro 4.2 A few people have asked me if I got my QTPro to work with Paypal IPN. I've only got it to work partially, but I did get stock attribute quantities to decrement, with the help of another user on this forum. I used the steps below, and keep in mind this is when integrating PayPal Shopping Cart IPN v3.1.5 with QT Pro 4.2, and NOT the OsCommerce team's PayPal IPN (though who knows, it may work for that too). What I still have no answer to is how to get the stock attribute quantities to properly increment again if an order is cancelled and "restock" is checked. This is all I can provide, sorry. Please don't message me asking for more because I simply don't have it. FILES AFFECTED: catalog/includes/modules/payment/paypal/classes/osC/Order.class.php catalog/includes/classes/order.php Possibly ??? catalog/ssadmin/includes/functions/general.php (around line 980, function tep_remove_order) CHANGES TO PAYPAL SHOPPING CART IPN CODE _____________________________________________________________________ _____________________________________________________________________ IN catalog/includes/modules/payment/paypal/classes/osC/Order.class.php _____________________________________________________________________ _____________________________________________________________________ ====================================================================== Around line 73 (code is similar to checkout_process.php line 111), add: ====================================================================== //begin QT PRO/Paypal IPN $products_stock_attributes=null; if (STOCK_LIMITED == 'true') { $products_attributes = $order->products[$i]['attributes']; // if (DOWNLOAD_ENABLED == 'true') { //end QT PRO/Paypal IPN ====================================================================== Around line 83 (code is similar to checkout_process.php line 130), add: ====================================================================== 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); if (tep_db_num_rows($stock_query) > 0) { $stock_values = tep_db_fetch_array($stock_query); //begin QT PRO/Paypal IPN $actual_stock_bought = $order->products[$i]['qty']; $download_selected = false; if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) { $download_selected = true; $products_stock_attributes='$$DOWNLOAD$$'; } // If not downloadable and attributes present, adjust attribute stock if (!$download_selected && is_array($products_attributes)) { $all_nonstocked = true; $products_stock_attributes_array = array(); foreach ($products_attributes as $attribute) { if ($attribute['track_stock'] == 1) { $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; $all_nonstocked = false; } } if ($all_nonstocked) { $actual_stock_bought = $order->products[$i]['qty']; } else { asort($products_stock_attributes_array, SORT_NUMERIC); $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']; 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 = ($attributes_stock_left < 1) ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty']; } else { $attributes_stock_left = 0 - $order->products[$i]['qty']; tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')"); $actual_stock_bought = 0; } } } // $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); // } // if (tep_db_num_rows($stock_query) > 0) { // $stock_values = tep_db_fetch_array($stock_query); // do not decrement quantities if products_attributes_filename exists if (!$download_selected) { $stock_left = $stock_values['products_quantity'] - $actual_stock_bought; tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET products_quantity = products_quantity - '" . $actual_stock_bought . "' WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); //end QT PRO/Paypal IPN ====================================================================== Around line 89 (code similar to checkout_process.php line 136), add: ====================================================================== //begin QT PRO/Paypal IPN } //end QT PRO/Paypal IPN ====================================================================== Around line 156, AFTER: // Update products_ordered (for bestsellers list) tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); ADD: //begin QT PRO/Paypal IPN tep_db_query("update " . TABLE_ORDERS_PRODUCTS . " SET products_stock_attributes = '" . $products_stock_attributes . "' WHERE orders_id = '" . $this->orderID . "' AND orders_products_id = '" . $order->products[i]['orders_products_id'] . "'"); //end QT PRO/Paypal IPN _____________________________________________________________________ _____________________________________________________________________ IN catalog/includes/classes/order.php _____________________________________________________________________ _____________________________________________________________________ ====================================================================== Around line 149, where Paypal IPN code exists: ====================================================================== //begin PayPal_Shopping_Cart_IPN //begin QT PRO/Paypal IPN $attributes_query = tep_db_query("select opa.products_options_id, opa.products_options_values_id, opa.products_options, opa.products_options_values, opa.options_values_price, opa.price_prefix, popt.products_options_track_stock from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa, " . TABLE_PRODUCTS_OPTIONS . " popt where opa.orders_id = '" . (int)$order_id . "' and opa.orders_products_id = '" . (int)$orders_products['orders_products_id'] . "' and popt.products_options_id = opa.products_options_id and popt.language_id = '" . (int)$languages_id . "'"); // Old code from above line is on next line: //$attributes_query = tep_db_query("select products_options_id, products_options_values_id, products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); //end QT PRO/Paypal IPN //end PayPal_Shopping_Cart_IPN if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], //begin PayPal_Shopping_Cart_IPN 'option_id' => $attributes['products_options_id'], 'value_id' => $attributes['products_options_values_id'], //end PayPal_Shopping_Cart_IPN //begin QT PRO/Paypal IPN 'track_stock' => $attributes['products_options_track_stock'], //end QT PRO/Paypal IPN 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']); $subindex++;
  3. I've been trying to get help on my issue in the Quantity Tracking Professional and I think I'm halfway toward solution. I've been trying to integrate QT Pro 4.2 along with Paypal Shopping Cart IPN 3.1.5 into my shop but alone they are incompatible, where Paypal orders don't update attribute stock quantities. Have a look at the posts by me and ralphday between #793 and #801: Aug 20 2005, 08:19 PM Post #793 Aug 23 2005, 09:53 PM Post #801 I've been able to get Paypal IPN to subtract the attributes' stock quantities, but I cannot get it to restock them correctly when I delete an order. This may or may not be related to a problem where in the orders_products table of the database, products_stock_attributes is being set to NULL on Paypal orders when it shouldn't be... orders made with Cheques have values that look like '1-4'. Any ideas of how this could be fixed?
  4. It's in there already, actually. Have a look: $orders_products_query = tep_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'"); while ($orders_products = tep_db_fetch_array($orders_products_query)) { $this->products[$index] = array('qty' => $orders_products['products_quantity'], 'id' => $orders_products['products_id'], //begin PayPal_Shopping_Cart_IPN 'orders_products_id' => $orders_products['orders_products_id'], //end PayPal_Shopping_Cart_IPN 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'price' => $orders_products['products_price'], 'final_price' => $orders_products['final_price']); I have another suspicion, probably a novice one, but... although I figure that classes don't need to have 'require's or 'include's in them, I wonder if the QT Pro code inside Order.class.php needs something like this, sort of how checkout_process.php has "include('includes/application_top.php')". Another thing I noticed is, in the Paypal IPN developed by the Oscommerce team, ipn.php has this code at the top: chdir('../../../../'); require('includes/application_top.php'); Note the "chdir". There's nothing like this in the Paypal Shopping Cart IPN code that I've found, even if the php files are buried deep in includes/modules/payment/paypal/(etc...). I wonder if application.top.inc.php or this other version of ipn.php have trouble because of not changing the working directory. Make sense? I just can't figure why the same code would be setting that NULL setting in the database while without going through Paypal IPN it sets a proper value.
  5. That didn't work, and actually it caused another problem where the IPN wasn't being accepted, which I fixed that by adding some extra single-quotes around the order ID and such, but no matter, the stock quantity still isn't being restocked and the products_stock_attributes setting is still NULL in the database. Let me go ahead and show you what I have as my updateProducts function in Order.class.php. Maybe the problem is in there... (pardon the length!): function updateProducts(&$order) { // initialized for the email confirmation $this->products_ordered = ''; $subtotal = 0; $total_tax = 0; for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { // Stock Update - Joao Correia //begin QT PRO/Paypal IPN $products_stock_attributes=null; if (STOCK_LIMITED == 'true') { $products_attributes = $order->products[$i]['attributes']; // if (DOWNLOAD_ENABLED == 'true') { //end QT PRO/Paypal IPN $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa ON p.products_id=pa.products_id LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad ON pa.products_attributes_id=pad.products_attributes_id WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"; // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop //begin QT PRO/Paypal IPN // $products_attributes = $order->products[$i]['attributes']; //end QT PRO/Paypal IPN 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); if (tep_db_num_rows($stock_query) > 0) { $stock_values = tep_db_fetch_array($stock_query); //begin QT PRO/Paypal IPN $actual_stock_bought = $order->products[$i]['qty']; $download_selected = false; if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) { $download_selected = true; $products_stock_attributes='$$DOWNLOAD$$'; } // If not downloadable and attributes present, adjust attribute stock if (!$download_selected && is_array($products_attributes)) { $all_nonstocked = true; $products_stock_attributes_array = array(); foreach ($products_attributes as $attribute) { if ($attribute['track_stock'] == 1) { $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id']; $all_nonstocked = false; } } if ($all_nonstocked) { $actual_stock_bought = $order->products[$i]['qty']; } else { asort($products_stock_attributes_array, SORT_NUMERIC); $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']; 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 = ($attributes_stock_left < 1) ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty']; } else { $attributes_stock_left = 0 - $order->products[$i]['qty']; tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')"); $actual_stock_bought = 0; } } } // $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); // } // if (tep_db_num_rows($stock_query) > 0) { // $stock_values = tep_db_fetch_array($stock_query); // do not decrement quantities if products_attributes_filename exists if (!$download_selected) { $stock_left = $stock_values['products_quantity'] - $actual_stock_bought; tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET products_quantity = products_quantity - '" . $actual_stock_bought . "' WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); //end QT PRO/Paypal IPN if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); } } } //begin QT PRO/Paypal IPN } //end QT PRO/Paypal IPN // Update products_ordered (for bestsellers list) tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); //begin QT PRO/Paypal IPN tep_db_query("update " . TABLE_ORDERS_PRODUCTS . " SET products_stock_attributes = '" . $products_stock_attributes . "' WHERE orders_id = '" . $this->orderID . "' AND orders_products_id = '" . $order->products[i]['orders_products_id'] . "'"); //end QT PRO/Paypal IPN //------insert customer choosen option to order-------- $attributes_exist = '0'; $products_ordered_attributes = ''; if (isset($order->products[$i]['attributes'])) { $attributes_exist = '1'; for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad on pa.products_attributes_id=pad.products_attributes_id where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $this->languageID . "' and poval.language_id = '" . $this->languageID . "'"; $attributes = tep_db_query($attributes_query); } else { $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $this->languageID . "' and poval.language_id = '" . $this->languageID . "'"); } $attributes_values = tep_db_fetch_array($attributes); if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename']) ) { $sql_data_array = array('orders_id' => $this->orderID, 'orders_products_id' => $order->products[$i]['orders_products_id'], 'orders_products_filename' => $attributes_values['products_attributes_filename'], 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 'download_count' => $attributes_values['products_attributes_maxcount']); tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); } $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name']; } } //------insert customer choosen option eof ---- $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']); $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty']; $total_cost += $total_products_price; //$currency_price = $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']); $products_ordered_price = $this->displayPrice($order->products[$i]['final_price'],$order->products[$i]['tax'],$order->products[$i]['qty']); $this->products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $products_ordered_price . $products_ordered_attributes . "\n"; } }
  6. Thanks Ralf, those changes are working so far along with the changes I had made to Order.class.php. When an order is paid for through Paypal IPN, the stock attribute decreases as it should. There is still a problem though; when you want to delete one of these orders from the admin and restock the quantity, the attribute's stock quantity isn't affected, though the main product quantity is increased... so for example if someone had ordered a t-shirt, leaving 9 large and 10 small shirts for a total of 19, and I delete that order while checking the "restock" box, it will still show 9 large and 10 small, but will show a total of 20 shirts in the Product Quantity value. I found that the code that removes orders is in general.php (catalog/admin/includes/functions/general.php) but I don't think the problem is here. I have the feeling that the problem is in how the order is added into the database. I've made two test orders of t-shirts, one Small shirt with Paypal IPN and the other an X-Large shirt with a Cheque, and notice that the attributes for each order are stored slightly differently... In the orders_products table, products_stock_attributes is NULL for the Paypal order, and '1-4' for the Cheque: insert into orders_products (orders_products_id, orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity, products_stock_attributes) values ('292', '199', '69', 'tshirt', 'TEST Shirt', '0.0100', '0.0100', '0.0000', '1', NULL); insert into orders_products (orders_products_id, orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity, products_stock_attributes) values ('293', '200', '69', 'tshirt', 'TEST Shirt', '0.0100', '0.0100', '0.0000', '1', '1-4') Also, in the orders_products_attributes table, products_options_id and products_options_values_id have values of '1' and '7' in the Paypal order, but values of '0' and '0' in the Cheque order: insert into orders_products_attributes (orders_products_attributes_id, orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix, products_options_id, products_options_values_id) values ('65', '199', '292', 'size', 'small', '0.0000', '+', '1', '7'); insert into orders_products_attributes (orders_products_attributes_id, orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix, products_options_id, products_options_values_id) values ('66', '200', '293', 'size', 'x-large', '0.0000', '+', '0', '0'); Where would these differences arise? I know there must be a problem with that NULL value because in the tep_remove_order function of general.php, it skips a big chunk of the QT Pro code if products_stock_attributes is NULL: if (tep_not_null($order['products_stock_attributes'])) ...don't forget, I'm an absolute php beginner here so feel free to dumb down the wording of your reply!
  7. My question has to do with integrating QT Pro 4.2 with Paypal Shopping Cart IPN 3.1.5. I noticed some previous posts about this but no one seemed to figure out how to make attribute stock quantities update when buying things using Paypal IPN. I've been working on Order.class.php (part of Paypal IPN at includes/modules/payment/paypal/classes/osC/) trying to replicate the QT Pro modifications to checkout_process.php, since as is mentioned earlier in this forum, a lot of the code from Order.class.php is taken from checkout_process.php. Most of it is within the function "updateProducts(&$order)". But even with this, the stock quantities aren't being updated when a payment is made, only the main product quanitity is updated. Now, I noticed that the updateProducts function takes a reference of $order, adding an '&' sign to the front so it looks like "updateProducts(&$order)". I know VERY BASIC php programming and don't know how references work, but I wonder if this affects how the rest of the QT Pro code works in this function? I also noticed "$this->" used in various places and wonder if that has to be used in the QT Pro code as well. Any thoughts from the more seasoned php programmers out there? Let me know if you need me to show you the code I've got so far for the updateProducts function.
×
×
  • Create New...