Post by Miguelito » Sat Dec 25, 2010 9:45 pm

Hi,

Searched through the forum but couldn't find a topic regarding this issue...

I need to get the total weight of an order in admin backend sales order. Went through sale order model and couldn't find a function which would handle this. Does anyone know if there's one I could use? Or do I need the create a new function to sale order model or modify the getOrder function? Idea anyone?


-Miguelito-

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by Miguelito » Sun Dec 26, 2010 6:26 pm

OK, solved this by creating a new public function getOrderWeight to sale order model and using that in the sale order controller :)

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by i2Paq » Sun Dec 26, 2010 8:26 pm

Miguelito wrote:OK, solved this by creating a new public function getOrderWeight to sale order model and using that in the sale order controller :)
Why not share that code with us?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

UPGRADE to 2.x: Contemplate before thou begins!

Our FREE search: Find your answer FAST!.

BUGs?: Known BUGS for All OC Versions.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by Miguelito » Mon Dec 27, 2010 12:44 am

Sure :)

Added to /admin/model/sale/order.php

Code: Select all

public function getOrderWeight($order_id) {
	        $query = $this->db->query("SELECT SUM(p.weight * op.quantity) AS weight FROM " . DB_PREFIX . "order_product op LEFT JOIN " . DB_PREFIX . "product p ON op.product_id = p.product_id WHERE op.order_id = '" . (int)$order_id . "'");
                
                if ($query->row['weight']) {
			$weight = $query->row['weight'];
		} else {
			$weight = 1;
		}
		return $weight;
	}
And used it in /admin/controller/sale/order.php

Code: Select all

$weight = array();
                        if (isset($this->request->get['order_id'])) {
			$weight['weight'] = $this->model_sale_order->getOrderWeight($this->request->get['order_id']);
		        }

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by tempe » Mon Apr 04, 2011 7:30 am

tried this one but confuse where to place that code, already tried to place them somewhere but not working

Newbie

Posts

Joined
Wed Mar 30, 2011 3:15 am

Post by ddowdall » Wed Sep 28, 2011 1:13 am

@Miguelito Thank you for sharing!

@tempe depending on which page you want to display the weight, you would add the code to the related function. So if you want to add the weight to the /index.php?route=sale/order/info page you would edit the info() function inside the /admin/controller/sale/order.php file.

I also added this line in the controller to make it work.

Code: Select all

$this->data['weight'] = $weight['weight'];
You will also have to edit the view for the page you want to have the weight be displayed on.
Add this line to display the weight:

Code: Select all

<?php echo $weight; ?>

New member

Posts

Joined
Tue Dec 07, 2010 2:06 am

Post by j_v » Thu Dec 22, 2011 3:59 pm

Hi,

Is there any way to add block to admin/index.php?route=sale/order/info&order_id=%someorder% without core files editing?

Best regards

j_v
Newbie

Posts

Joined
Thu Dec 22, 2011 3:56 pm

Post by nancymobley73 » Wed Dec 28, 2011 10:41 pm

j_v wrote:Hi,

Is there any way to add block to admin/index.php?route=sale/order/info&order_id=%someorder% without core files editing?

Best regards
From what i can see no it is not possible. You have to edit the core files for it to work.

how to gain weight fast


Newbie

Posts

Joined
Wed Dec 28, 2011 10:35 pm

Post by j_v » Thu Jan 05, 2012 10:03 pm

nancymobley73 wrote:
j_v wrote:Hi,

Is there any way to add block to admin/index.php?route=sale/order/info&order_id=%someorder% without core files editing?

Best regards
From what i can see no it is not possible. You have to edit the core files for it to work.
It is a pity.

Thank you for answer and happy New Year!

j_v
Newbie

Posts

Joined
Thu Dec 22, 2011 3:56 pm

Post by joshgeake » Wed Nov 21, 2012 10:35 pm

This will probably be what you want. Works in 1.5.3.

Attachments


Newbie

Posts

Joined
Fri Aug 03, 2012 10:25 pm

Post by planetdrop » Sun Jan 13, 2013 8:34 pm

There are two problems with this method.

1. Weight Class - This does not take into account if multiple types of weight classes are used. Such as gram and kg. Rather than using a total SUM in the query, it may be best to loop each query returning the SUM of identical weight classes and then tally the weights using $this->weight->convert(). Using the weight_class_id from the "product" table and converting it to the weight class from the store configuration. (i.e. "SELECT SUM(p.weight * op.quantity) AS weight, p.weight_class_id FROM...")

2. Product Options - This method does not take into account weights from the product options. You also need to tally weights from the "product_option_value" table linked to "order_options."

Newbie

Posts

Joined
Thu Mar 29, 2012 6:45 pm

Post by thbr02 » Fri May 09, 2014 12:36 am

I think this is a very usefull extension, but I really would like to include the product option weight as well. Any suggestions how I can change the code above?

Active Member

Posts

Joined
Wed Jun 22, 2011 10:30 pm
Location - Sweden

Post by thbr02 » Sat May 10, 2014 11:17 pm

Thought I've sovled it, but I didn't ???. Would appreciate some help.

Active Member

Posts

Joined
Wed Jun 22, 2011 10:30 pm
Location - Sweden

Post by chokybp » Thu Apr 26, 2018 12:47 pm

I have created the fallowing function:

Code: Select all

public function getOrderWeight($order_id){
        $weight = 0;
        $query_products = $this->db->query("SELECT op.product_id, op.order_product_id, op.quantity, p.weight FROM `" . DB_PREFIX . "order_product` op"
                ." LEFT JOIN `" . DB_PREFIX . "product` p ON (p.product_id = op.product_id)"
                ." WHERE order_id = '" . (int)$order_id . "'");
        
        foreach($query_products->rows as $row){
            $product_weight = (float)$row['weight'];
            $query_options = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_option` oo"
                    ." LEFT JOIN `" . DB_PREFIX . "product_option_value` pov ON (oo.product_option_value_id = pov.product_option_value_id)"
                    ." WHERE oo.order_product_id = '" . (int)$row['order_product_id'] . "'");
            
            // add weigth from option value if any
            foreach($query_options->rows as $row_ov){
                if ($row_ov['weight_prefix'] == '+') {
                    $product_weight += (float)$row_ov['weight'];
                } elseif ($row_ov['weight_prefix'] == '-') {
                    $product_weight -= (float)$row_ov['weight'];
                }
            }
            $weight += $product_weight * (int)$row['quantity'];
        }
        return $weight;
    }
It works with option but just not with weight classes.

Newbie

Posts

Joined
Thu Apr 26, 2018 1:20 am
Who is online

Users browsing this forum: No registered users and 8 guests