diff --git a/app/code/Mindarc/Feed/Config/Converter.php b/app/code/Mindarc/Feed/Config/Converter.php new file mode 100644 index 0000000..cdc02da --- /dev/null +++ b/app/code/Mindarc/Feed/Config/Converter.php @@ -0,0 +1,90 @@ +evaluate('/config/feed'); + /** @var $typeNode \DOMNode */ + foreach ($indexers as $indexerNode) { + $data = []; + $indexerId = $this->getAttributeValue($indexerNode, 'id'); + $data['indexer_id'] = $indexerId; + $data['action_class'] = $this->getAttributeValue($indexerNode, 'class'); + $data['feedprefix'] = ''; + $data['title'] = ''; + $data['description'] = ''; + + /** @var $childNode \DOMNode */ + foreach ($indexerNode->childNodes as $childNode) { + if ($childNode->nodeType != XML_ELEMENT_NODE) { + continue; + } + /** @var $childNode \DOMElement */ + $data = $this->convertChild($childNode, $data); + } + $output[$indexerId] = $data; + } + + return $output; + } + + /** + * Get attribute value + * + * @param \DOMNode $input + * @param string $attributeName + * @param mixed $default + * @return null|string + */ + protected function getAttributeValue(\DOMNode $input, $attributeName, $default = null) + { + $node = $input->attributes->getNamedItem($attributeName); + + return $node ? $node->nodeValue : $default; + } + + /** + * Convert child from dom to array + * + * @param \DOMElement $childNode + * @param array $data + * @return array + */ + protected function convertChild(\DOMElement $childNode, $data) + { + switch ($childNode->nodeName) { + case 'feedprefix': + $data['feedprefix'] = $childNode->nodeValue; + break; + case 'title': + $data['title'] = $childNode->nodeValue; + break; + case 'description': + $data['description'] = $childNode->nodeValue; + break; + } + + return $data; + } +} diff --git a/app/code/Mindarc/Feed/Config/Data.php b/app/code/Mindarc/Feed/Config/Data.php new file mode 100644 index 0000000..a3a4f22 --- /dev/null +++ b/app/code/Mindarc/Feed/Config/Data.php @@ -0,0 +1,31 @@ +urnResolver = $urnResolver; + } + + /** + * Get path to merged config schema + * + * @return string|null + */ + public function getSchema() + { + return $this->urnResolver->getRealPath('urn:magento:module:Mindarc_Feed:etc/feed.xsd'); + } + + /** + * Get path to pre file validation schema + * + * @return string|null + */ + public function getPerFileSchema() + { + return $this->urnResolver->getRealPath('urn:magento:module:Mindarc_Feed:etc/feed.xsd'); + } +} diff --git a/app/code/Mindarc/Feed/Console/Command/FeedGenerator.php b/app/code/Mindarc/Feed/Console/Command/FeedGenerator.php new file mode 100644 index 0000000..b20eb2e --- /dev/null +++ b/app/code/Mindarc/Feed/Console/Command/FeedGenerator.php @@ -0,0 +1,120 @@ +generatorFactory = $generatorFactory; + $this->appState = $appState; + $this->config = $config; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('mindarc:feed') + ->setDescription('Generates the feeds.') + ->setDefinition($this->getInputList()); + } + + /** + * @return array + */ + public function getInputList() : array + { + return [ + new InputArgument( + self::INPUT_KEY_FEEDS, + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'Add feed name.' + ), + ]; + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return null + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL); + foreach ($this->getFeedsArgs($input) as $feedId) { + $feedConfig = $this->config->get($feedId); + if (!empty($feedConfig)) { + $feedGenerator = $this->getFeedGenerator($feedConfig['action_class']); + $feedGenerator->generate($feedConfig['feedprefix']); + } else { + throw new \InvalidArgumentException( + "The requested feed types are not supported: '" + ); + } + } + } + + /** + * @param InputInterface $input + * @return array + */ + protected function getFeedsArgs(InputInterface $input) : array + { + $feedTypes = []; + if ($input->getArgument(self::INPUT_KEY_FEEDS)) { + $requestedTypes = $input->getArgument(self::INPUT_KEY_FEEDS); + $feedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen'); + } + + return $feedTypes; + } + + /** + * @param string $class + * @return \Mindarc\Feed\FeedAdapter\GeneratorInterface + */ + protected function getFeedGenerator(string $class) : \Mindarc\Feed\FeedAdapter\GeneratorInterface + { + return $this->generatorFactory->create($class); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/Cron/FeedGenerator.php b/app/code/Mindarc/Feed/Cron/FeedGenerator.php new file mode 100644 index 0000000..546d620 --- /dev/null +++ b/app/code/Mindarc/Feed/Cron/FeedGenerator.php @@ -0,0 +1,66 @@ +generatorFactory = $generatorFactory; + $this->appState = $appState; + $this->config = $config; + } + + /** + * @return null + */ + protected function execute() + { + $this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL); + $feedConfigs = $this->config->get(); + foreach ($feedConfigs as $feedConfig){ + $feedGenerator = $this->getFeedGenerator($feedConfig['action_class']); + $feedGenerator->generate($feedConfig['feedprefix']); + } + } + + /** + * @param string $class + * @return \Mindarc\Feed\FeedAdapter\GeneratorInterface + */ + protected function getFeedGenerator(string $class) : \Mindarc\Feed\FeedAdapter\GeneratorInterface + { + return $this->generatorFactory->create($class); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/CurrencyService/ServiceAdapter.php b/app/code/Mindarc/Feed/CurrencyService/ServiceAdapter.php new file mode 100644 index 0000000..780e289 --- /dev/null +++ b/app/code/Mindarc/Feed/CurrencyService/ServiceAdapter.php @@ -0,0 +1,90 @@ +client = new Client(['base_uri' => $this->service]); + $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; + } + + /** + * @return string + */ + private function getServiceKey() : string + { + if(!$this->apiKey){ + $this->apiKey = $this->scopeConfig->getValue(self::GEO_RESTRICT_PATH, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->storeManager->getStore()->getId()); + } + return $this->apiKey; + } + + /** + * @param string $from + * @param string $to + * @return Object + */ + public function getCurrency(string $from, string $to) : float + { + /** + * Need Payed service to do real conversion + */ + $arguments = '?access_key=' . $this->getServiceKey() . '&format=1¤cies='.$to; + $response = (string)$this->client->get($arguments)->getBody(); + if ($response) { + $jsonObj = json_decode($response); + if ($jsonObj && !empty($jsonObj->quotes) && isset($jsonObj->quotes->{$from.$to})) { + return $jsonObj->quotes->{$from.$to}; + } + } + return 1; + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/CurrencyService/ServiceHelper.php b/app/code/Mindarc/Feed/CurrencyService/ServiceHelper.php new file mode 100644 index 0000000..52d29c0 --- /dev/null +++ b/app/code/Mindarc/Feed/CurrencyService/ServiceHelper.php @@ -0,0 +1,51 @@ +remoteAddress = $remoteAddress; + $this->serviceAdapter = $serviceAdapter; + } + + /** + * This can be extedted to cache multiple currecy conversion based on future needs + * @return float + */ + public function convertPrice($price) : float + { + if(!isset($this->_cache['USDAUD'])){ + $this->_cache['USDAUD'] = $this->serviceAdapter->getCurrency('USD', 'AUD'); + } + return (float) number_format($price/$this->_cache['USDAUD'], 2); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/FeedAdapter/GeneratorFactory.php b/app/code/Mindarc/Feed/FeedAdapter/GeneratorFactory.php new file mode 100644 index 0000000..c4f443b --- /dev/null +++ b/app/code/Mindarc/Feed/FeedAdapter/GeneratorFactory.php @@ -0,0 +1,52 @@ +_objectManager = $objectManager; + } + + /** + * + * @param string $feedClassName + * @param array $data + * @return \Mindarc\Feed\FeedAdapter\GeneratorInterface + */ + public function create($feedClassName = '', array $data = []) : \Mindarc\Feed\FeedAdapter\GeneratorInterface + { + if (empty($feedClassName)) { + throw new \InvalidArgumentException( + $feedClassName . + 'No Feed Generator Class provided' + ); + } + $feed = $this->_objectManager->create($feedClassName, $data); + if (false == $feed instanceof \Mindarc\Feed\FeedAdapter\GeneratorInterface) { + throw new \InvalidArgumentException( + $feedClassName . + ' doesn\'t implement \Mindarc\Feed\FeedAdapter\GeneratorInterface' + ); + } + + return $feed; + } +} diff --git a/app/code/Mindarc/Feed/FeedAdapter/GeneratorInterface.php b/app/code/Mindarc/Feed/FeedAdapter/GeneratorInterface.php new file mode 100644 index 0000000..53a43e4 --- /dev/null +++ b/app/code/Mindarc/Feed/FeedAdapter/GeneratorInterface.php @@ -0,0 +1,20 @@ +storeRepository = $storeRepository; + $this->storeManager = $storeManager; + $this->scopeConfig = $scopeConfig; + $this->productCollectionFactory = $productCollectionFactory; + $this->productStatus = $productStatus; + $this->productVisibility = $productVisibility; + $this->catalogImageHelper = $catalogImageHelper; + $this->directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $this->serviceHelper = $serviceHelper; + } + + /** + * Generate the Google feed file + * + * @param string $filePrefix + * @return mixed + */ + public function generate(string $filePrefix) + { + foreach ($this->storeRepository->getList() as $store) { + $feedTitle = 'Test Store ' . $store->getName(); + $storeUrl = $store->getCurrentUrl(); + $feedDescription = 'Test Store ' . $store->getName(); + + $collection = $this->productCollectionFactory->create(); + $collection->addAttributeToSelect(['name', 'description', 'price', 'image', 'url']); + $collection->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()]); + $collection->setVisibility($this->productVisibility->getVisibleInSiteIds()); + $collection->addStoreFilter($store); + + foreach ($collection as $product) { + if ($this->reset) { + $fileName = $filePrefix . $store->getCode() . '.xml'; + $this->createFeed($fileName, $feedTitle, $storeUrl, $feedDescription); + } + $this->writeFeedRow($product); + } + $this->finalizeFeed(); + } + } + + /** + * Generate Feed Headers + * + * @param string $fileName + * @param string $title + * @param string $link + * @param string $description + */ + protected function createFeed(string $fileName, string $title, string $link, string $description) + { + $path = $this->getFeedPath(). DIRECTORY_SEPARATOR . $fileName; + $this->stream = $this->directory->openFile($path); + + $fileHeader = '' . + PHP_EOL . + '' . + PHP_EOL; + $fileHeader .= '' . PHP_EOL; + $fileHeader .= '' . htmlspecialchars($title) . '' . PHP_EOL; + $fileHeader .= '' . htmlspecialchars($link) . '' . PHP_EOL; + $fileHeader .= '' . htmlspecialchars($description) . ''; + $this->stream->write($fileHeader); + $this->reset = false; + } + + /** + * Generate Feed contents + * + * @param \Magento\Catalog\Model\Product $product + */ + protected function writeFeedRow(\Magento\Catalog\Model\Product $product) + { + $row = '' . PHP_EOL; + $row .= '' . htmlspecialchars($product->getName()) . '' . PHP_EOL; + $row .= '' . htmlspecialchars($product->getProductUrl()) . '' . PHP_EOL; + $row .= '' . htmlspecialchars($product->getDescription()) . '' . PHP_EOL; + $row .= '' . $this->getProductImage($product) . '' . PHP_EOL; + $row .= '' . $product->getPrice() . '' . PHP_EOL; + $row .= '' . $product->getPrice() . '' . PHP_EOL; + $row .= '' . $this->serviceHelper->convertPrice($product->getPrice()) . '' . PHP_EOL; + $row .= '' . PHP_EOL; + $this->getStream()->write($row); + } + + /** + * Get product image url + * + * @param $product + * @return string + */ + protected function getProductImage(\Magento\Catalog\Model\Product $product) : string + { + return $this->catalogImageHelper + ->init($product, 'product_page_image_large') + ->setImageFile($product->getImage()) + ->getUrl(); + } + + /** + * File stream + * + * @return \Magento\Framework\Filesystem\File\WriteInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function getStream() : \Magento\Framework\Filesystem\File\WriteInterface + { + if ($this->stream) { + return $this->stream; + } else { + throw new \Magento\Framework\Exception\LocalizedException(__('File handler unreachable')); + } + } + + /** + * close the file + */ + protected function finalizeFeed() + { + if ($this->stream) { + $fileFooter = '' . PHP_EOL; + $fileFooter .= ''; + $this->stream->write($fileFooter); + $this->stream->close(); + $this->stream = null; + } + // Reset all counters + $this->reset = true; + } + + /** + * @return string + */ + protected function _getBaseDir(): string + { + return $this->directory->getAbsolutePath(); + } + + /** + * @return string + */ + protected function getFeedPath() : string + { + return $this->scopeConfig->getValue(self::FEED_FOLDER, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->storeManager->getStore()->getId()); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/composer.json b/app/code/Mindarc/Feed/composer.json new file mode 100755 index 0000000..5c11638 --- /dev/null +++ b/app/code/Mindarc/Feed/composer.json @@ -0,0 +1,26 @@ +{ + "name": "mindarc/feed", + "description": "Google Feed Generator", + "type": "magento2-module", + "version": "1.0.1", + "extra": { + "map": [ + [ + "*", + "Mindarc/Feed" + ] + ] + }, + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mindarc\\Feed\\": "" + } + }, + "require": { + "php": "~7.0.0", + "magento/magento-composer-installer": "*" + } +} \ No newline at end of file diff --git a/app/code/Mindarc/Feed/etc/acl.xml b/app/code/Mindarc/Feed/etc/acl.xml new file mode 100644 index 0000000..36e1397 --- /dev/null +++ b/app/code/Mindarc/Feed/etc/acl.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/app/code/Mindarc/Feed/etc/adminhtml/system.xml b/app/code/Mindarc/Feed/etc/adminhtml/system.xml new file mode 100644 index 0000000..9f92e1d --- /dev/null +++ b/app/code/Mindarc/Feed/etc/adminhtml/system.xml @@ -0,0 +1,34 @@ + + + + + + + +
+ separator-top + + mindarc + Mindarc_Feed::config + + + + + Feed folder in /pub/media + + + + + + + Go to https://currencylayer.com to get an API key + + +
+
+
diff --git a/app/code/Mindarc/Feed/etc/config.xml b/app/code/Mindarc/Feed/etc/config.xml new file mode 100644 index 0000000..e0ca875 --- /dev/null +++ b/app/code/Mindarc/Feed/etc/config.xml @@ -0,0 +1,16 @@ + + + + + + + feed + + + + \ No newline at end of file diff --git a/app/code/Mindarc/Feed/etc/crontab.xml b/app/code/Mindarc/Feed/etc/crontab.xml new file mode 100644 index 0000000..a92fbd1 --- /dev/null +++ b/app/code/Mindarc/Feed/etc/crontab.xml @@ -0,0 +1,14 @@ + + + + + + 0 0 * * * + + + diff --git a/app/code/Mindarc/Feed/etc/di.xml b/app/code/Mindarc/Feed/etc/di.xml new file mode 100644 index 0000000..408c00a --- /dev/null +++ b/app/code/Mindarc/Feed/etc/di.xml @@ -0,0 +1,31 @@ + + + + + + + Mindarc\Feed\Console\Command\FeedGenerator + + + + + + Mindarc\Feed\Config\Converter + Mindarc\Feed\Config\SchemaLocator + feed.xml + + id + + + + + + Mindarc\Feed\Config\Reader + + + diff --git a/app/code/Mindarc/Feed/etc/feed.xml b/app/code/Mindarc/Feed/etc/feed.xml new file mode 100644 index 0000000..9c704ab --- /dev/null +++ b/app/code/Mindarc/Feed/etc/feed.xml @@ -0,0 +1,14 @@ + + + + + google + Google Feed Generator + Generate google feeds to each Magento stores + + diff --git a/app/code/Mindarc/Feed/etc/feed.xsd b/app/code/Mindarc/Feed/etc/feed.xsd new file mode 100644 index 0000000..422756b --- /dev/null +++ b/app/code/Mindarc/Feed/etc/feed.xsd @@ -0,0 +1,83 @@ + + + + + + + Feed declaration. + + + + + + + + + + + + + + + + + + + + + + + + + Class name can contain only [a-zA-Z\]. + + + + + + + + + + + + Feed Id must be unique. + + + + + + + + + Feed Id must be unique. + + + + + + + + + + + + + + + + + + Fieldset name must be unique. + + + + + + + diff --git a/app/code/Mindarc/Feed/etc/module.xml b/app/code/Mindarc/Feed/etc/module.xml new file mode 100755 index 0000000..c00f00e --- /dev/null +++ b/app/code/Mindarc/Feed/etc/module.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/code/Mindarc/Feed/registration.php b/app/code/Mindarc/Feed/registration.php new file mode 100755 index 0000000..d4d08ed --- /dev/null +++ b/app/code/Mindarc/Feed/registration.php @@ -0,0 +1,11 @@ +response = $response; + parent::__construct($context); + } + + /** + * @param null $coreRoute + * @return \Magento\Framework\App\ResponseInterface + */ + public function execute($coreRoute = null) : \Magento\Framework\App\ResponseInterface + { + $this->response->setHttpResponseCode('404'); + $this->response->setBody('Access Forbidden'); + + return $this->response; + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/GeoService/ServiceAdapter.php b/app/code/Mindarc/GeoRestriction/GeoService/ServiceAdapter.php new file mode 100644 index 0000000..c891345 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/GeoService/ServiceAdapter.php @@ -0,0 +1,85 @@ +client = new Client(['base_uri' => $this->service]); + $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; + } + + /** + * @return string + */ + private function getServiceKey() : string + { + if(!$this->apiKey){ + $this->apiKey = $this->scopeConfig->getValue(self::GEO_RESTRICT_PATH, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->storeManager->getStore()->getId()); + } + return $this->apiKey; + } + + /** + * @param string $ip + * @return string + */ + public function getCountryByIP(string $ip) : string + { + $arguments = '?access_key=' . $this->getServiceKey() . '&output=json'; + $response = (string)$this->client->get(urlencode($ip) . $arguments)->getBody(); + if ($response) { + $jsonObj = json_decode($response); + if ($jsonObj && !empty($jsonObj->country_code)) { + return $jsonObj->country_code; + } + } + return ''; + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/GeoService/ServiceHelper.php b/app/code/Mindarc/GeoRestriction/GeoService/ServiceHelper.php new file mode 100644 index 0000000..0f082e8 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/GeoService/ServiceHelper.php @@ -0,0 +1,46 @@ +remoteAddress = $remoteAddress; + $this->serviceAdapter = $serviceAdapter; + } + + /** + * @return string + */ + public function getUserCountry() : string + { + $userIp = $this->remoteAddress->getRemoteAddress(); + return $this->serviceAdapter->getCountryByIP($userIp); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/Observer/RestrictContentByCountryObserver.php b/app/code/Mindarc/GeoRestriction/Observer/RestrictContentByCountryObserver.php new file mode 100644 index 0000000..0bb0a91 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/Observer/RestrictContentByCountryObserver.php @@ -0,0 +1,91 @@ +serviceHelper = $serviceHelper; + $this->responseFactory = $responseFactory; + $this->scopeConfig = $scopeConfig; + $this->storeManager = $storeManager; + $this->actionFlag = $actionFlag; + } + + /** + * Check user country and restrict access + * + * @param EventObserver $observer + * @return RestrictContentByCountryObserver + */ + public function execute(EventObserver $observer) : RestrictContentByCountryObserver + { + if ($observer->getRequest()->getModuleName() != 'admin' && + strpos($observer->getRequest()->getUriString(), 'geo-restrict/restrict/error') !== true) { + $restrictCountries = $this->scopeConfig->getValue(self::GEO_RESTRICT_PATH, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->storeManager->getStore()->getId()); + $restrictCountriesArr = explode(',', $restrictCountries); + if (!empty($restrictCountries) && in_array($this->serviceHelper->getUserCountry(), $restrictCountriesArr) + ) { + $this->responseFactory->create()->setRedirect('geo-restrict/restrict/error')->sendResponse(); + } + } + + return $this; + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/Setup/UpgradeData.php b/app/code/Mindarc/GeoRestriction/Setup/UpgradeData.php new file mode 100644 index 0000000..b5c5046 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/Setup/UpgradeData.php @@ -0,0 +1,70 @@ +blockRepository = $blockRepository; + $this->blockInterfaceFactory = $blockInterfaceFactory; + } + + /** + * {@inheritdoc} + */ + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + + $setup->startSetup(); + + if (version_compare($context->getVersion(), '1.1.0') < 0) { + $usBlock = $this->blockInterfaceFactory->create()->setTitle('US Block') + ->setIdentifier('us-block') + ->setContent('US Block Content') + ->setIsActive(1)->setStores([\Magento\Store\Model\Store::DEFAULT_STORE_ID]); + + $this->blockRepository->save($usBlock); + + $globalBlock = $this->blockInterfaceFactory->create()->setTitle('Global Block') + ->setIdentifier('global-block') + ->setContent('Global Block Content') + ->setIsActive(1)->setStores([\Magento\Store\Model\Store::DEFAULT_STORE_ID]); + + $this->blockRepository->save($globalBlock); + } + + $setup->endSetup(); + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/ViewModel/GeoBlock.php b/app/code/Mindarc/GeoRestriction/ViewModel/GeoBlock.php new file mode 100644 index 0000000..003e578 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/ViewModel/GeoBlock.php @@ -0,0 +1,67 @@ +serviceHelper = $serviceHelper; + $this->blockRepository = $blockRepository; + } + + /** + * @return string + */ + public function getUserCountry() : string + { + if (!$this->userCountry) { + $this->userCountry = $this->serviceHelper->getUserCountry(); + } + return $this->userCountry; + } + + /** + * @return bool + */ + public function isCountryUs() : bool + { + return $this->getUserCountry() == 'US'; + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/composer.json b/app/code/Mindarc/GeoRestriction/composer.json new file mode 100755 index 0000000..0343136 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/composer.json @@ -0,0 +1,27 @@ +{ + "name": "mindarc/geo-restriction", + "description": "Geo Restriction", + "type": "magento2-module", + "version": "1.0.1", + "extra": { + "map": [ + [ + "*", + "Mindarc/GeoRestriction" + ] + ] + }, + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Mindarc\\Feed\\": "" + } + }, + "require": { + "php": "~7.0.0", + "magento/magento-composer-installer": "*", + "divineomega/php-geolocation": "*" + } +} \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/etc/acl.xml b/app/code/Mindarc/GeoRestriction/etc/acl.xml new file mode 100644 index 0000000..8dada3a --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/acl.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/app/code/Mindarc/GeoRestriction/etc/adminhtml/system.xml b/app/code/Mindarc/GeoRestriction/etc/adminhtml/system.xml new file mode 100644 index 0000000..0604f15 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/adminhtml/system.xml @@ -0,0 +1,29 @@ + + + + + + + +
+ separator-top + + mindarc + Mindarc_GeoRestriction::config + + + + Go to https://ipstack.com/ to get an API key + + + + + +
+
+
diff --git a/app/code/Mindarc/GeoRestriction/etc/config.xml b/app/code/Mindarc/GeoRestriction/etc/config.xml new file mode 100644 index 0000000..fe832f5 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/config.xml @@ -0,0 +1,16 @@ + + + + + + + RU,CN + + + + \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/etc/events.xml b/app/code/Mindarc/GeoRestriction/etc/events.xml new file mode 100644 index 0000000..77d7ede --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/events.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/etc/frontend/routes.xml b/app/code/Mindarc/GeoRestriction/etc/frontend/routes.xml new file mode 100644 index 0000000..f85dafe --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/frontend/routes.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Mindarc/GeoRestriction/etc/module.xml b/app/code/Mindarc/GeoRestriction/etc/module.xml new file mode 100755 index 0000000..d28f893 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/etc/module.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/code/Mindarc/GeoRestriction/registration.php b/app/code/Mindarc/GeoRestriction/registration.php new file mode 100755 index 0000000..2c18364 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/registration.php @@ -0,0 +1,11 @@ + + + + + + + + Mindarc\GeoRestriction\ViewModel\GeoBlock + + + + + diff --git a/app/code/Mindarc/GeoRestriction/view/frontend/templates/geoblock.phtml b/app/code/Mindarc/GeoRestriction/view/frontend/templates/geoblock.phtml new file mode 100644 index 0000000..a1fa8b1 --- /dev/null +++ b/app/code/Mindarc/GeoRestriction/view/frontend/templates/geoblock.phtml @@ -0,0 +1,14 @@ +getData('viewModel'); +?> +

getUserCountry());?>

+ +

+isCountryUs()):?> + getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('us-block')->toHtml();?> + + getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('global-block')->toHtml() ?> + +

diff --git a/app/code/modules_here.txt b/app/code/modules_here.txt deleted file mode 100644 index 8b4e938..0000000 --- a/app/code/modules_here.txt +++ /dev/null @@ -1 +0,0 @@ -Create your modules in here