Tracking Frontend vs Backend Purchases in Magento
In Magento, discerning whether an order was placed through the frontend of your website or manually entered via the administrative panel can be crucial for auditing and analytics purposes. Fortunately, Magento provides a way to distinguish these two types of orders using specific attributes.
Understanding Order Creation Methods
When an order is created through the frontend (customer checkout), it follows the standard customer-initiated checkout process. On the other hand, backend orders are manually created by an administrator or via API.
Identifying Frontend Orders
To determine if an order was placed through the frontend, look for specific Magento attribute values:
-
Order Status: By default, frontend orders have a status of “pending” or “processing”. Manual/Backend orders typically start with statuses like “holded”.
-
Remote IP: The
remote_ipfield in the sales_order table contains the customer’s public IP address for frontend orders. -
Customer ID (Customer Entity ID): Customer-initiated orders contain a non-zero value in this field.
Here’s how you can fetch frontend orders using Magento’s API or SQL queries:
Using Magento API
You can use the Magento REST API to fetch order data with specific criteria, such as customer entity ID not being zero. Here’s an example of fetching frontend orders using cURL and the REST API:
curl -X GET "http://yourstore.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=customer_id&searchCriteria[filter_groups][0][filters][0][value]=!0" -H "Content-Type: application/json" -H "Authorization: Bearer your_token"
Replace yourstore.com with your domain and your_token with a valid admin token.
Using SQL Queries
Alternatively, you can directly query the Magento database to find frontend orders:
SELECT * FROM sales_order WHERE customer_id != 0;
Identifying Backend Orders
Backend orders have certain common characteristics:
- Order Status: “holded”, “canceled”, or other non-standard statuses.
- Remote IP: Often displays as ‘::1’ (localhost) for admin-initiated orders.
- Customer ID: Zero, indicating a guest checkout or manual creation.
Conclusion
Distinguishing frontend from backend purchases in Magento is essential for understanding your business’s order flow and ensuring data integrity. By examining the order status, remote IP address, and customer entity ID, you can effectively identify and filter these two types of orders.
Remember to always use official documentation ( https://laravelcompany.com/magento-documentation ) as a reference for API endpoints and attribute descriptions when working with Magento’s core functionality.