1

In Magento 2 I am attempting to setup a controller I can retrieve after page load via Ajax that does not register as a URL in the admin panel for "Customers>Now Online"

I have a route.xml setup as

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..
/../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="mymodule" frontName="mymodule">
            <module name="Testing_Mymodule" />
        </route>
    </router>
</config>

And a controller such as:

namespace Testing\Mymodule\Controller\Index;


class Index extends \Magento\Framework\App\Action\Action
{


    public function execute()
    {
        $jsonData = json_encode(array('test1', 'test2', 'test3'));
        $this->getResponse()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody($jsonData);
    }
}

This results in a json result of the json array. Now if one checks the "Customers>Now Online" It shows the controller as the last URL visited. Is there a way to access this controller without registering the URL.

| improve this question | | | | |
  • do you have a module.xml in your module? Did you clear the cache? How are you calling your url? – Marius Aug 21 '15 at 6:14
  • Marius, yes the module is appearing and I can connect to the controller. What I am trying to achieve is a controller that I can connect to via Ajax that doesn't change the customers "Now Online" URL – Eirik Aug 21 '15 at 15:03
  • I can access the controller via the domain.com/mymodule and it returns that json array. However, it is registering this as the last visited page for the customer in the "Customers>Now Online" report – Eirik Aug 21 '15 at 15:04
1

I took a look through the \Magento\Customer\Model\Visitor model and it seams that you can skip the loging for certain user agents and for certain modules. (check the initByRequest method).
By the looks of the method isModuleIgnored, the one that checks if a module should be skipped you may be able to ignore the logging for your module by adding this, in the di.xml of your module:

<type name="Magento\Customer\Model\Visitor">
    <arguments>
        <argument name="ignores" xsi:type="array">
            <item name="the_route_name_of_your_module" xsi:type="bool">true</item>
        </argument>
    </arguments>
</type>

But I didn't test it.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.