Guest Posted March 4, 2007 Posted March 4, 2007 Hi everyone, I just wanted to hear if anyone has managed to make these two contributions work alongside each other? The problem I'm having is basicly that both contributions modifies how the stock system is working and combining the two includes rewriting the code from one contribt to include the code from another. The QT-pro contribution includes changes to the stock management that allows tracking stock for each of the product variations, while the bundled products creates a 'container' product with various sub-products (that are in fact products) - but where the product variations stock level is not being tracked. For example the general.php file originally looks like this: // function tep_get_products_stock($products_id) { // $products_id = tep_get_prid($products_id); //$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); //$stock_values = tep_db_fetch_array($stock_query); // return $stock_values['products_quantity']; // } While the QT-pro modifications looks like this: //// // Return a product's stock // TABLES: products //++++ QT Pro: Begin Changed code function tep_get_products_stock($products_id, $attributes=array()) { global $languages_id; $products_id = tep_get_prid($products_id); if (sizeof($attributes)>0) { $all_nonstocked = true; $attr_list=''; $options_list=implode(",",array_keys($attributes)); $track_stock_query=tep_db_query("select products_options_id, products_options_track_stock from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id in ($options_list) and language_id= '" . (int)$languages_id . "order by products_options_id'"); while($track_stock_array=tep_db_fetch_array($track_stock_query)) { if ($track_stock_array['products_options_track_stock']) { $attr_list.=$track_stock_array['products_options_id'] . '-' . $attributes[$track_stock_array['products_options_id']] . ','; $all_nonstocked=false; } } $attr_list=substr($attr_list,0,strlen($attr_list)-1); } if ((sizeof($attributes)==0) | ($all_nonstocked)) { $stock_query = tep_db_query("select products_quantity as quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); } else { $stock_query=tep_db_query("select products_stock_quantity as quantity from " . TABLE_PRODUCTS_STOCK . " where products_id='". (int)$products_id . "' and products_stock_attributes='$attr_list'"); } if (tep_db_num_rows($stock_query)>0) { $stock=tep_db_fetch_array($stock_query); $quantity=$stock['quantity']; } else { $quantity = 0; } return $quantity; //++++ QT Pro: End Changed Code } And the bundled products looks like this: //// // Return a product's stock // TABLES: products // function heavily modified for bundle mod function tep_get_products_stock($products_id) { $products_id = tep_get_prid($products_id); //add bundle field to database query $stock_query = tep_db_query("select products_quantity, products_bundle from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); //determine whether product is a bundle $stock_data = tep_db_fetch_array($stock_query); if ($stock_data['products_bundle'] == 'yes') { // order item is a bundle and must be separated $bundle_query = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_quantity, p.products_bundle from " . TABLE_PRODUCTS_BUNDLES . " pb LEFT JOIN " . TABLE_PRODUCTS . " p ON p.products_id=pb.subproduct_id where pb.bundle_id = '" . (int)$products_id . "'"); while ($bundle_data = tep_db_fetch_array($bundle_query)) { if ($bundle_data['products_bundle'] == "yes") { //seperation routine in case there is also a bundle within a bundle $bundle_query_nested = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_quantity, p.products_bundle from " . TABLE_PRODUCTS_BUNDLES . " pb LEFT JOIN " . TABLE_PRODUCTS . " p ON p.products_id=pb.subproduct_id where pb.bundle_id = '" . $bundle_data['subproduct_id'] . "'"); while ($bundle_data_nested = tep_db_fetch_array($bundle_query_nested)) { //generate stock levels string within 2nd level bundle, adding commas between values $stock_bundle .= (int)($bundle_data_nested['products_quantity'] / $bundle_data_nested['subproduct_qty']) . ','; } } else { //generate stock levels string if it is only a 1st level bundle, adding commas between values $stock_bundle .= (int)($bundle_data['products_quantity'] / $bundle_data['subproduct_qty']) . ','; } } //create an array from the stock_bundle string $stock_bundle_array = explode (',', $stock_bundle); //sorts the array in order of stock levels of subproducts sort($stock_bundle_array); //select the smallest subproduct stock value as the stock level of the bundle (first value is null due to way $stock_bundle is made) $stock_values = $stock_bundle_array[1]; } else { //generate stock value for single product $stock_values = $stock_data['products_quantity']; } return $stock_values; } I wanted to know if anyone managed to sort this little problem or even encountered it? The problem seems to be overlaps in checkout_confirmation.php, checkout_process.php and functions/general.php only. Any help or pointers would be greatly appreciated. Regards /Martin Quote
phpConsult Posted July 20, 2012 Posted July 20, 2012 @@JensenDK Did you find a solution meanwhile? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.