[ic] Creating custom shipping dropdown list (about old post by Michael Lehmkuhl)

Paco Sánchez interchange-users@icdevgroup.org
Tue Jan 21 18:07:01 2003


> That is nice.. But where are you getting the shipping costs from? One

I have created different shipping methods for each "vendor".

Anyway I have already tried several different ways to do this I want but to
no avail.

My idea is as follows:

- You create an additional field at the products database.  Let us call it
"vendor" (or whatever you like).  In this field you indicate, for each
product, a code that will identify the shipping methods available for it.
In my case I set this code to 00 or 01 depending on the products.

- Now you create shipping methods for each code.  The idea is that you can
create several methods for each.

- Then at checkout.html, items in an order are grouped depending on their
"vendor" field.  I think this could be done by something like [seti
currentvendor][item-field vendor][/seti].

-  But then, and this is what I have not been able to achieve, a shipping
options dropdown list should appear for each product, showing only valid
shipping methods for the related vendor.  The original idea obtained from an
old post from Michael Lehmkuhl is as follows:

<SELECT NAME=mv_shipmode onChange="this.form.submit()" CLASS="styled">
[seti vendormodes][data table=country key='[default country US]'
col=shipmodes][/seti]
[perl]

    my @temparr = split(/[\s,]/,$Scratch->{vendormodes});
    my $currentvendor = $Scratch->{currentvendor};

    # Display only those shipping modes that match the vendor for this
product.
    @temparr = grep { m"^$currentvendor" } @temparr;

    $Scratch->{vendormodes} = join(' ',@temparr);

[/perl]

[shipping
    label=1
    mode='[scratch vendormodes]'
]
</SELECT>

But unfortunately it does not work.  Further, I believe he got this running,
as it can be seen at https://www.hoopstore.net/store, but unfortunately he
seems not to be here anymore to explain how he didi it.

I have also found an alternative as follows.  The only limitation is that
you can only define a single shipping method for each product:

- Create a new field in the products database as in the former example.
Here we will call it "ship".  You will also insert a shipping code here for
each product.

- Then create a shipping methos for each code.  Say you have codes 00 and
01, so you could create shipping methods UPS00 and FEDEX01.

- Now create the following user tag in catalog.cfg:

UserTag delivery-charge Routine <<EOR
sub {
	my $mv_shipmode = $::Values->{mv_shipmode};
	my $items = $Vend::Items;
	my $delivery_charges = 0;
	my $opt = { convert => 1, noformat => 1 };
	my %carts;

	# iterate over the cart, watch the sun rise :)

	foreach my $i (0 .. $#$Vend::Items) {

		# decode cart item into components

		my $code = $Vend::Items->[$i]{code};
		my $mv_ib = $Vend::Items->[$i]{mv_ib};

		# get shipping class of product

		my $db = Vend::Data::database_exists_ref($mv_ib);
		$db = $db->ref();

		return "no such sku $code" unless $db->record_exists($code);
		my $ship = $db->field($code, "ship");

		# create cart for each shipping class

		push @{$carts{$ship}}, $Vend::Items->[$i];
	}

	# calculate shipping for each cart ...
	foreach my $c (keys %carts) {
		$Vend::Items = $carts{$c}; # set shopping cart to this subset of items
		my $delivery = Vend::Interpolate::tag_shipping($mv_shipmode . $c,
$opt);
		$delivery_charges += $delivery;
	}

        # restore original shipping cart
	$Vend::Items = $items;

	return $delivery_charges;
}
EOR


- And finally insert this tag [delivery-charge] wherever you want to see the
shipping charges for a product.

This is a very good idea that I have found in an old post from Guido Sohne.
Unfortunately it is only good if you only have a shipping method for each
ship code.

If anyone could help in doing this letting the customer choose among
shipping methods available for a ship code, it would be much appreciated.
Sure it can be done as seen in hoopstore.


> another note does anyone know where ord/checkout.html is configured to the
> store? The checkout.html file I am using in storeid = 'store' is not the
one
> I see being displayed, the one being displayed is the foundation
> checkout.html template.
>

You must edit the checkout.html at
~interchange/catalogs/YOUR_CATALOG/pages/ord/checkout.html

That is the one you will see from the UI.

Regards,

Paco Sánchez
http://pacosanchez.com
mailto:psanchez%40pacosanchez%2ecom
ICQ 101879542