cancel
Showing results for 
Search instead for 
Did you mean: 

Create a filter off remote_ip

SOLVED

Create a filter off remote_ip

Our Customer Service Dept uses the Magento back end to place phone orders, therefor sales_flat_order.remote_ip = NULL for such orders, and all other "real" orders have a logged IP Address.  Yet I can not find any way to interact with sales_flat_order.remote_ip .  Any help?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Create a filter off remote_ip

Hi Kevin,

When you say you can't find any way to interact with sales_flat_order.remote_ip, do you mean you don't have access to the remote_ip column when building reports?

If you're a Magento BI Pro subscriber, you'll most likely just need to track this column in your sales_flat_order table using your Data Warehouse manager. After tracking the column, you can add it to your metrics so that it will be available as a filter and group by in reports.

If you're a Magento BI Essentials subscriber, the remote_ip is not included with the preset selection of tables and fields that come with your subscription. Typically tracking additional tables and columns would require upgrading to Pro. However I recommend you send an email to support@rjmetrics.com to determine whether or not it is possible to include this field for your particular Essentials subscription.

Hope this helps!
Chris

Chris Schmid
Sr. Product Analyst
Adobe

View solution in original post

2 REPLIES 2

Re: Create a filter off remote_ip

Hi Kevin,

When you say you can't find any way to interact with sales_flat_order.remote_ip, do you mean you don't have access to the remote_ip column when building reports?

If you're a Magento BI Pro subscriber, you'll most likely just need to track this column in your sales_flat_order table using your Data Warehouse manager. After tracking the column, you can add it to your metrics so that it will be available as a filter and group by in reports.

If you're a Magento BI Essentials subscriber, the remote_ip is not included with the preset selection of tables and fields that come with your subscription. Typically tracking additional tables and columns would require upgrading to Pro. However I recommend you send an email to support@rjmetrics.com to determine whether or not it is possible to include this field for your particular Essentials subscription.

Hope this helps!
Chris

Chris Schmid
Sr. Product Analyst
Adobe

Re: Create a filter off remote_ip

Hi @kevin_t_irish,

 

In Magento 2, the remote_ip field in the sales_order table is used to store the IP address of the customer when an order is placed. However, it is not always populated for orders placed via the admin backend or other non-web channels, like phone orders.

 

If you want to track or interact with IP addresses for orders placed through the admin backend, you might consider customizing your Magento instance. Here are some options:

 

  • Custom Attribute: Create a custom attribute to store the IP address for orders placed through the admin. This would involve creating a new column in the sales_order table or creating a separate table to store the additional information.
  • Observer: Use an event observer to capture the IP address when an order is placed via the admin backend. You can create an observer for the sales_order_place_after event, which is triggered after an order is placed. In the observer, you can retrieve the IP address and update the order accordingly.

Here's an example of how you might approach this:

// app/code/Vendor/Module/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_place_after">
        <observer name="update_order_ip" instance="Vendor\Module\Observer\UpdateOrderIp" />
    </event>
</config>

// app/code/Vendor/Module/Observer/UpdateOrderIp.php
<?php
namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
use Magento\Sales\Api\OrderRepositoryInterface;

class UpdateOrderIp implements ObserverInterface
{
    protected $orderRepository;
    protected $remoteAddress;

    public function __construct(
        OrderRepositoryInterface $orderRepository,
        RemoteAddress $remoteAddress
    ) {
        $this->orderRepository = $orderRepository;
        $this->remoteAddress = $remoteAddress;
    }

    public function execute(Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();

        // Check if the order is placed via the admin
        if ($order->getRemoteIp() === null) {
            // Get the current IP address dynamically
            $ipAddress = $this->remoteAddress->getRemoteAddress();

            // Update the order with the IP address
            $order->setRemoteIp($ipAddress);
            $this->orderRepository->save($order);
        }
    }
}

If the issue will be resolved, Click Kudos & Accept as a Solution.