Trying to build a new module

agtlewis <[email protected]>
Newsgroups gmane.comp.web.oscommerce.devel
Message-ID <f14e29d6332332ca213e751d77b86600@osCommerce-Forums>
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=168047#168047
----------------------------------------------------------------

I am trying to build a shipping module that calculates the shipping method based on the following...

The products table has an added column called products_ship.  If this is set to 1 then the shipping amount is calculated based on the price.  If it is set to 0 then the weight is used.

I wrote the following code which will be wrapped up in function qoute() once it is complete.


[code]
<?php
/*
AVAILABLE VARIABLES
  Name                How Defined
$customer_id        Not Researched

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This code requires dbconn(); which is included and initialized in application_top.php to $connect,
and assumes that the $customer_id variable can be used to retrieve the customers shopping cart
contents from the table customers_basket.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

// calculate the weight of all products in the current customers basket that
// ship by weight
$get_product_id_query = "select products_id, customers_basket_quantity from customers_basket where customers_id='" . $customer_id . "'";
$get_product_id_connect = mysql_query($get_product_id_query, $connect);

// loop through all products in basket
while ($product_ids = mysql_fetch_assoc($get_product_id_connect))
  {
  $n_product_id = $product_ids['products_id'];
  $n_qty = $product_ids['customers_basket_quantity'];
  
  // now that we have the product id lets get the calculation method,
  // item price and weight for the product from the products table
  $get_product_info = "select products_weight, products_price, products_ship from products where products_id='" . $n_product_id . "'";
  $get_product_info_connect = mysql_query($get_product_info, $connect);
  $new_product_info = mysql_fetch_assoc($get_product_info_connect);
  
  $n_product_weight = $new_product_info['products_weight'];
  $n_product_ship = $new_product_info['products_ship'];
  $n_product_price = $new_product_info['products_price'];
  
  // now if product_ship is set to 0 then we DO use weight to calculate shipping for this item
  // otherwise the product shipping price will be calculated based off of the item price
  if ($n_product_ship == 0)
    {
    $n_grand_total_weight = ($n_product_weight * $n_qty) + $n_grand_total_weight;
    }
    else
    {
    $n_grand_total_price = ($n_product_price * $n_qty) + $n_grand_total_price;
    }
  }
  
// we now have $n_grand_total_weight which should be multiplied by a price per pound, and
// $n_grand_total_price which should be multiplied by a percentage

// CODE NEEDS TO BE ADDED HERE TO GET THE SHIPPING PRICE PER POUND AND PRICE PER DOLLAR
// for now we will set it manually

$n_price_per_pound = 2.00;
$n_price_per_dollar = 0.085;

// calculate the total for both weight and price, then add them together
$n_shipping_price_weight = $n_grand_total_weight * $n_price_per_pound;
$n_shipping_price_dollar = $n_grand_total_price * $n_price_per_dollar;

$n_final_shipping_price = round(($n_shipping_price_weight + $n_price_per_dollar),2);
?>

[/code]


Now it's not done so it won't add the tax or anything yet, but while looking at the customers_basket table I discovered that when an item has options select something like 2{4}4{3}7 in the products_id table.  I need to know where the function is that deciphers this (array I am guessing) so that I can either get just the products_id, or use that to calculate the price of the item with the selected options, depending on what products_ship is set at.

A am a little stuck so any help would be appreciated.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.