Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerioms committed Apr 6, 2018
0 parents commit f50d92b
Show file tree
Hide file tree
Showing 28 changed files with 1,346 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Block/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) Intelipost
* @author Alex Restani <[email protected]>
*/

namespace Intelipost\Autocomplete\Block;

class Create extends \Magento\Framework\View\Element\Template
{

protected $_scopeConfig;

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
$this->setTemplate('create.phtml');

parent::__construct($context);
$this->_scopeConfig = $scopeConfig;
}

public function getLoadPageTime()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/settings/load_page_time');
}

public function getCustomState()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer_create/create_custom_state');
}

public function getCustomCity()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer_create/create_custom_city');
}

public function getCustomStreet()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer_create/create_custom_street');
}

public function getCustomQuarter()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer_create/create_custom_quarter');
}

public function getCustomAdditionalInfo()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer_create/create_custom_additional_info');
}

}
56 changes: 56 additions & 0 deletions Block/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) Intelipost
* @author Alex Restani <[email protected]>
*/

namespace Intelipost\Autocomplete\Block;

class Customer extends \Magento\Framework\View\Element\Template
{

protected $_scopeConfig;

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
$this->setTemplate('customer.phtml');

parent::__construct($context);
$this->_scopeConfig = $scopeConfig;
}

public function getLoadPageTime()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/settings/load_page_time');
}

public function getCustomState()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer/custom_state');
}

public function getCustomCity()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer/custom_city');
}

public function getCustomStreet()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer/custom_street');
}

public function getCustomQuarter()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer/custom_quarter');
}

public function getCustomAdditionalInfo()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_customer/custom_additional_info');
}

}
58 changes: 58 additions & 0 deletions Block/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

namespace Intelipost\Autocomplete\Block;

class Order extends \Magento\Framework\View\Element\Template
{

protected $_scopeConfig;

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
$this->setTemplate('order.phtml');

parent::__construct($context);
$this->_scopeConfig = $scopeConfig;
}

public function getLoadPageTime()
{
$time = $this->_scopeConfig->getValue('intelipost_autocomplete/settings/load_page_time');
return $time;
}

public function getCustomState()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_checkout/checkout_custom_state');
}

public function getCustomCity()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_checkout/checkout_custom_city');
}

public function getCustomStreet()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_checkout/checkout_custom_street');
}

public function getCustomQuarter()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_checkout/checkout_custom_quarter');
}

public function getCustomAdditionalInfo()
{
return $this->_scopeConfig->getValue('intelipost_autocomplete/custom_fields_checkout/checkout_custom_additional_info');
}

}

29 changes: 29 additions & 0 deletions Block/Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

namespace Intelipost\Autocomplete\Block;

class Url extends \Magento\Framework\View\Element\Template
{

public function __construct(
\Magento\Framework\View\Element\Template\Context $context
)
{
$this->setTemplate('url.phtml');

parent::__construct($context);
}

public function getAjaxUrl()
{
return $this->getUrl('intelipost_autocomplete/search/index');
}

}


41 changes: 41 additions & 0 deletions Controller/Adminhtml/Search/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

namespace Intelipost\Autocomplete\Controller\Adminhtml\Search;

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

protected $_autocompleteHelper;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Intelipost\Autocomplete\Helper\Api $autocompleteHelper
)
{
$this->_autocompleteHelper = $autocompleteHelper;

parent::__construct ($context);
}

public function execute()
{
$postcode = $this->getRequest()->getParam('postcode');
$postcode = preg_replace ('#[^0-9]#', "", $postcode);
if (empty ($postcode) || strlen ($postcode) != 8) return;

$result = $this->_autocompleteHelper->getCEPLocationAddressComplete ($postcode);
if (!$result || !is_array ($result)) return;

if (array_key_exists ('content', $result))
{
$this->getResponse()->setBody(json_encode ($result ['content']));
}
}

}

26 changes: 26 additions & 0 deletions Controller/Search/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

namespace Intelipost\Autocomplete\Controller\Search;

class Index extends \Intelipost\Autocomplete\Controller\Adminhtml\Search\Index
{

protected $_autocompleteHelper;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Intelipost\Autocomplete\Helper\Api $autocompleteHelper
)
{
$this->_autocompleteHelper = $autocompleteHelper;

parent::__construct ($context, $autocompleteHelper);
}

}

37 changes: 37 additions & 0 deletions Helper/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

namespace Intelipost\Autocomplete\Helper;

class Api extends \Intelipost\Basic\Helper\Api
{

const AUTOCOMPLETE_CEP_LOCATION_ADDRESS_COMPLETE = 'cep_location/address_complete/';

protected $_scopeConfig;

public function __construct
(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
$this->_scopeConfig = $scopeConfig;

parent::__construct($scopeConfig);
}

public function getCEPLocationAddressComplete ($destPostcode)
{
$response = $this->apiRequest (self::GET, self::AUTOCOMPLETE_CEP_LOCATION_ADDRESS_COMPLETE . "{$destPostcode}");

$result = json_decode ($response, true);

return $result;
}

}

34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "intelipost/magento2-autocomplete",
"description": "Intelipost Autocomplete",
"type": "magento2-module",
"version": "1.0.0",
"authors": [
{
"name": "Intelipost",
"email": "[email protected]",
"homepage": "http://www.intelipost.com.br/"
},
{
"name": "Eneias Ramos de Melo",
"email": "[email protected]",
"homepage": "http://www.gamuza.com.br/"
}
],
"license": [
"OSL-3.0"
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"intelipost/magento2-basic": "1.*"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Intelipost\\Autocomplete\\": ""
}
}
}

17 changes: 17 additions & 0 deletions etc/adminhtml/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
/*
* @package Intelipost_Autocomplete
* @copyright Copyright (c) 2016 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/
-->

<config>
<router id="admin">
<route id="intelipost_autocomplete" frontName="intelipost_autocomplete">
<module name="Intelipost_Autocomplete" />
</route>
</router>
</config>

Loading

0 comments on commit f50d92b

Please sign in to comment.