Post by nextgenxx » Tue Oct 07, 2008 6:59 am

How can I show a "grand total" dollar amount below the following prices.
                 
                            Product Total:      $164.80
                        Coupon (-10%):      -$10.00
Shipping & Handling (USA Only): $19.95

                          GRAND TOTAL:

Currently it dosen't show the grand total just the seperate totals.

User avatar
New member

Posts

Joined
Tue Jul 15, 2008 1:13 am


Post by Qphoria » Tue Oct 07, 2008 7:43 am

Hmm..

I see it differently:

Subtotal: $50.00
PRIORITY (1 Day): $6.45
Coupon (-10%): -$5.00
Coupon (Free Shipping): -$6.45
Illinois Tax: $2.50
Total: $47.50

Did you make any changes to the files?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by nextgenxx » Tue Oct 07, 2008 8:04 am

I still can't see the user group page, but somehow moving forward in installing your mods :). I have installed  OC twice and both stores don't have the user group page found. It is really weird, it is only that one page like that.

Moving on to the grand totals, it would be nice to have the coupon at the very end of all calculations, but also on another note we have no sales tax to deal or worry about here in Oregon.

This is what I am getting:

Subtotal:  $164.80
Shipping & Handling UPS Ground (USA Only): $29.95
Coupon (-10%): -$19.48



No Grand Total.
What php code controls the Grand total is it (total.php) I just would like the final amount to appear on the Checkout Confirmation page before the buyer click "I agree to the terms..."

User avatar
New member

Posts

Joined
Tue Jul 15, 2008 1:13 am


Post by bruce » Tue Oct 07, 2008 8:35 am

Try this...

In your store admin, from the menu Extensions->Calculate

Check that each one has a unique sort order with the Total having the highest value. Duplicate sort order causes the second and subsequent totals with the same sort order to disappear.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Qphoria » Tue Oct 07, 2008 10:17 am

Was hoping that was fixed in 0.7.current but I see it is not :'( :-\
Can we call it a feature ?  ;D

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by bruce » Tue Oct 07, 2008 10:32 am

This fixes the problem if you want to use it.

So far, I am just putting a copy of the msort() function in each class where it is needed. Obviously I want it in a single location at some stage.

The following is a working replacement for library\cart\calculate.php and contains the replaced code in the comments.
Please backup your original before replacing... just in case.

Code: Select all

<?php
class Calculate
{
	var $data = array();

	function __construct(&$locator)
	{
		$this->database =& $locator->get('database');
		$results = $this->database->getRows("select * from extension where type = 'calculate'");
		foreach ($results as $result)
		{
			$file  = DIR_EXTENSION . $result['directory'] . '/' . $result['filename'];
			$class = 'Calculate' . str_replace('_', '', $result['code']);

			if (file_exists($file))
			{
				require_once($file);
				$this->data[$result['code']] = new $class($locator);
			}
		}
	}

	function getTotals()
	{
		$sort_data = array();

		foreach (array_keys($this->data) as $key)
		{
			$order = $this->data[$key]->getSortOrder();
			$sort_data[] = array('order' => $order, 'key' => $key);
		}

		$sorted = $this->msort($sort_data, "order");
		$total_data = array();
		$i = 0;
		foreach ($sorted as  $key =>$calculator)
		{
			$results = $this->data[$calculator['key']]->calculate();
			foreach ($results as $result)
			{
				$total_data[] = array(
					'title'      => $result['title'],
					'text'       => $result['text'],
					'value'      => $result['value'],
					'sort_order' => $i
				);
				$i++;
			}
		}

		return $total_data;
	}

	function msort($array, $id="id", $sort_ascending=true)
	{
		$temp_array = array();
		while(count($array)>0)
		{
			$lowest_id = 0;
			$index=0;
			foreach ($array as $item)
			{
				if (isset($item[$id]))
				{
					if ($array[$lowest_id][$id])
					{
						if ($item[$id]<$array[$lowest_id][$id])
						{
							$lowest_id = $index;
						}
					}
				}
				$index++;
			}
			$temp_array[] = $array[$lowest_id];
			$array = array_merge(array_slice($array, 0,$lowest_id), array_slice($array, $lowest_id+1));
		}
		if ($sort_ascending)
		{
			return $temp_array;
		}
		else
		{
			return array_reverse($temp_array);
		}
	}

