36 votes
Accepted

How to create order using REST API?

I finally figured it out. Here is what I'm doing. Get a single product curl -g -X GET "$base_url/index.php/rest/V1/products/24-MB05/" \ -H "Authorization: Bearer $token" Create cart curl -g -X ...
TFS's user avatar
  • 4,319
29 votes
Accepted

Magento 2 How to create new order attribute programatically

Practically, there are two main ways to add an order attribute (a new column) to order via an upgrade script. --Using $setup->getConnection()->addColumn() app/code/Vendor/SalesOrder/Setup/...
Khoa TruongDinh's user avatar
28 votes
Accepted

Sales orders is not displayed in admin panel in grid of Magento2.2.0?

Disable Asynchronous indexing under Store > Configuration > Advance > Developer > Grid Settings Clear cache (optional reindexing) or set up a cron job.
Adnan's user avatar
  • 843
27 votes
Accepted

Magento 2: How to update order status programmatically in custom module?

You can do it like following way declare below namespace use Magento\Sales\Model\Order; $orderId = 1; //Use constructor injection for Order class. Below $objectManager is just for testing/explanation ...
Dhaval Solanki's user avatar
21 votes

Magento 2 : load order by id in customer account order view

Try following way: protected $orderRepository; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Sales\Api\OrderRepositoryInterface $...
Sohel Rana's user avatar
  • 35.8k
18 votes

Add More Mass action in Order grid in magento2

You need to define router for adminhtml in order to get it work with your custom module. You can define the same at app\code{{your_package}}{{your_module}}\etc\adminhtml\routes.xml as like below: ...
Himmat Paliwal's user avatar
18 votes
Accepted

How to Get order increment id using order id in Magento 2

You have to pass \Magento\Sales\Api\OrderRepositoryInterface in construct of your class. protected $orderRepository; public function __construct( ..., \Magento\Sales\Api\...
Bartłomiej Szubert's user avatar
17 votes

Column 'store_id' in where clause is ambiguous when adding custom order attribute to grid and changing store

use below code just before the $this->setCollection($collection); $collection->addFilterToMap('store_id', 'main_table.store_id'); Second Solution edit your column code: if (!Mage::app()->...
Prashant Valanda's user avatar
17 votes
Accepted

How to get email address by order id in Magento 2?

Try this : $order = $this->_objectManager->create('\Magento\Sales\Model\Order')->load($id); $email = $order->getCustomerEmail(); To get Customer Id : $customerId = $order->...
Ashish Jagnani's user avatar
16 votes
Accepted

What's the best event/way to listen for all order state changes in Magento 2?

As far as I know, we can use events: sales_order_save_after and sales_order_state_change_before. I refer sales_order_save_after event. In our observer, we can get the state of order: Observer/...
Khoa TruongDinh's user avatar
16 votes

Magento 2 How to create new order attribute programatically

Magento 2.3.4 do not support above format: Please check below steps to add new attribute to sales_order, quote and sales_invoice tables. Vendor/Module/etc/db_schema.xml <?xml version="1.0"?>...
Hitesh Balpande's user avatar
16 votes

Magento 2: How to update order status programmatically in custom module?

Order state update To update the order state and and status pro-grammatically in order define the status and state in this format. Initiate order object in the construct function and use that order ...
gelanivishal's user avatar
  • 1,336
15 votes

How to adding Custom Attributes to Magento 2 Quotes and Orders

app/code/Vendor/Module/etc/catalog_attributes.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:...
Oscprofessionals's user avatar
13 votes
Accepted

"discount_tax_compensation_amount" attribute in Sales Order Item (Magento 2)

It is used by Magento to calculate the amount of tax that is not originally calculated when a product that has a tax is under discount. For example. Let’s suppose you have a product named “Pencil”. ...
Kavitha mano's user avatar
13 votes
Accepted

Get Customer information from order Magento 2

Inside observer, $order = $observer->getEvent()->getOrder(); $orderFromFront = $order->getRemoteIp(); $guestCustomer = $order->getCustomerIsGuest(); $groupId = $order->...
Rakesh Jesadiya's user avatar
13 votes

sales_order_place_after not triggering in magento 2

sales_order_place_after is not proper,bcoz of it is not fire every time. sales_order_place_after naturally fires whenever call place() of Magento\Sales\Model\Order and it's call depend on payment ...
Amit Bera's user avatar
  • 77.5k
12 votes

Magento 2: How to update order status programmatically in custom module?

Since load() and save() are deprecated now (because :) * @deprecated 100.1.0 because entities must not be responsible for their own loading. * Service contracts should persist entities. Use resource ...
medmek's user avatar
  • 594
12 votes
Accepted

How to get last order status history comment and order status Magento 2

To retrieve latest order's comment history you can do following: $histories = $order->getStatusHistories(); /** @var OrderStatusHistoryInterface $caseCreationComment */ $latestHistoryComment = ...
joni jones's user avatar
  • 2,549
12 votes

Get tracking info from order/shipment object

To get the shipping tracking numbers, use the following code. $tracksCollection = $order->getTracksCollection(); foreach ($tracksCollection->getItems() as $track) { $trackNumbers[] = $...
Muhammad Saeed Khan's user avatar
11 votes

how to display product image in sales/order/view/ page

We shouldn't edit vendor\magento\module-sales\view\frontend\templates\order\items.phtml because the file vendor/magento/module-sales/view/frontend/templates/order/items/renderer/default.phtml is used ...
Khoa TruongDinh's user avatar
11 votes

Magento 2 : load order by id in customer account order view

Declare \Magento\Sales\Api\OrderRepositoryInterface in construct of your class. Try following snippet: protected $orderRepository; public function __construct( \Magento\Sales\Api\...
Ashish Viradiya's user avatar
11 votes
Accepted

Magento 2 Filter not working while Custom column added on Sales Grid Using Ui Component

I have the same issue and $this->addFilterToMap() fix my issue.. check this answer Magento 2 grid uiComponent: include a table alias in a column filter
Emipro Technologies Pvt. Ltd.'s user avatar
11 votes
Accepted

magento 2 - getCreatedAt() returns UTC time and not local time

You can use an instance of Timezone to convert it into store's timezone. Here is a very generic example. namespace VendorName\ModuleName\MyDir; class MyClass { private $timezone; public ...
Maruti N. Sharma's user avatar
11 votes
Accepted

Magento 2 get Orders from last 2 Days

Try below code protected function _prepareLayout() { $searchCriteria = $this->searchCriteriaBuilder ->addFilter('status','pending','eq') ->addSortOrder($this->sortBuilder-&...
Abhishek Panchal's user avatar
11 votes

Get order id by order increment id in Magento 2

You don't need to get the collection of order instead use \Magento\Sales\Model\Spi\OrderResourceInterface to get a single order object use Magento\Sales\Api\Data\OrderInterface; class Mageprince { ...
Prince Patel's user avatar
  • 22.7k
10 votes
Accepted

magento2:unable to save the data in newly added column of sales_order_grid table

Suppose column name 'delivery_date, So that you need to add di.xml for save some value for custom column to grid Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3....
Sohel Rana's user avatar
  • 35.8k
10 votes

Magento 2 - sales_order_place_after not returning Order ID

This is an old question but given I have just faced the same problem myself I thought I would give my take on the answer. sales_order_place_after is triggered before the order is saved to db so at the ...
Andrew Kett's user avatar
  • 3,488
10 votes

Requested entity doesn\'t exist in Magento 2

I had the same error showing on Admin > Sales > Orders when trying to access a list of all orders. It turned out to be a discrepancy between two tables sales_order and sales_order_grid. Some ...
zmish's user avatar
  • 101
10 votes
Accepted

How to rename order shipments name in customer dashboard frontend?

You need to override this file in your module Path: vendor\magento\module-sales\view\frontend\layout\sales_order_info_links.xml Following is the code for that invoice and order shipment links in ...
Muhammad Hasham's user avatar
10 votes
Accepted

Where is "status" located in the database from Magento 2 order grid

Rakesh Donga pointed out the two Queries but more specific queries based on your situation UPDATE sales_order SET state='complete', status='complete' WHERE status = 'processing' UPDATE ...
Muhammad Hasham's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible