Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Per item shipping, then a flat rate...

Per item shipping, then a flat rate...

Locked

Views: 4,203

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
9 Aug 2006, 5:42 AM
#1
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Per item shipping, then a flat rate...

I am wondering what is the best way to implement the following shipping senario.

Currently we have a flat rate of 200 yen per item and for orders over 3,000 yen we have free shipping.

Our shipping company has changed and so we want to eliminate free shipping.

We will continue to charge 200 yen shipping for each item up to a maximum of 500 yen, no matter how many more items are ordered, as the shipping company charges 500 yen no matter how big the order is. (For small items we use the post office, so 200 yen is fine for them...)

What is the best way to do this?

Thanks in advance...

10 Aug 2006, 2:33 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

Customize item.php

When the number of items is >= 3 return 500 ... otherwise, have it do the calculation for you ...

10 Aug 2006, 7:43 AM
#3
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Hi,

Thanks for that suggestion... I checked item.php but could not find anything obvious that I could easily adjust related to item number, so I guess the PHP to achieve this needs to be written from scratch. (or perhaps I am missing something...) I am afraid however, that me writing PHP is not going to happen anytime soon...

I am not sure how to implement ‘have it do the calculation for you...’ I went through the shipping modules but could not find anything that would calculate shipping from the number of items in the order...

I wonder if you could possibly help out with explaining that or adjusting the PHP that I have included below... (or anyone who is up to speed on PHP, for that matter...)

Thank you in advance!

Here is the PHP that was in includes/modules/shipping/


<?php // // +----------------------------------------------------------------------+ // |zen-cart Open Source E-commerce | // +----------------------------------------------------------------------+ // | Copyright (c) 2004 The zen-cart developers | // | | // | <http://www.zen-cart.com/index.php> | // | | // | Portions Copyright (c) 2003 osCommerce | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the GPL license, | // | that is bundled with this package in the file LICENSE, and is | // | available through the world-wide-web at the following url: | // | <http://www.zen-cart.com/license/2_0.txt>. | // | If you did not receive a copy of the zen-cart license and are unable | // | to obtain it through the world-wide-web, please send a note to | // | [[email protected]](mailto:[email protected]) so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // $Id: item.php 1969 2005-09-13 06:57:21Z drbyte $ // class item { var $code, $title, $description, $icon, $enabled; // class constructor function item() { global $order, $db; $this->code = 'item'; $this->title = MODULE_SHIPPING_ITEM_TEXT_TITLE; $this->description = MODULE_SHIPPING_ITEM_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ITEM_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ITEM_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_ITEM_TAX_BASIS; // disable only when entire cart is free shipping if (zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false); } if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_ZONE > 0) ) { $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_ITEM_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while (!$check->EOF) { if ($check->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } $check->MoveNext(); } if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order, $total_count; // adjusted count for free shipping // $total_count = $total_count - $_SESSION['cart']->in_cart_check('product_is_free','1'); // $total_count = $total_count - $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1'); $total_count = $total_count - $_SESSION['cart']->free_shipping_items(); $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY, 'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); return $this->quotes; } function check() { global $db; if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ITEM_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; } function install() { global $db; $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Item Shipping', 'MODULE_SHIPPING_ITEM_STATUS', 'True', 'Do you want to offer per item rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_ITEM_COST', '2.50', 'The shipping cost will be multiplied by the number of items in an order that uses this shipping method.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_ITEM_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_ITEM_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_ITEM_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_ITEM_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_ITEM_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); } function remove() { global $db; $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_SHIPPING_ITEM_STATUS', 'MODULE_SHIPPING_ITEM_COST', 'MODULE_SHIPPING_ITEM_HANDLING', 'MODULE_SHIPPING_ITEM_TAX_CLASS', 'MODULE_SHIPPING_ITEM_TAX_BASIS', 'MODULE_SHIPPING_ITEM_ZONE', 'MODULE_SHIPPING_ITEM_SORT_ORDER'); } } ?>
10 Aug 2006, 7:53 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

This returns the pricing info ...

$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));

You need to test for how many items ... the $total_count just before that code, and when it is >= 3 send 500 vs computed cost ...

11 Aug 2006, 5:09 AM
#5
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Dear Linda,

Thank you for you patience and your time. I have tried my best to adjust that section of PHP but with no success. I went to several PHP tutorial sites and tried to get an understanding of how to do things, but the examples are so different from the code in Zen that I could not make any progress... Whatever I tried I got error messages or parsing errors etc....

If you, or someone, would be so kind as to give me an example that I could try, I might be able to make some headway...

Thank you again!

11 Aug 2006, 11:16 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

The idea is ...

