[ic] Assemblies -- Magic words

Mike Heins mike at perusion.com
Mon Jul 26 21:40:12 EDT 2004


Quoting Eric Small (interchange at ericsmall.com):
> Jeme wrote:
> >
> >Is that in the distribution?  It's not in the Debian package I have. 
> >Where can I get this demo?  More importantly (assuming you have a moment
> >to point it out and save me a day's rifling through code), what is
> >different in your demo that causes behavior?
> > 
> >
> I have done something very similar to what you're trying to do.  It is 
> possible :)  I used parts of the Mike demo to help me out.  I downloaded 
> my copy from http://www.interchange.rtfm.info/downloads/demos/
> 
> I don't recall that the Mike demo did have item grouping in the cart 
> with a single checkbox, but I might have missed it since I was taking 
> pieces of Mike and putting into Foundation.

It may just be in my local version. In any case, it is very
easy:

	[if-item-param !mv_si]
	<input type=checkbox name="quantity[item-param mv_ip]" value=0> Remove
	[/if-item-param]

> One problem I did run into was changing cart quantities.  The quantity 
> of the master item will change, but the child items won't change.  You 
> should be able to find my solution, which was created with much help 
> from Mike Heins, by searching the forums for munge_cart_quantity.  This 
> action will update the cart quantities to keep the same ratio between 
> the parent and child items in a group.  I'm not much of a Perl 
> programmer so my code probably isn't a "best solution", but it does work.

That is actually an possiblity for a standard feature; you could have a
"mv_slave_quantity" parameter that would automatically change the
quantity of sub_items when the master item changed.

In any case, it is pretty easy to put in a little bit of
embedded Perl code for the basket/checkout/final order profile:

    [calc]
        my %quantity;
        for my $it (@$Items) {
            next unless $it->{mv_mi};
            if($it->{mv_si}) {
		$it->{quantity} = $quantity{$it->{mv_mi}};
            }
            else {
		$quantity{$it->{mv_mi}} = $it->{quantity};
            }
        }
        return;
    [/calc]

Actually, now that I think about it that is a great place to put a
SpecialSub -- "post_cart_update" and "pre_cart_update".

Sub <<EOR
sub slave_quantity {
        my %quantity;
        for my $it (@$Items) {
            next unless $it->{mv_mi};
            if($it->{mv_si}) {
		$it->{quantity} = $quantity{$it->{mv_mi}};
            }
            else {
		$quantity{$it->{mv_mi}} = $it->{quantity};
            }
        }
        return;
}
EOR

SpecialSub post_cart_update slave_quantity

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Being against torture ought to be sort of a bipartisan thing.
-- Karl Lehenbauer


More information about the interchange-users mailing list