Page 1 of 1

[solved]cart module options

Posted: Sat Oct 10, 2009 9:39 am
by kurashiki_ben
Cart version 1.4.2

Hello,

Does anyone know what the options are for the my cart page?

I want to display the cart total, but I can't find the correct option.
I have tried $carttotal which works in the cart view page, but it results in a null value in the my cart page.

here's my template:
(the $cart_itemcount works fine)

Code: Select all

{* mycart form template *}
{$formstart}
<table align="center" width="100%">
<tbody>
    <tr>
<td align="left" border="0">
<strong>商品の数: </strong></td><td align="left"><strong>{$cart_itemcount}</strong></td></tr>
{if isset($submitname)}
<tr>
<td align="center"><strong>かごの合計:<br />(税込み) </strong></td>
<td>{math equation='x * y' x=$carttotal y=1.05 assign='tmp2'}{$tmp2|number_format:0}{$currencysymbol}
</td>
</tr>
{/if}
</tbody>
</table>
<div align="center"><input type="button" id="kagoni" name="kagoni" onclick="window.location='index.php?page=kago'" value="買い物かご"/>
</div>
{$formend}
<br />
Thanks

Ben

Re: cart module options

Posted: Sat Oct 10, 2009 11:20 am
by SideshowBob
Hi Ben,

I'm currently building an e-commerce site with the CG modules and, whilst generally the modules are excellent,  I found the lack of totals and subtotals quite surprising. I submitted a feature request.

I think there are two solutions here, either hack the module php to output the values you need or calculate the total using Smarty.

I chose the Smarty route as it keeps my upgrade options open.

Hope that helps,
Bob

Re: cart module options

Posted: Sun Oct 11, 2009 3:16 am
by kurashiki_ben
thanks for your reply SideshowBob

Do you have an example of a Smarty tag that you used?

many thanks for your help

Regards

Ben

Re: cart module options

Posted: Sun Oct 11, 2009 7:59 am
by SideshowBob
ah, I didn't use the MyCart function, I use a modified ViewCart. That could be your best option.

Anyway, here is the Smarty code I used to create Totals and subtotals. This is actually from the Confirm Order template from the Orders module but hopefully you get the idea.

Code: Select all

{assign var=total value=0} {* set total variable to 0 *}

      {foreach from=$destination->get_items() item='item'}

         {math equation="x * y" x=$item->get_quantity() y=$item->get_unit_price() assign=subtotal} {* set subtotal *}
         {math equation="x + y" x=$total y=$subtotal assign=total} {* add subtotal to total *}

         <tr>
            <td>{$Orders->Lang($item->get_item_type())}</td>
            <td>{$item->get_description()}</td>
            <td>{$item->get_quantity()}</td>
	    <td>{$currencysymbol}{$item->get_unit_price()|number_format:2}</td>
            <td>{$currencysymbol}{$subtotal|number_format:2}</td>
          </tr>
      {/foreach}
      <tr>
          <td colspan="5">Total: {$currencysymbol}{$total|number_format:2}</td>
      </tr>

Re: cart module options

Posted: Mon Oct 12, 2009 4:56 am
by kurashiki_ben
SlideshowBob,

Thats great. Thanks for your answer. With that I found a solution.
I ended up calling the cart module twice. Once to show the itemcount, once for the total.

Code: Select all

<div id="cart">
{Cart action='mycart'}
{Cart action='viewcart' viewcarttemplate="hompagecart"}
</div>
mycart template:

Code: Select all

{* mycart form template *}
{$formstart}
<table id="basketcount" align="center" border="0" width="100%">
<tbody>
<tr>
<td align="left" width="50%">
<strong>商品の数: </strong></td>
<td align="left" width="50%">{$cart_itemcount}</td>
</tr>
</tbody>
</table>
{$formend}
modified viewcart template:

Code: Select all

{* homepagecartdisplay form template *}
{$formstart}
{if !isset($cartitems) || count($cartitems) > 0 }
<table id="homebasket" align="center" width="100%">
<tbody>
<tr>
<td align="left" width="50%"><strong>かごの合計:<br />(税込み) </strong></td>
<td align="left" width="50%">{math equation='x * y' x=$carttotal y=1.05 assign='tmp'}{$tmp|number_format:0}{$currencysymbol}</td>
</tr>
</tbody>
</table>
{/if}
<div align="center"><input type="button" id="kagoni" name="kagoni" onclick="window.location='index.php?page=kago'" value="買い物かご"/>
</div>
{$formend}
<br />
Best regards

Ben