Jump to content

first module, get order details


maipiusenza

Recommended Posts

Hi,

I'm just creating my first module.

 

I was able to create the package install it and get an "hello world" in the admin product details page.

 

Now I need some more info:

1) I wrote

	  return parent::install() &&
		$this->registerHook('displayAdminOrder') &&
		Configuration::updateValue('MYMODULE_NAME', 'my friend');
	}

But in PS 1.4 displayAdminOrder is  adminOrder

how can I write it to work with all versions of PS?

 

2) the module must retrive some order info:

 

- full shipping address

- customer shipping phone numbers

- customer email adress

- order total weight

 

I Imagine I should get them in mymodule.php and pass it to the template by smarty variables, but I don't know how to get that data.

 

Thanks a lot!

 

Nadia

 

 

Link to comment
Share on other sites

Thanks!

 

Ok for point 1, but I can't get the info of point 2.

 

This in what I wrote:

public function hookAdminOrder($params)
{

  $order = new Order($params['id_order']);
  $html = '<br /><fieldset style="width:400px;"><legend>' . $this->l('ADDITIONAL FIRLDSET') . '</legend>';

  $html .= $order->id_customer.'<br/>'; //ok
   
  $html .= '</fieldset>';
  return $html;	  
}

So I can get Id_customer, but I don't know how to get

- order weight

- Shipping address name

- Shipping address company

- Shipping address city, zip, state, phone...

- Customer email

 

Is there a list of vars that I can use?

 

Thanks

Nadia

Link to comment
Share on other sites

you can use OrderDetail class, there is a variable named product_weight,

to get a customer address you have to use class named Address: $address = new Address($order->id_address_delivery)

to get cuctomer data you have to use Customer class: $customer = new Customer($order->id_customer)

Link to comment
Share on other sites

I've found almost all data (please let me know if I'm doing it wrong):

	$order = new Order($params['id_order']);
	$customer = new Customer($order->id_customer);
  	$address = new Address($order->id_address_delivery);
	$state = new State ($address->id_state);
	$country = new Country ($address->id_country);
  
  $html = '<br /><fieldset style=""><legend>' . $this->l('LDV Generator') . '</legend>';
  $html .= $order->id_customer.'<br/>'; //ok
  $html .= 'firstname: '.$address->firstname.'<br/>';
  $html .= 'lastname: '.$address->lastname.'<br/>';
  $html .= 'company: '.$address->company.'<br/>';
  $html .= 'address1: '.$address->address1.'<br/>';
  $html .= 'address2: '.$address->address2.'<br/>';
  $html .= 'postcode: '.$address->postcode.'<br/>';
  $html .= 'city: '.$address->city.'<br/>';
  $html .= 'other: '.$address->other.'<br/>';
  $html .= 'phone: '.$address->phone.'<br/>';
  $html .= 'phone_mobile: '.$address->phone_mobile.'<br/>';
  $html .= 'mail: '.$customer->email.'<br/>';
  $html .= 'state: '.$state->name.' - '. $state->iso_code.'<br/>';
  $html .= 'country: '.$country->iso_code.'<br/>';
  
  $html .= '</fieldset>';
  return $html;	  

But I don't find the order total weight.

The only way to get is is to look in the order_detail table and sum the value for each product ordered?

 

Thanks

Link to comment
Share on other sites

done it with:

$q = "	SELECT product_weight
		FROM "._DB_PREFIX_."order_detail 
		 WHERE id_order = " .$params['id_order'];


$r = @mysql_query($q);
	$pesoTot =0;
	$myi=0;
	while (list($ordWhList) = mysql_fetch_row($r)) {

		$pesoTot +=$ordWhList;

		$myi ++;
		
}
  $html .= 'pesoTot: '.$pesoTot.'<br/>';

Is it all right and the best way to get that data?

 

Thanks!

Link to comment
Share on other sites

just a little correction, if someone needs it:

the previous code took the weight for a single unit, if in the cart you have two or more of the same product, it needs the quantity too.

$q = "
		SELECT product_weight, product_quantity
		FROM "._DB_PREFIX_."order_detail 
		 WHERE id_order = " .$params['id_order'];
		
$r = @mysql_query($q);
	$pesoTot =0;
	$myi=0;

while (list($ordWhList, $prQt) = mysql_fetch_row($r)) {
	$pesoTot +=($ordWhList*$prQt);
	$myi ++;
}

Link to comment
Share on other sites

  • 1 month later...

And if I want to bring OrderDetail data having id_order = x

What would have to do?

 

Because if put

$order = new OrderDetail($params['id_order']);

The give me a order detail with id_order_detail = id_order and I want to take OrderDetails where id_order = $params[id_order]

Link to comment
Share on other sites

  • 2 weeks later...

Hello sorry, I try to do your own thing I guess. I want to export data for the LDV courier. I've also created my admin module with hook in order, I can get the data, but I can not use a controller for processing. For example click button etc.. In my folder I created MyModule admin / controller and put the file that overwrites AdminOrderController my controller, but the controller is not found.

Link to comment
Share on other sites

@xabikip

 

Sorry, I don't understand your request.

 

If you need to get order details of an order X rather that the one with order id, in the query, you should replace

$q = "
		SELECT product_weight, product_quantity
		FROM "._DB_PREFIX_."order_detail 
		 WHERE id_order = " .$params['id_order'];

with

$q = "
		SELECT product_weight, product_quantity
		FROM "._DB_PREFIX_."order_detail 
		 WHERE id_order = 123";

(instead of 123 you write the number X you need)

 

But I probably didn't understand your question...

_____

 

@pinarello
I wrote you a previous pm but didn't yet read this one so I didn't understand your question.

My module doesn't  use any button to create a file inside prestashop as it retrieves the data I need and than creates a flash file wich can send that data to my software that elaborates them. And I'm not able to help you with tha controller as I never used one. Anyway contact me if I can help you in some way.

 

Nadia


 

Link to comment
Share on other sites

  • 8 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...