[comment]
ui_name: cart
ui_type: component
ui_class: content
ui_group: checkout
ui_label: Shopping cart display (full)

others_bought:
	label: Use "others who bought this" here
	type: yesno

upsell_in_cart:
	label: Put upsell come-in under item
	type: yesno

continue_shopping:
        label: Show continue shopping button
        type: yesno

[/comment]
<!-- BEGIN COMPONENT [control component cart] -->

<br><b>[L]Your Current Shopping Cart[/L]:</b><br>

<table width="100%" cellspacing="0">
<tr>
	<td align="center">

	[calc]
		my $cname = $Config->{CookieName} || 'MV_SESSION_ID';
		$Scratch->{have_cookie} = $Tag->read_cookie($cname)
			and delete $Scratch->{tried};
		return;
	[/calc]
	[if scratch have_cookie]
	[elsif scratch tried]
    		[L CART_MSG1]You must have cookies set to leave the basket. Check out now or forever lose your shopping cart.[/L]
	[/elsif]
	[else]
		[set tried]1[/set]
		[bounce href="[area ord/basket]"]
	[/else]
	[/if]

	<FORM ACTION="[process secure=1]" METHOD=POST name="basket">
		[form-session-id]
    	<INPUT TYPE=hidden NAME=mv_doit      VALUE=refresh>
    	<INPUT TYPE=hidden NAME=mv_orderpage VALUE="ord/basket">
    	<INPUT TYPE=hidden NAME=mv_nextpage  VALUE=index>
    	<br>

	<table>
    	<tr>
      		<td>
        		<table cellspacing="0" cellpadding="4" border="0">
			<TR>
          			<td class="titletab_small"><b>&nbsp;[L]Remove[/L]</b></td>
			       <td class="titletab_small" align="center"><b>[L]SKU[/L]</b></td>
          			<td class="titletab_small"><b>[L]Description[/L]</b></td>
          			<td class="titletab_small"><b>[L]Quantity[/L]</b></td>
          			<td class="titletab_small" align="center"><b>[L]Price[/L]</b></td>
          			<td class="titletab_small"><b>[L]Extension[/L]&nbsp;</b></td>
			</TR>
			<TBODY>
	
[if items]
[then]
[item-list]

[item-change 2][condition]2[/condition]
[/item-change 2]

[item-calc]
#Log("Checking master item $master");
	$row_class = ++$count % 2 ?  'cartnorm' : 'cartalt';
	my $item = '[item-increment]';
	my $up = q{[item-data merchandising upsell_to]};
	my $cr = q{[item-data merchandising cross_sell]};
	$upsell_remove{'[item-code]'} = 1;
	$cross_remove{'[item-code]'} = 1;
	my %seen = ( '' => 1 );

	$Scratch->{upsell} .= " $up" if $up;
	$Scratch->{cross_codes} .= " $cr" if $cr;
	my @up = split /\s+/, $Scratch->{upsell};
	my @cr = split /\s+/, $Scratch->{cross_codes};
	@up = grep  ( (!$seen{$_}++ && ! $upsell_remove{$_}), @up);
	@cr = grep  ( (!$seen{$_}++ && ! $cross_remove{$_}), @cr);
	$Scratch->{upsell} = join " ", @up;
	$Scratch->{cross_codes} = join " ", @cr;
	return;
[/item-calc]

	<TR class="[item-calc]$row_class || 'cartnorm'[/item-calc]">
		<TD align=center valign="top">
	    		<INPUT TYPE=checkbox NAME="[item-quantity-name]" onClick="this.form.action='[process]', this.form.submit()" VALUE=0>
	  	</TD>
	  	<TD valign="top"><b>[item-sku]</b></TD>
	  	<td><a href="[area href="[item-sku]"]" class="cartlink"><b>[item-description]</b></A><br><br>

	[if scratch dealer]
	[if-item-data pricing sku]
	    <BR>[page quantity [item-code]]
	    [L]QUANTITY PRICING[/L]</A>
	[/if-item-data]
	[/if]
	[if-item-field weight]
	[seti weight][summary amount=`[item-quantity] * [item-field weight]`][/seti]
	[/if-item-field]
	[if-item-param mv_min_under]
		<br>
		<span style="color: __CONTRAST__; font-size: 8pt">
		[msg arg.0="[item-param mv_min_quantity]"]Minimum order quantity of %s enforced.[/msg]
		</span>
	[/if-item-param]
	[if-item-param mv_max_over]
		<br>
		<span style="color: __CONTRAST__; font-size: 8pt">
		[msg arg.0="[item-param mv_max_quantity]"]Maximum order quantity of %s enforced.[/msg]
		</span>
	[/if-item-param]

[if type=explicit compare="[control others_bought]"]
	[if-item-data merchandising others_bought]
	[perl tables=products]
		my $hash = [item-data merchandising others_bought];
		my @ary = sort { $hash->{$b} <=> $hash->{$a} } keys %$hash;
		return '' unless @ary;
		my %in_basket;
		splice(@ary, 3);
		for(@{$Carts->{main}}) {
			$in_basket{$_->{code}} = 1;
		}
		@ary = grep ! $in_basket{$_}, @ary;
		return '' unless @ary;
		my $out = <<'EOF';
	    <TABLE>
	    <TR>
              <TD class="titletab_small">[L]&nbsp;Customers who bought this item also bought&nbsp;[/L]:</TD>
	    </TR>
            <TR class="[item-calc]$row_class || 'contentbar1'[/item-calc]">
	      <TD>
EOF
		for(@ary) {
 			my $desc = tag_data( 'products', 'description', $_);
			$out .= <<EOF;
			<A HREF="[area $_]" class="cartlink">$desc</A><BR>
EOF
		}
		return $out . '</TD></TR></TABLE>';
	[/perl]
	[/if-item-data]
[/if]


[if type=explicit compare="[control upsell_in_cart]"]
	[set upsell_found][/set]
	[loop list="[item-data merchandising upsell_to]"]
	[if scratch upsell_found]
	<TABLE>
	<TR>
		<TD class="titletab_small">
			[L]&nbsp;Other items you may like&nbsp;[/L]:
	      	</TD>
	      	<TD></TD>
	</TR>
	<TR>
	      	<TD>
		  [list]
		  [loop-calc]
		  @ary = grep $_->{code} eq q{[loop-code]}, @{$Carts->{main}};
		  return if scalar @ary;
		  $Scratch->{upsell_found} = 1;
		  return q{<A HREF="[area [loop-code]]" class="cartlink">[loop-description]</A><BR>};
		  [/loop-calc]
		  [/list]
	      	</TD>
	</TR>
	</table>

	[/if]
	[/loop]
[/if]

	<br>

	[table-organize cols=4 table=' ' font="size=1" pretty=1]
		[item-options td=1 label=1 bold=1 price=1]
	[/table-organize]

	  </TD>

[input-filter name="[item-quantity-name]" op="nullselect digits_dot"][/input-filter]

	  <TD ALIGN=CENTER valign="top">
	    <INPUT TYPE=text NAME="[item-quantity-name]" VALUE="[item-quantity]" SIZE=3>
	  </TD>
	[if discount [item-code]]
	  <TD ALIGN=right valign="top">
	    [L]Regular price[/L] <STRIKE>[item-price]</STRIKE>
	    <BR>
	    <B>[L]Your price[/L]: [discount-price]<br>
	    [L]You save[/L]: [item-difference]
	  </TD>
	  <TD ALIGN=right valign="top">
	    <strike>[item-subtotal]</strike><br>
	    <B>[item-discount-subtotal]<BR>
	    [L]You save[/L]: [item-discount]</b>
	  </TD>
	[else]
	  <TD ALIGN=right valign="top">[item-price]</TD>
	  <TD ALIGN=right valign="top">[item-subtotal]</TD>
	[/else]
	[/if]
	</TR>

[item-tag-address
			set="[cgi mv_an[item-modifier mv_ip]]"
			address_label=nick
			nick="[cgi mv_an[item-modifier mv_ip]]"
			if="[value separate_addresses]"
			form="
				mv_action=refresh
				edit_addresses=1
				"
			textarea=1
			widget=links]
[address]

	<TR class="[item-calc]$row_class || 'cartalt'[/item-calc]">

[if cgi edit_addresses]
	  <TD>&nbsp;</TD>
	  <TD>&nbsp;</td>
	  <TD>
	    <SMALL>
	    <INPUT TYPE=hidden NAME="[item-modifier-name mv_an]" VALUE="{mv_an}">
	    {textarea}
	    </SMALL>
	  </TD>
	  <TD><INPUT TYPE=submit VALUE=[L]Save[/L]></TD>
[else]
	  <TD COLSPAN=2>
	    <SMALL>Retrieve:<BR>
	    {address_book}
	    </small>
	  </TD>
	  <TD>
	    <SMALL>
	    <PRE>{mv_ad}</PRE><INPUT TYPE=hidden NAME="[item-modifier-name mv_ad]" VALUE="[filter entities]{mv_ad}[/filter]">
	    </SMALL>
	  </TD>
	  <TD>&nbsp;</TD>
[/else]
[/if]
	  <TD>&nbsp;</TD>
	  <TD>&nbsp;</TD>
	</TR>
[/address]
[/item-tag-address]

