Post by Qphoria » Mon Aug 03, 2009 7:27 am

In the checkout/confirm.php file there is this bit of code:

Code: Select all

$results = $this->model_checkout_extension->getExtensions('total');
		
foreach ($results as $result) {
	$this->load->model('total/' . $result['key']);

	$this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
}
		
$sort_order = array(); 
	  
foreach ($total_data as $key => $value) {
	$sort_order[$key] = $value['sort_order'];
 }

array_multisort($sort_order, SORT_ASC, $total_data);
This shows that first it loops through all the order calcs. During which time it does the calculations, THEN sorts them. But that means the sort only affects what order they are displayed in, not the order that they are calculated in.

So If I add a new total module for military discount, and set the sort order to 2, which is the same as the Low Order Fee module.... It will show the discount in the total, but won't actually take the discount off because the "total" module has already loaded first. (and yes you can trust that I coded it correctly :P)
militdisc.jpg

militdisc.jpg (11.57 KiB) Viewed 3014 times

The problem is the first $results returns the modules in any random order since there is no "order by" qualifier on the catalog/model/extension function for getExtensions().

Code: Select all

$results
: array = 
  0: array = 
    extension_id: string = "14"
    type: string = "total"
    key: string = "coupon"
  1: array = 
    extension_id: string = "22"
    type: string = "total"
    key: string = "shipping"
  2: array = 
    extension_id: string = "63"
    type: string = "total"
    key: string = "low_order_fee"
  3: array = 
    extension_id: string = "57"
    type: string = "total"
    key: string = "sub_total"
  4: array = 
    extension_id: string = "58"
    type: string = "total"
    key: string = "tax"
  5: array = 
    extension_id: string = "59"
    type: string = "total"
    key: string = "total"
  6: array = 
    extension_id: string = "102"
    type: string = "total"
    key: string = "handling"
  7: array = 
    extension_id: string = "107"
    type: string = "total"
    key: string = "military_discount"

You will see this is already a problem with the new "Handling" total extension, as it also loads after total.

There needs to be a sort on these results before doing the getTotal on each of them so that "total" can always be last.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JJJaved » Tue Aug 04, 2009 9:24 pm

Please inform when this "discount" module is fully tested and functial.

New member

Posts

Joined
Tue Jul 07, 2009 12:57 am
Location - Cardiff - UK

Post by Daniel » Tue Aug 04, 2009 9:37 pm

thansk for letting me know about this!

the fix will be in the next release.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by iloveopencart » Wed Aug 05, 2009 1:52 pm

Ah, thanks for discovering that, Q. That has been driving me c-c-crazy (using OC 1.2.9). I just couldn't figure out why $total was displaying $0.00 all the time. So I just reordered the extension_id in the extension table to the order I wanted them to appear and added ORDER BY extension_id to the query in model/checkout/extension file, and magic - it worked! Of course, this is just a quick fix. If any new extension is added, the id's will probably have to be reordered. But if anyone else is having trouble with the totals, this is a pretty simple solution.

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by somwicked » Fri Aug 07, 2009 1:46 pm

Running into the exact same issue - the low order fee - is not being added to the total.

I follow editing the table to set the sort order as wanted but changing the SQL query is making my head hurt due to all the concatenation going on - makes my eyes go all oogly.

Would it be possible to get you to post your extension.php or send it to me via PM?

Would be VERY much appreciated.

Newbie

Posts

Joined
Tue Jun 09, 2009 8:01 am

Post by somwicked » Fri Aug 07, 2009 2:05 pm

Never mind got .. just had to peel my eyes open for a bit. Thanks for the fix!

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "extension WHERE `type` = '" . $this->db->escape($type) . "'" . "ORDER by extension_id");

Newbie

Posts

Joined
Tue Jun 09, 2009 8:01 am

Post by jinnmyx » Mon Aug 17, 2009 3:05 am

But I think it still come with problem if when uninstall all and re-install back from Total, Sub-total, etc...

For temp solution, I change to sort by `key`(alpha) name, because the total always count at the last.

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "extension WHERE `type` = '" . $this->db->escape($type) . "' ORDER by `key`");

Newbie

Posts

Joined
Mon Aug 17, 2009 2:47 am

Post by Qphoria » Mon Aug 17, 2009 3:33 am

FYI you don't need this since 1.3.1+

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 21 guests