IF count >= 3
charge 500
else
charge normal
endif

So ... you need to alter the code in /includes/modules/item.php to use this IF in place of the normal method ...

      // if total item count >= 3 charge 500 otherwise, charge regular item charge
      if ($total_count >= 3) {
        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                              'methods' => array(array('id' => $this->code,
                                                       'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                       'cost' => 500)));
      } else {
        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                              'methods' => array(array('id' => $this->code,
                                                       'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                       'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));
      }
12 Aug 2006, 12:15 AM
#7
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Well, thank you very much! I must say that I could not have come up with such a piece of code, even with weeks of study, I imagine. Now that I can see the final result, I can understand what you have done, but this was really something beyond me.

I have tested it and it works fine!

One thing that I have yet to figure out is how you developers make a living from all the work you do on Zen-Cart AND the enormous assistance you give everyone. This is the most amazing and helpful community. It is really very Zen! (And I live in Japan, so that is saying something!)

The store that I am building I am doing completely as a volunteer, but I will be sending you a donation out of my own pocket for the wonderful work you are all doing and the marvelous positive assistance you are giving the many small businesses around the world.

Thank you so much!

12 Aug 2006, 1:37 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

The donations that people give to Zen Cart are very important to us ...

While it will be sometime before we "make a living" we hope that others like you understand that for use to build such software and provide the kind of support you need and want to run your businesses ... these donations are important ...

We hope more and more people will come to find that Zen Cart is their e-commerce solution ... and they want to keep it running and developing and have access to the free support ...

Glad that you were able to get the code working for your site! :smile:

12 Aug 2006, 8:10 AM
#9
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Thanks for explaining things to me... I have sent off an donation but there is no need to send me anything, which means more for you hard workers over there!

I am sure I will have some further questions, probably sooner than later...

Once again, thank you for the wonderful support!

12 Aug 2006, 4:06 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

Thanks for the donation ... we really appeciate that ... :yes:

22 Oct 2006, 4:05 PM
#11
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Hello AJeh,

I am not sure when or why, but someone ordered 10 items in our store today, and each item was charged 200 yen!

In the last couple of weeks I upgraded to 1.3.5 so perhaps something needs to be adjusted or perhaps I never noticed it before... I re-read your instructions carefully just now and realized you said... ‘use this IF in place of the normal method ..’

I didn’t actually replace, I added the code to what was already there...

Here is the section of code as it currently is written. Is this correct or must I eliminate some of it? Or is there something else I must do?

Thanks in advance...

  // adjusted count for free shipping

// $total_count = $total_count - $_SESSION['cart']->in_cart_check('product_is_free','1');
// $total_count = $total_count - $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');
$total_count = $total_count - $_SESSION['cart']->free_shipping_items();

  // if total item count >= 3 charge 600 otherwise, charge regular item charge 
  if ($total_count >= 3) { 
    $this->quotes = array('id' => $this->code, 
                          'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE, 
                          'methods' => array(array('id' => $this->code, 
                                                   'title' => MODULE_SHIPPING_ITEM_TEXT_WAY, 
                                                   'cost' => 600))); 
  } else { 

  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                 'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));

  if ($this->tax_class > 0) {
    $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }
28 Oct 2006, 12:00 AM
#12
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Hello!

Have not had any response so I will explain the situation again.

Prior to upgrading to 1.3.6 the shipping was set up in my cart to work with the following parameters:

One item: 200 yen
Two items: 400 yen
Three items or more: 500 yen

With the help of Linda, who wrote the calculation below, I got it to work fine... but now, it no longer functions as it should...

Could someone help out on this?

Thanks!

The calculation that I used/am now using in item.php is:

// if total item count >= 3 charge 500 otherwise, charge regular item charge
if ($total_count >= 3) {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
'cost' => 500)));
} else {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));
}

28 Oct 2006, 1:06 AM
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

I stuck that code in place of the original code:

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                     'cost' => (MODULE_SHIPPING_ITEM_COST * $total_count) + MODULE_SHIPPING_ITEM_HANDLING)));

And works fine ...

Make sure you do not have the original code still in there ...

28 Oct 2006, 3:21 PM
#14
peace_freak avatar

peace_freak

Zen Follower

Join Date:
Apr 2006
Posts:
354
Plugin Contributions:
0

Re: Per item shipping, then a flat rate...

Thanks for getting back to me Linda.

I removed the original code and put in the code you wrote for me earlier...

That did the trick!

Thank you for setting me straight!

28 Oct 2006, 3:22 PM
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Per item shipping, then a flat rate...

Sure thing ... glad you were able to get the custom shipping working again ... :smile: