2

Hi Below are the 3 queries i need to convert it into magento queries..

1.

$details = $connection->fetchAll("SELECT sales_order.customer_id , sales_invoice.increment_id , sales_invoice.grand_total , sales_invoice.created_at , sales_order_payment.method FROM sales_order inner join sales_invoice on sales_invoice.order_id = sales_order.entity_id inner join sales_order_payment on sales_order_payment.parent_id = sales_order.entity_id WHERE sales_order.increment_id = '" .$increment_id. "'");

2.

$update_xml_generated = ("INSERT INTO hydrogen_xml_generation (increment_id,xml_generated) VALUES('" .$increment_id. "' , '1')");

3.

$connection->query($update_xml_generated);

Can any body help on this .I don't know how to do it in magento because am a fresher.Thanks in advance.

Piyush
5,9249 gold badges35 silver badges67 bronze badges
asked Sep 18, 2017 at 8:56

1 Answer 1

2

For your first query, As per Magento2 standard, you can inject Sales Collection Factory class,

protected $order;
public function __construct(
.....
\Magento\Sales\Model\OrderFactory $order,
.......
 ) {
 ...
 $this->order = $order;
 ........
 parent::__construct($context, $data);
}

Using this code you can get your order invoice and payment details

public function getInvoiceDetails($order_id){
 $orderdetails = $this->order->loadByIncrementId($increment_id);
 //below will give you payment details
 $payment = $orderdetails->getPayment();
 $orderdetails->getGrandTotal(); //you can get the grandtotal like this
 //below will get all invoices for the order
 foreach ($orderdetails->getInvoiceCollection() as $invoice)
 {
 $invoice_id = $invoice->getIncrementId();
 }
 }

For the second query where you are inserting data in your custom table please follow this answer to save data in custom table from standard Magento way

answered Sep 18, 2017 at 9:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.