Hot answers tagged

7

Use below code: protected $logger; protected $objectManager; protected $_curl; public function __construct( \Psr\Log\LoggerInterface $logger, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\HTTP\Client\Curl $curl) { $this->logger = $logger; $this->_curl = $curl; $this-...


5

Use StoreManagerInterface to set current store. You can use observer to do so. /** * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManagerInterface; //Inject your class public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManagerInterface ) { $this->_storeManagerInterface = $storeManagerInterface; ...


5

There are multiple approaches how you can do this without editing magento code (webserver level, for example). These approaches might be more efficient. But if you want to do it with magento, your $resultRedirect should be returned to App\Http. Your observer does not return $resultRedirect, so it is not processed by \Magento\Framework\App\Http::launch and ...


3

The only trick is identifying the source of the traffic, using the paid-for GeoIP database from MaxMind will give you the granular detail you need for city-level identification. Once you've got GeoIP configured, you would just make a CMS page to suit for each location, and have the server perform a rewrite to handle it. Eg. For a homepage redirect for ...


3

I did not test this solution yet, but I think it should work: class Atwix_Ipstoreswitcher_Model_Observer { /** * redirects customer to store view based on GeoIP * @param $event */ public function controllerActionPostdispatch($event) { /** @var Mage_Customer_Model_Session $session */ $session = Mage::getSingleton('...


2

You can try another event controller_front_send_response_before


2

I got my answer following below code: I have created observer for this. MagentoDir/Shasha/Geoip/etc/frontend/events.xml <config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='urn:magento:framework/Event/etc/events.xsd'> <event name='controller_action_predispatch'> <observer name='...


2

Try to using a plugin that overwrites country list with your specific country list. I have used hard-coded country here, you need to add your logic here. app/code/SR/MagentoCommunity/etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:...


2

These are the steps to do: 1. Redirects can be done in the following way: $observer->getControllerAction()->getResponse()>setRedirect($redirectUrl); 2. The best solution, perhaps, will be to use the controller_action_predispatch (as there are unfortunately no other, more suitable events). 3. In the same observer you can also set up ...


2

Okay seems like I got it working after struggling. In our case we always redirect the first visitor to the correct store. Redirect directly from Varnish. No bypassing. It is super messy but if anyone got a better solution feel free to post it here. Install Varnish GeoIP Module https://rageagainstshell.com/2016/05/geoip-location-in-varnish/ Make sure to ...


1

Use following event which work when FPC enabled: controller_front_send_response_before or you can go with JS implementation.


1

You are doing it correctly, the issue that you are facing is may be due to localhost. Try above code by passing hard codded IP for testing purpose, like this: $geoplugin = new geoPlugin(); $yourIp = "206.189.146.36"; $geoplugin->locate(); if ($geoplugin->countryCode) { $_SESSION['cCode'] = $geoplugin->countryCode; } else { $_SESSION['cCode'...


1

You can do this by setting cacheable attribute false in layout XML files. <block class="Block\Class" name="blockname" cacheable="false" /> You can also check this link How do disable caching of custom block on product view page?


1

Try this: protected function _construct() { $this->addData( [ 'cache_lifetime' => false, 'cache_tags' => ['Rokanthemes_Themeoption', \Magento\Store\Model\Group::CACHE_TAG], ] ); } OR Add below function in your block file public function getCacheLifetime() { return false; } OR Set cacheable ...


1

You need to create plugin for check on every request create di.xml file in your custom module <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <type name="Magento\Framework\App\...


1

We hit the same issue, when trying to apply the suggested "Block Sucuri Bypass" location / { # Block everything that isn't sucuri allow 192.88.134.0/23; allow 185.93.228.0/22; allow 2a02:fe80::/29; allow 66.248.200.0/22; deny all; # other nginx config } As this was below the already configured: # Define header with original ...


1

For all those who come across the same issue and try to get an answer from sucuri or hopeless hosting providers like siteground, this is what worked for me. I put the following code at the very beginning of Magento index.php: if(isset($_SERVER['HTTP_X_SUCURI_CLIENTIP'])) { $_SERVER["REMOTE_ADDR"] = $_SERVER['HTTP_X_SUCURI_CLIENTIP'];


1

You will need to add the composer autoloader (vendor/autoload.php) and register it before the Magento autoloader. That's important because the Magento autoloader will try to include the file where it expects the class to be which throws an error if that file does not exist. So later autoloaders do not have a chance at all. There are some open source ...


1

This should do the trick for you: <?php require_once $_SERVER['DOCUMENT_ROOT'] . 'vendor/autoload.php'; use GeoIp2\Database\Reader; class Testmodule_Currency_Model_Store extends Mage_Core_Model_Store { public function getDefaultCurrencyCode() { $reader = new Reader($_SERVER['DOCUMENT_ROOT'] . 'vendor/GeoLite2-Country_20171205/GeoLite2-...


1

I have implemented what I think is the best over-engineered solution, at least for our use case. We are not using Amasty's Geo-IP Redirect. Instead we chose to develop our own custom solution which probably ended up being quite similar. Plugin to frontend controller dispatch method I'm guessing? Our use case We run multiple websites, each with a single ...


1

you have probably only few options: use geoip mod and custom varnish config to pass proper geoip hash to backend. use "VCL Fix = on" in Turpentine settings, it will bypass request if no cookies or magento session. (caution: high load) set all geoip cookies and variables with javascript on client side. better to use option 1. but in different ...


1

Sure. The homepage is just a CMS page, therefore you can create a second one. Then you need some way to distinguish between the customers. I don't know whether geoIP can do this for US, but with a commercial database I think this is possible. So yo can just redirect the customers from one city to the one page and the others to another page. All others maybe ...


1

Use around plugin on \Magento\Framework\App\FrontControllerInterface::dispatch method and do redirect without call dispatch method.


1

Well, to do that you will need a GeoIp module. A good resource can be found here: https://www.atwix.com/magento/geoip-magento-store-switcher/ First you'll have to install the GitHub module: https://github.com/tim-bezhashvyly/Sandfox_GeoIP Then you will have to synchronize the IP database under System Configuration->General->Countries Options From that ...


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