BCS Engineering   Your Source for Web and Network Solutions!

Shipping Per Product Install

Note: You should always make a back-up copy of your files and database before installing any modification.

  1. Apply SQL patches:
    Apply the provided sql patch in patch.sql You can also optionally apply the language patch using the Patch sql utility in X-cart to quickly add the new language variables.
  2. Edit shipping/shipping.php
    1. Before:
      if (!$enable_shipping || $config["Shipping"]["realtime_shipping"] != "Y") {

    2. Insert:
      # BCSE begin
      $products_sql="";
      $num_products=0;
      if($products)
      foreach($products as $key=>$cur_product)
      {
      if($key == 0)
      $products_sql.="productid=$cur_product[productid] ";
      else
      $products_sql.="or productid=$cur_product[productid] ";
      $num_products+=1;
      }
      # BCSE End
    3. Find the BLUE code and insert the GREEN code around it:
      if(func_query_first_cell("select value from product_shipping_config where name='product_shipping'")=='N') # BCSE
           $shipping = func_query("SELECT * FROM $sql_tbl[shipping] WHERE active='Y' $destination_condition $weight_condition ORDER BY orderby");
      else # BCSE
           $shipping = func_query("SELECT count($sql_tbl[shipping].shippingid) as total, $sql_tbl[shipping].*,productid FROM $sql_tbl[shipping] left join product_shipping using (shippingid) WHERE $products_sql and active='Y' $destination_condition $weight_condition group BY shippingid having total=$num_products order by orderby"); # BCSE
    4. Find the BLUE code and insert the GREEN code around it:
      if(func_query_first_cell("select value from product_shipping_config where name='product_shipping'")=='N') # BCSE
           $shipping = func_query ("SELECT * FROM $sql_tbl[shipping] WHERE and code='' active='Y' $destination_condition $weight_condition ORDER BY orderby");
      else # BCSE
           $shipping = func_query("SELECT count($sql_tbl[shipping].shippingid) as total, $sql_tbl[shipping].*,productid FROM $sql_tbl[shipping] left join product_shipping using (shippingid) WHERE $products_sql and code='' and active='Y' $destination_condition $weight_condition group BY shippingid having total=$num_products order by orderby"); # BCSE


    5. Find the BLUE code and insert the GREEN code around it:
      if(func_query_first_cell("select value from product_shipping_config where name='product_shipping'")=='N') # BCSE
           $result = func_query_first("SELECT *, '$intershipper_rate[rate]' AS rate, '$intershipper_rate[warning]' AS warning, '$ship_time' AS shipping_time FROM $sql_tbl[shipping] WHERE subcode='$intershipper_rate[methodid]' AND active='Y' $weight_condition ORDER BY orderby");
      else # BCSE
           $result = func_query_first("SELECT count($sql_tbl[shipping].shippingid) as total, $sql_tbl[shipping].*,productid, '$intershipper_rate[rate]' AS rate, '$intershipper_rate[warning]' AS warning, '$ship_time' AS shipping_time FROM $sql_tbl[shipping] left join product_shipping using (shippingid) WHERE $products_sql and subcode='$intershipper_rate[methodid]' AND active='Y' $weight_condition group BY shippingid having total=$num_products order by orderby"); # BCSE


  3. Edit include/product_modify.php
    • Find the following code:
      $status = "modified";
      }

      # For existing product: get the categories list before updating
      if ($product_info) {

    • Insert the following code before the code above:
      # BCSE begin
      if(!empty($change_shipping))
      {
      db_query("delete from product_shipping where productid='$productid'");
      if($products_shipping)
      foreach($products_shipping as $key=>$value)
      db_query("insert into product_shipping (shippingid, productid) values ($value,$productid)");
      }
      # BCSE end

    • Find the following code:
      $taxes = func_query("SELECT $sql_tbl[taxes].*, COUNT($sql_tbl[product_taxes].productid) as selected FROM $sql_tbl[taxes] LEFT JOIN $sql_tbl[product_taxes] ON $sql_tbl[product_taxes].taxid=$sql_tbl[taxes].taxid AND $sql_tbl[product_taxes].productid='$productid' GROUP BY $sql_tbl[taxes].taxid");

      $smarty->assign("taxes", $taxes);

    • Insert the following code before the above code:
      # BCSE begin
      $shipping_methods=func_query("select shippingid, shipping from $sql_tbl[shipping] where active='Y'");
      $current_shipping_methods=func_query("select $sql_tbl[shipping].shippingid, shipping, product_shipping.shippingid as prod_shippingid, productid from $sql_tbl[shipping] left join product_shipping using (shippingid) where productid='$productid'");
      $smarty->assign("shipping_methods",$shipping_methods);
      $smarty->assign("current_shipping_methods",$current_shipping_methods);
      # BCSE end



  4. Edit skin1/main/product_details.tpl
    • Find the following code:
      <TR>
      {if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[shipping_freight]"></TD>{/if}

    • Insert the code below before the code above:

      {* BCSE begin *}
      {if $productids eq ''}
      <tr>
      <td class="FormButton" nowrap valign=top>{$lng.lbl_current} {$lng.lbl_shipping_methods}</td>
      <td class="ProductDetails">
      {section name=idx loop=$current_shipping_methods}
      {$current_shipping_methods[idx].shipping|trademark}<BR>
      {/section}
      </td>
      </tr>
      <tr>
      <td class="FormButton" nowrap>{$lng.lbl_change_shipping}</td>
      <td class="ProductDetails"><input type=checkbox name=change_shipping></td>
      </tr>
      {/if}
      <TR>
      {if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[products_shipping]"></TD>{/if}
      <TD class="FormButton" nowrap valign=top>{$lng.lbl_shipping_methods}</TD>
      <TD class="ProductDetails">
      <SELECT name="products_shipping[]" multiple>
      {section name=shipping_index loop=$shipping_methods}
      <option value="{$shipping_methods[shipping_index].shippingid}" {if $shipping_methods[shipping_index].productid eq $product.productid}selected{/if}>{$shipping_methods[shipping_index].shipping|trademark}</option>
      {/section}
      </SELECT>
      </TD>
      </TR>
      {* BCSE end *}
  5. Edit skin1/common_templates.tpl Add after the first {if} {include} pair
    {elseif $main eq "shipping_per_product"}
    {include file="main/shipping_per_product.tpl"}
  6. Edit skin1/admin/menu.tpl Add before {/capture}:
    <a href="{$catalogs.admin}/shipping_per_product.php" class="VertMenuItems">Shipping Per Product</a>
  7. After uploading the changed files, you can define shipping for each product by modifying the products individually or by using our "Shipping per Product" tool that you will now see in your X-cart admin.


Usage: To use this mod, you need to select atleast 1 shipping method for a product for it to be "shippable". We recommend that you have atleast 1 shipping method in common for all of your products. Otherwise if 2 products are put in the cart and they don't have a common shipping method, then "no shipping methods allowed" message will show up (as expected since they can't ship together).