Wednesday, July 29, 2009

OSCommerce hack to faciliate drop shipping

Today I did a little hack job on one of my OSCommerce store fronts.

See, the problem was that I wanted to offer t-shirts on one of my client's sites, but they didn't want to carry inventory off the go. As I'm sure you realize, this is why sites like CafePress and SpreadShirt were created.

Small problem - these sites make you maintain a separate cart. So, if you're selling stuff on your site with full e-commerce capability, then it's bad form to direct the consumer to ANOTHER site to buy another one of your products.

That said, if you're going to take this back-door approach until volume increases, how do you do it and still cover shipping for these products that are shipped separately?

Well, the way I solved it, using an OSCommerce cart, was to modify the flat rate shipping module as follows:


// class constructor
function flat() {
global $order, $cart;

$this->code = 'flat';
$this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
$this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);

$spreadshirtActive = 0;
foreach ($cart->get_products() as $this_product) {
if ( ($this_product['model'] == 'Spreadshirt') && ($spreadshirtActive == 0) ) {
$this->shippingCost = MODULE_SHIPPING_FLAT_COST + 6;
$spreadshirtActive = 1;
} else {
$this->shippingCost = MODULE_SHIPPING_FLAT_COST;
}
}

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
$check_flag = false;
$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while ($check = tep_db_fetch_array($check_query)) {
if ($check['zone_id'] < check_flag =" true;">delivery['zone_id']) {
$check_flag = true;
break;
}
}

if ($check_flag == false) {
$this->enabled = false;
}
}
}

// class methods
function quote($method = '') {
global $order;

$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
'cost' => $this->shippingCost)));

The magic here happens with the 'cost' => portion of the $this->quotes array. $this->shippingCost is set above that to be a function of the products model. This works because I puth the $cart object into this class using the global $cart;...

Now, if some one orders my base product, it's a flat shipping cost. For any other drop shippers which add additional cost to me, I can pass that cost on to the consumer.

I also modified product_info.php to remove the model if statement so the field doesn't get displayed to consumers.

Just a quick little hack that might be useful to you...

No comments: