Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Free shipping issue


Peper

Recommended Posts

Need help with the free shipping in 2.3.4 edge

I added store pickup and another for customer to use his own courier for collecting orders

 

However the free shipping takes priority over these other 2 shipping methods and customer can only proceed with free shipping option

How to force the other 2 shipping modules to show??

Getting the Phoenix off the ground

Link to comment
Share on other sites

Hello Pierre @@Peper,

 

In Admin => Modules => Order Total => Shipping => Set: "Allow Free Shipping" to "false"

Link to comment
Share on other sites

Thanks Raiwa @@raiwa

 

Put it this way, Free shipping option still needs to show along with other shipping options.

This is to allow local customers to collect from store and some ie wants to send their own courier overnight delivery which is not covered for economical free shipping

 

My current store 2.2 I somehow got it to work:

http://i63.tinypic.com/sdnwp1.jpg

Getting the Phoenix off the ground

Link to comment
Share on other sites

Hello Pierre @@Peper,

 

You can use the flat rate shipping module, just rename the title and set the shipping cost to zero.

If you need more options try this:

http://addons.oscommerce.com/info/164

 

regards

Rainer

Link to comment
Share on other sites

Hi Raiwa @@raiwa

 

Got this eventually sorted and seems fine so far.

Let me explain briefly how to for others with same req.

 

In oscommerce ver 2.3.4 edge the free shipping is already installed, however basic.(add maybe weight and so restrictions)

So I added a shipping module from 2.2 - http://addons.oscommerce.com/info/146/v,22 and installed as another shipping module but only added the shipping files - no code changes

Setup both Free shipping in admin - modules order total and shipping

 

Changed code in catalog/checkout_shipping.php to below

 

This is somewhat brutal but works, I'm sure the developers might have a look and redesign

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');
  require('includes/classes/http_client.php');

// if the customer is not logged on, redirect them to the login page
  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

// if there is nothing in the customers cart, redirect them to the shopping cart page
  if ($cart->count_contents() < 1) {
    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  }

// if no shipping destination address was selected, use the customers own address as default
  if (!tep_session_is_registered('sendto')) {
    tep_session_register('sendto');
    $sendto = $customer_default_shipping_address_id;
  } else {
// verify the selected shipping address
    if ( (is_array($sendto) && empty($sendto)) || is_numeric($sendto) ) {
      $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'");
      $check_address = tep_db_fetch_array($check_address_query);

      if ($check_address['total'] != '1') {
        $sendto = $customer_default_shipping_address_id;
        if (tep_session_is_registered('shipping')) tep_session_unregister('shipping');
      }
    }
  }

//session to use for shipping insurance
  $_SESSION['choose_insurance'] = $_POST[choose_insurance];

  require(DIR_WS_CLASSES . 'order.php');
  $order = new order;

// register a random ID in the session to check throughout the checkout procedure
// against alterations in the shopping cart contents
  if (!tep_session_is_registered('cartID')) {
    tep_session_register('cartID');
  } elseif (($cartID != $cart->cartID) && tep_session_is_registered('shipping')) {
    tep_session_unregister('shipping');
  }

  $cartID = $cart->cartID = $cart->generate_cart_id();

// if the order contains only virtual products, forward the customer to the billing page as
// a shipping address is not needed
  if ($order->content_type == 'virtual') {
    if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
    $shipping = false;
    $sendto = false;
    tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  }

  $total_weight = $cart->show_weight();
  $total_count = $cart->count_contents();

// load all enabled shipping modules
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping;

  if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
    $pass = false;

    switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
      case 'national':
        if ($order->delivery['country_id'] == STORE_COUNTRY) {
          $pass = true;
        }
        break;
      case 'international':
        if ($order->delivery['country_id'] != STORE_COUNTRY) {
          $pass = true;
        }
        break;
      case 'both':
        $pass = true;
        break;
    }

    $free_shipping = false;

   if ( ($pass == true) && ($cart->show_total() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {

	 $free_shipping = true;

      include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
    }
  } else {
    $free_shipping = false;
  }

// process the selected shipping method
  if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken) ) {
    if (!tep_session_is_registered('comments')) tep_session_register('comments');
    if (tep_not_null($HTTP_POST_VARS['comments'])) {
      $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
    }

    if (!tep_session_is_registered('shipping')) tep_session_register('shipping');

    if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
      if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) {
        $shipping = $HTTP_POST_VARS['shipping'];

        list($module, $method) = explode('_', $shipping);
        if ( is_object($$module) || ($shipping == 'free_free') ) {
          if ($shipping == 'free_free') {
            $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
            $quote[0]['methods'][0]['cost'] = '0';
          } else {
            $quote = $shipping_modules->quote($method, $module);
          }
          if (isset($quote['error'])) {
            tep_session_unregister('shipping');
          } else {
            if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
              $shipping = array('id' => $shipping,
                                'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
                                'cost' => $quote[0]['methods'][0]['cost']);

              tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
            }
          }
        } else {
          tep_session_unregister('shipping');
        }
      }
    } else {
      if ( defined('SHIPPING_ALLOW_UNDEFINED_ZONES') && (SHIPPING_ALLOW_UNDEFINED_ZONES == 'False') ) {
        tep_session_unregister('shipping');
      } else {
        $shipping = false;
        tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
      }
    }
  }

// get all available shipping quotes
  $quotes = $shipping_modules->quote();

// if no shipping method has been selected, automatically select the cheapest method.
// if the modules status was changed when none were available, to save on implementing
// a javascript force-selection method, also automatically select the cheapest shipping
// method if more than one module is now enabled
  if ( !tep_session_is_registered('shipping') || ( tep_session_is_registered('shipping') && ($shipping == false) && (tep_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest();

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING);

  if ( defined('SHIPPING_ALLOW_UNDEFINED_ZONES') && (SHIPPING_ALLOW_UNDEFINED_ZONES == 'False') && !    tep_session_is_registered('shipping') && ($shipping == false) ) {
  $messageStack->add_session('checkout_address', ERROR_NO_SHIPPING_AVAILABLE_TO_SHIPPING_ADDRESS);
  tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL'));
}

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<div class="page-header">
  <h1><?php echo HEADING_TITLE; ?></h1>
</div>

<?php echo tep_draw_form('checkout_address', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', 'class="form-horizontal"', true) . tep_draw_hidden_field('action', 'process'); ?>

<div class="contentContainer">
  <h2><?php echo TABLE_HEADING_SHIPPING_ADDRESS; ?></h2>

  <div class="contentText row">
    <div class="col-sm-8">
      <div class="alert alert-warning">
        <?php echo TEXT_CHOOSE_SHIPPING_DESTINATION; ?>
        <div class="clearfix"></div>
        <div class="pull-right">
          <?php echo tep_draw_button(IMAGE_BUTTON_CHANGE_ADDRESS, 'fa fa-home', tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL')); ?>
        </div>
        <div class="clearfix"></div>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="panel panel-primary">
        <div class="panel-heading"><?php echo TITLE_SHIPPING_ADDRESS; ?></div>
        <div class="panel-body">
          <?php echo tep_address_label($customer_id, $sendto, true, ' ', '<br />'); ?>
        </div>
      </div>
    </div>
  </div>

  <div class="clearfix"></div>

<?php
  if (tep_count_shipping_modules() > 0) {
?>

  <h2><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></h2>

<?php
    if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {
?>

  <div class="contentText">
    <div class="alert alert-warning">
      <div class="row">
        <div class="col-xs-8">
          <?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?>
        </div>
        <div class="col-xs-4 text-right">
          <?php echo '<strong>' . TITLE_PLEASE_SELECT . '</strong>'; ?>
        </div>
      </div>
    </div>
  </div>

<?php
    } elseif ($free_shipping == false) {
?>

  <div class="contentText">
    <div class="alert alert-info"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></div>
  </div>

<?php
    }
?>

  <div class="contentText">
    <table class="table table-striped table-condensed table-hover">
      <tbody>

<?php
    if ($free_shipping == true) {
?>

    <div class="contentText">
      <div class="panel panel-success">
        <div class="panel-heading"><strong><?php echo FREE_SHIPPING_TITLE; ?></strong> <?php echo $quotes[$i]['icon']; ?></div>
        <div class="panel-body">
          <?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . tep_draw_hidden_field('shipping', 'free_free'); ?>
        </div>
      </div>
    </div>

<?php
//    } else {
//      $radio_buttons = 0;
	}
      $radio_buttons = 1;
// SHOW FREE SHIPPING + MODULES END
      for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
          for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
// set the radio button to be checked if it is the method chosen
          $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id']) ? true : false);         

?>
      <tr class="table-selection">
        <td>
          <strong><?php echo $quotes[$i]['module']; ?></strong>
          <?php
          if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) echo ' ' . $quotes[$i]['icon'];
          ?>

          <?php
          if (isset($quotes[$i]['error'])) {
            echo '<div class="help-block">' . $quotes[$i]['error'] . '</div>';
          }
          ?>

          <?php
          if (tep_not_null($quotes[$i]['methods'][$j]['title'])) echo '<div class="help-block">' . $quotes[$i]['methods'][$j]['title'] . '</div>';
          ?>
          </td>

<?php
            if ( ($n > 1) || ($n2 > 1) ) {
?>

        <td align="right">
          <?php
          if (isset($quotes[$i]['error'])) {
            // nothing
            echo ' ';
          }
          else {
            echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?>  <?php echo tep_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'required aria-required="true"');
          }
          ?>
        </td>

<?php
            } else {
?>

        <td align="right"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></td>

<?php
            }
?>
      </tr>
<?php
      }
    }
?>

      </tbody>
    </table>
  </div>

<?php
  }
?>
<?php
// BEGIN Shipping Insurance 3.0 with customer choice
if (($order->info['subtotal'] >= MODULE_ORDER_TOTAL_INSURANCE_OVER) && (MODULE_ORDER_TOTAL_INSURANCE_STATUS == 'true') && (MODULE_ORDER_TOTAL_INSURANCE_USE == 'true')) {
	if ($order->delivery['country_id'] == STORE_COUNTRY) {
		if (MODULE_ORDER_TOTAL_INSURANCE_INCREMENT > 0) {
			$how_often = ceil(($order->info['subtotal'] - MODULE_ORDER_TOTAL_INSURANCE_OVER)/MODULE_ORDER_TOTAL_INSURANCE_INCREMENT);
		} else {
			$how_often = 0;
		}
		$this_amount = MODULE_ORDER_TOTAL_INSURANCE_BASE + (MODULE_ORDER_TOTAL_INSURANCE_FEE * $how_often);
		if ($this_amount < MODULE_ORDER_TOTAL_INSURANCE_MIN_CHARGE ) {
			$this_amount = MODULE_ORDER_TOTAL_INSURANCE_MIN_CHARGE;
		}

	}

	if ($order->delivery['country_id'] != STORE_COUNTRY) {
		if (MODULE_ORDER_TOTAL_INTL_INSURANCE_INCREMENT > 0) {
			$how_often = ceil(($order->info['subtotal'] - MODULE_ORDER_TOTAL_INTL_INSURANCE_OVER)/MODULE_ORDER_TOTAL_INTL_INSURANCE_INCREMENT);
		} else {
			$how_often = 0;
		}
		$this_amount = MODULE_ORDER_TOTAL_INTL_INSURANCE_BASE + (MODULE_ORDER_TOTAL_INTL_INSURANCE_FEE * $how_often);
		if ($this_amount < MODULE_ORDER_TOTAL_INTL_INSURANCE_MIN_CHARGE ) {
			$this_amount = MODULE_ORDER_TOTAL_INTL_INSURANCE_MIN_CHARGE;
		}
	}
?>

    <div class="contentText">
      <div class="panel panel-success">
        <div class="panel-heading"><strong><?php echo TEXT_SHIPPING_INSURANCE_TITLE; ?><div align="right">Unselect if not required            <input type="checkbox" name="choose_insurance" value="1" checked></strong></div><?php echo TEXT_SHIPPING_INSURANCE_CHOICE; echo $currencies->format($this_amount); ?>?<br /><span class="smallText"><?php echo TEXT_SHIPPING_INSURANCE_DISCLAIMER; ?></div>
              </div>
    </div>
<?php
}
// END Shipping Insurance 3.0 with customer choice
?>

  <hr>

  <div class="contentText">
    <div class="form-group">
      <label for="inputComments" class="control-label col-sm-4"><?php echo TABLE_HEADING_COMMENTS; ?></label>
      <div class="col-sm-8">
	   <?php
        echo tep_draw_textarea_field('comments', 'soft', 60, 5, $comments, 'id="inputComments" placeholder="' . TABLE_HEADING_COMMENTS . '"');
        ?>
      </div>
    </div>
  </div>

  <div class="buttonSet">
    <div class="text-right"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'fa fa-angle-right', null, 'primary', null, 'btn-success'); ?></div>
  </div>
  
  <div class="clearfix"></div>

  <div class="contentText">
    <div class="stepwizard">
      <div class="stepwizard-row">
        <div class="stepwizard-step">
          <button type="button" class="btn btn-primary btn-circle">1</button>
          <p><?php echo CHECKOUT_BAR_DELIVERY; ?></p>
        </div>
        <div class="stepwizard-step">
          <button type="button" class="btn btn-default btn-circle" disabled="disabled">2</button>
          <p><?php echo CHECKOUT_BAR_PAYMENT; ?></p>
        </div>
        <div class="stepwizard-step">
          <button type="button" class="btn btn-default btn-circle" disabled="disabled">3</button>
          <p><?php echo CHECKOUT_BAR_CONFIRMATION; ?></p>
        </div>
      </div>
    </div>
  </div>

</div>

</form>

<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Result:

http://i64.tinypic.com/312hd2d.jpg

Getting the Phoenix off the ground

Link to comment
Share on other sites

@@Peper,

 

If it's good for you, ok. But in general terms it is not good to need to apply changes in core files. For sure you'll find a store pickup and free shipping module which allows to do what you wish without the need to apply changes in checkout_shipping.php.

Your fix is also problematic if PayPal express checkout is used, you would need to modify the pay pal express module too.

 

regards

Rainer

Link to comment
Share on other sites

@@Peper,

 

I forgot to mention: if you add a shipping estimator module or any other add-on which uses shipping modules, you'll have to apply the modifications there too.

Also to say that if you one day need to update your store/add-ons the modifications will give you extra job, not to mention if you "forget" to apply them again to replaced files.

Because of all of this it is much more recommended to realize it without core file changes. If you do it with the apropiate shipping modules, you'll do it once and it will work everywhere and forever. :)

 

regards

Rainer

Link to comment
Share on other sites

Hey Raiwa @@raiwa

 

Thanks, but I'm no serious programmer here(basic google been best friend since 2008 until you hit your own unanswered questions)

Please let me know more detail into this, I could not find a better or to say any other solution but to change core file.

Was stuck a few days on this. Adding the store pickup(already installed) was not a solution as the built in free shipping overrides all other shipping modules.

 

The build in free shipping is passed to checkout confirmation page, only using the option to select free shipping together with other shipping options displayed (worked out in clever way) 

 

My new store is not live yet - about 95%, rebuilding my new store to have similar capabilities as my old 2.2 version had which is heavily modified. 

So now in testing stage to tweak here and there, small language changes and so on but is looking very good.

Getting the Phoenix off the ground

Link to comment
Share on other sites

@@Peper,

 

I can't give you an exact solution without knowing your exact store setup and have also no time for this, sorry.

Please have a look on the existing add-ons.

Do a search for free shipping and store pickup in the addons area.

For example I found this:

http://addons.oscommerce.com/info/9349

http://addons.oscommerce.com/info/164

http://addons.oscommerce.com/info/1993

http://addons.oscommerce.com/info/5797

 

Please check them out

 

regards

Rainer

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...