	/*

	  The following original code is flawed in that a duplicate value for sort_order over
	  any of the calculate extensions will cause the first instance(s) to simply disappear.

	function getTotals()
	{
		$sort_order = array();

		foreach (array_keys($this->data) as $key)
		{
			//$sort_order[$this->data[$key]->getSortOrder()] = $key;
			$order = $this->data[$key]->getSortOrder();
			$sort_order[] = array('order' => $order, 'name' => $key);
		}

		ksort($sort_order);

		$total_data = array();

		$i = 0;

		foreach ($sort_order as $key)
		{
	  		$results = $this->data[$key]->calculate();

	  		foreach ($results as $result)
	  		{
	    		$total_data[] = array(
		  			'title'      => $result['title'],
		  			'text'       => $result['text'],
		  			'value'      => $result['value'],
					'sort_order' => $i
			);

				$i++;
	  		}
		}

		return $total_data;
  	}
*/
}
?>

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by nextgenxx » Wed Oct 08, 2008 1:03 am

Thanks Bruce, It worked! Also, how can I make the grand total Bold.

User avatar
New member

Posts

Joined
Tue Jul 15, 2008 1:13 am


Post by Qphoria » Wed Oct 08, 2008 2:07 am

The fix was added to 0.7.9. Thanks bruce

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by bruce » Wed Oct 08, 2008 9:13 am

nextgenxx wrote: Thanks Bruce, It worked! Also, how can I make the grand total Bold.
Ah yes... this is harder. As you can see in this extract from checkout_confirm.tpl, all the calculated totals have the same style.

Code: Select all

        <?php foreach ($totals as $total) { ?>
        <tr>
          <td class="right" colspan="4"><?php echo $total['title']; ?></td>
          <td class="right"><?php echo $total['text']; ?></td>
        </tr>
        <?php } ?>
and from this extract from catalog\extension\calculate\total.php, you can see that there is no way to identify the grand total from the other totals.

Code: Select all

		if ($this->config->get('total_status')) {
      		$total_data[] = array(
	    		'title' => $this->language->get('text_total_title'), 
	    		'text'  => $this->currency->format($this->cart->getTotal()),
	    		'value' => $this->cart->getTotal()
	  		);
		}
Solution:
=======
1) Modify catalog\extension\calculate\total.php to replace the above snippet with the following to add a language independant tag to the grand total array...

Code: Select all

		if ($this->config->get('total_status')) {
      		$total_data[] = array(
	    		'title' => $this->language->get('text_total_title'), 
	    		'text'  => $this->currency->format($this->cart->getTotal()),
	    		'tag '  => 'grand_total',
	    		'value' => $this->cart->getTotal()
	  		);
		}
2) Modify the getTotals() function in library\cart\calculate.php to add the tag value there if it is present. Shown below...

Code: Select all

			foreach ($results as $result)
			{
				$total_data[] = array(
					'title'      => $result['title'],
					'text'       => $result['text'],
					'value'      => $result['value'],
					'tag'        => isset($result['tag']) ? $result['tag'] : '',
					'sort_order' => $i
				);
				$i++;
			}
3) Replace the section from catalog\template\default\content\checkout_confirm.tpl that displays the totals with the following to use the tag value to apply an additional style or formatting to the grand total only.

Code: Select all

    <div class="f">
      <table>
<?php foreach ($totals as $total)
{
  if ($total['tag'] == 'grand_total')
  {
?>
        <tr>
          <td class="right" style="font-weight: bold;" colspan="4"><?php htmlEcho($total['title']); ?></td>
          <td class="right" style="font-weight: bold;" ><?php htmlEcho($total['text']); ?></td>
        </tr>
  <?php
  }
  else
  {
  ?>
        <tr>
          <td class="right" colspan="4"><?php htmlEcho($total['title']); ?></td>
          <td class="right"><?php htmlEcho($total['text']); ?></td>
        </tr>
<?php
  }
}
?>
      </table>
    </div>
I have attached a screenshot of these changes in action

Cheers

Bruce

Attachments

???
grand_total.png

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by nextgenxx » Thu Oct 09, 2008 12:57 am

hmmn...I have tried doing this three times now and each time I get through all the steps I get a blank screen at the end. Step one works, step two gets a blank screen and then step three. I have looked closley and don't know what is going wrong.

I was able to change catalog\language\english\extension\calculate\total.php with the following to get the text bold, bot the ammount.

Total:';
?>

I know this probably isn't the correct way to go about, but works now.

Brent

User avatar
New member

Posts

Joined
Tue Jul 15, 2008 1:13 am


Post by bruce » Thu Oct 09, 2008 9:08 am

simple and effective... I love it.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 1 guest