[ic] Assistance Requested mv_order_group And 'mv_mi' => undef (solved)

Eric Small interchange at ericsmall.com
Tue Apr 20 09:12:14 EDT 2004


Quoting Mike Heins
> It is easy to make this the default with a special tag ...

You're right it was easy, once I figured out how to get at everything :)

Attached is my custom procedure to handle the processing, perhaps it will be 
useful to someone in the future.  Please note I'm a newb at Perl so this might 
not be as elegant a solution as it could be.


[set munge_cart_quantity]
[calc]
#	Check to see if the quantities of a master group item have changed.
#	If they have then update the quantities of child items by the same factor.
# Example: Assume current master item (MI) quantity is 2 and child item (CI)  # 
quantity is 4.
#    Suppose the new MI quantity is 5 then the CI quantity will become 10.
#    4 * 5 / 2 = 10 = (CIquantity * MIquantity_new / MIquantity_old)
# Note:  This procedure was designed for integer quantities.  If fractional   # 
quantities are required then take note of the int conversions.

	#Log('Called munge_cart_quantity');

	my $ItemIndex = 0;
	my $mvmi_last = undef;
	my $mvmi_cur;
	my $mvsi_cur;
	my $qty_curcgi;
	my $qty_cur;
	my $qty_new;
	my $qty_group_cur;
	my $qty_group_new;
	
	foreach (@{$Items}) {
#Get current group
		$mvmi_cur = $_->{'mv_mi'};
#Check to see if current item is in a group
		if ($mvmi_cur != undef) {
			#Log('Item ' . $ItemIndex . uneval($_));
			$mvsi_cur = $_->{'mv_si'};
#Check to see if this item is a new group
			if (($mvmi_last != $mvmi_cur) && ($mvsi_cur == 0)) {
				$qty_group_cur = int(($_->{'quantity'}));
				$qty_curcgi = "quantity$ItemIndex";
				$qty_group_new = int(($CGI->{$qty_curcgi}));
				if ($qty_group_new < 0) {
					$qty_group_new = 0;
				}
				$CGI->{$qty_curcgi} = $qty_group_new;
				$qty_ratio = ($qty_group_new / $qty_group_cur);
				#Log("Found Master Item $ItemIndex , $qty_ratio");
				#Log("qty_curcgi = $qty_curcgi");
				#Log("qty_ratio = $qty_new / $qty_cur");
			}elsif (($mvmi_last == $mvmi_cur)) {
#Check to see if change is needed.
#No action needed if item quantity has not changed or new quantity is 0.
				if (($qty_ratio != 1) && ($qty_ratio != 0)) {
					$qty_cur = int($_->{'quantity'});
					$qty_new = ($qty_cur * $qty_group_new / $qty_group_cur);
					$_->{'quantity'} = "$qty_new";
					#Log("Changed Item $ItemIndex:" . " $qty_cur * $qty_ratio = $qty_new");
				}
			}
		}
		$mvmi_last = $mvmi_cur;
		$ItemIndex++;
	}
[/calc]
[/set]


Interchange 5.0.1 on Debian 3.0r2 with perl 5.6.1and PostgreSQL 7.4.1



More information about the interchange-users mailing list