[if session logged_in]
	<TR class="[item-calc]$row_class || 'cartalt'[/item-calc]">
	  <TD ALIGN="right" COLSPAN="6" valign="top">
		[if value separate_addresses]

		[page href="@@MV_PAGE@@" form="
			separate_addresses=0
			mv_action=return
		"][L]Same shipping address[/L]</A>&nbsp;&nbsp;&nbsp;
		[page href="@@MV_PAGE@@" form="edit_addresses=1"]<small>[L]Edit address[/L]</small></A>&nbsp;&nbsp;&nbsp;
		[page href="ship_addresses" form="ui_return_to=@@MV_PAGE@@"]<small>[L]Add address[/L]</small></A>
		[else]
		[page href="@@MV_PAGE@@" form="
			separate_addresses=1
			mv_action=return
		"][L]Separate shipping addresses[/L]</A>
		[/else]
		[/if]
	  </td>
	</TR>

[/if]

[/item-list]
[/then]
[else]

	<TR>
	  <TD ALIGN=CENTER COLSPAN=6 class="cartnorm">
	    <b>[L]No items at the moment.[/L]</b>
	  </TD>
	</TR>

[/else]
[/if]

        </TBODY>
        </table>

      </td>
    </tr>
    </table>

    <br>

    <table border="0" width="60%">  
    <tr>
      <td>

	<table border="0" width="100%">
        <tr> 
	  <td>
	    <INPUT type="submit" value="[L]Recalculate[/L]" class="button3">
	  </td>
	  <td align="center" valign="center"> 
    		[button
     		  text="[L]Check Out[/L]"
			  class="button3"
			  form=basket
		  ]
			mv_todo=return
			mv_nextpage=ord/checkout
		[/button]
	  </td>
	  <td align="center">
	    [if type=explicit compare="[control continue_shopping]"]
    	      [button
				text="[L]Continue shopping[/L]"
				class=button2
				form=basket
			  ]
     	  		[bounce page=index]
        		mv_nextpage=nothing
    	      [/button]
	    [/if]
	  </td>
      	  <td align="Right">
            <table cellspacing="0" cellpadding="4" border="0">
            <tr> 
              <td align=right>
                [L]Shipping Weight[/L]:
              </td>
              <td class="titletab_small" align="right">[summary format="%s" total=1]</td>
            </tr>
            <tr>
              <td align="right">
                <b>[L]Subtotal[/L]:</b>
              </td>
              <td class="titletab_small" align=right><b>[subtotal]</b></td>
            </tr>
	    </table>
	  </td>
	</tr>
	<tr>
	  <td colspan="4" align="center">
	    <br>
  [set Save Cart]
   mv_todo=return
   mv_nextpage=ord/basket
   save_cart=none
   [save_cart nickname="[value c_nickname]" recurring="[value c_recurring]"]
  [/set]

[if !scratch just_nickname]
  [seti just_nickname][tag time]%b-%d-%Y[/tag][/seti]
[/if]

[if session logged_in][then]
  [if value save_cart eq 'recurring']
    	    <FORM ACTION="[process]" METHOD=POST>
			[form-session-id]
    	    [L]To save this recurring order, give it a nickname, then press 'Save Cart'.[/L]<br>
    	    [L]Nickname[/L]:
    	    <INPUT TYPE=TEXT NAME="c_nickname" SIZE=11 VALUE="[scratch just_nickname]">
			<INPUT TYPE=HIDDEN NAME="c_recurring" VALUE="1">
    	    <INPUT TYPE=HIDDEN NAME="save_cart" VALUE="recurring">
    	    <INPUT TYPE=HIDDEN NAME="mv_todo" VALUE="return">
    	    <INPUT TYPE=HIDDEN NAME="mv_check" VALUE="Save Cart">
    	    <INPUT TYPE=SUBMIT VALUE="[L]Save Cart[/L]">
    	    </FORM>
  [elsif value save_cart eq 'cart']
    	    <FORM ACTION="[process]" METHOD=POST>
			[form-session-id]
    	    [L]To save this cart, give it a nickname, then press 'Save Cart'.[/L]<br>
    	    [L]Nickname[/L]:
    	    <INPUT TYPE=TEXT NAME="c_nickname" SIZE=11 VALUE="[scratch just_nickname]">
    	    <INPUT TYPE=HIDDEN NAME="c_recurring" VALUE="0">
    	    <INPUT TYPE=HIDDEN NAME="save_cart" VALUE="cart">
    	    <INPUT TYPE=HIDDEN NAME="mv_todo" VALUE="return">
    	    <INPUT TYPE=HIDDEN NAME="mv_check" VALUE="Save Cart">
    	    <INPUT TYPE=SUBMIT VALUE="[L]Save Cart[/L]">
	    </FORM>
  [/elsif]
  [else]
      [button
          text="[L]Save This Cart[/L]"
          src="__IMAGE_DIR__/savecart.gif"
          extra="class=titletab_small"
          hidetext=1
          form=basket
          mv_check="Save This Cart"
      ]
          mv_todo=return
          mv_nextpage=ord/basket
          save_cart=cart
      [/button]
      [button
          text="[L]Set As Recurring Order[/L]"
          src="__IMAGE_DIR__/saverecur.gif"
          extra="class=titletab_small"
          hidetext=1
          form=basket
          mv_check="Set As Recurring Order"
      ]
          [set save_cart]recurring[/set]
          mv_todo=return
          mv_nextpage=ord/basket
          save_cart=recurring
      [/button]
  [/else]
  [/if]
[/then][/if]
						
	  </td>					
        </tr>
        </table>

      </td>
    </tr>
    </TABLE>
    </FORM>

  </td>
</tr>
</table>

<br><br>

<!-- END COMPONENT [control component cart] -->
