Dynamically link to order page within Magento's admin section

Submitted by metaharper - 5 years ago

This is a custom script I created to redirect a site administrator or customer service rep to Magento's order page within the admin section. You may have noticed a URL namespace similar to the following if you have ever managed an order in the admin section: https://yourstore.com/index.php/admin/sales_order/view/order_id/20345 What you are seeing at the trailing end of the URL is the entity_id from Magento's DB. This script converts an order number to its corresponding entity_id and redirects you - the administrator - to the specified order in the admin panel. To summarize; a link indicating the "human readable" order number (e.g. 100012345) would show either in an email to the site administrator or - in my case - a list of daily orders shown on an ERP webpage. The administrator clicks the order number URL which then passes the order number to this script as a GET URL variable: whatever.com/redirect.php?order=100012345. Javascript then redirects the browser window to Magento's admin panel. Make sense? Please post questions or comments if I need to clarify.

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
$query = 'SELECT entity_id FROM sales_flat_order_grid where increment_id="' . htmlspecialchars($_GET["order"]) . '";';

$result = mysqli_query($con,$query);

echo "
<title>Redirect Script</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />

Please wait...<br />";

while($row = mysqli_fetch_array($result)) {
  echo "<td>" . $row['entity_id'] . "</td>";
  echo '
<script type="text/javascript">
window.location.replace("https://yourstore.com/index.php/admin/sales_order/view/order_id/' . $row['entity_id'] . '");</script>

echo "

Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean