Jump to content

gameflier

Members
  • Content count

    1
  • Joined

  • Last visited

  1. gameflier

    Bundled products

    hi all.. sorry my bad english.. here is my problem when I try to install bundled product intergrated with qtpro.. since there are many duplicate codes need to modify on those 2 contributions.. especially in catalog/includes/functions/general.php function tep_get_products_stock($products_id).. can any help me to combine those 2 codes ? thanks osc version: 2.2rc2a bundle product version:1.5.4 qtpro version: 4.51b here is original code // Return a product's stock // TABLES: products 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']; } qtpro code // 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 } bundle product code // BOF Bundled Products //// // 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; } // EOF Bundled Products
×