init module
This commit is contained in:
		
							parent
							
								
									e42620c625
								
							
						
					
					
						commit
						867e553946
					
				|  | @ -0,0 +1,86 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace IpSupply\SyncOrder\Api; | ||||||
|  | 
 | ||||||
|  | use IpSupply\SyncOrder\Api\RepositoryInterface; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @api | ||||||
|  |  */ | ||||||
|  | class Repository implements RepositoryInterface | ||||||
|  | { | ||||||
|  |     function __construct() | ||||||
|  |     { | ||||||
|  |         $this->authorization(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function authorization() | ||||||
|  |     { | ||||||
|  |         $headers = apache_request_headers(); | ||||||
|  |         $apiKey = \IpSupply\SyncOrder\Helper::API_KEY; | ||||||
|  | 
 | ||||||
|  |         foreach ($headers as $key => $value) { | ||||||
|  |             $key = strtolower($key); | ||||||
|  |             if ('api_key' === $key && $value === $apiKey) { | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         header('HTTP/1.1 401 Unauthorized'); | ||||||
|  |         header('Accept: application/json'); | ||||||
|  |         header('Content-Type: application/json'); | ||||||
|  |         die(json_encode(['message' => 'unauthorized'])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function _responseOk(array $data) | ||||||
|  |     { | ||||||
|  |         header('HTTP/1.1 200 Ok'); | ||||||
|  |         header('Accept: application/json'); | ||||||
|  |         header('Content-Type: application/json'); | ||||||
|  |         die(json_encode($data)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function _responseFail(array $data) | ||||||
|  |     { | ||||||
|  |         header('HTTP/1.1 400 Bad request'); | ||||||
|  |         header('Accept: application/json'); | ||||||
|  |         header('Content-Type: application/json'); | ||||||
|  |         die(json_encode($data)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function _responseMethodFail() | ||||||
|  |     { | ||||||
|  |         header('HTTP/1.1 400 bad request'); | ||||||
|  |         header('Accept: application/json'); | ||||||
|  |         header('Content-Type: application/json'); | ||||||
|  |         die(json_encode([ | ||||||
|  |             'status' => false, | ||||||
|  |             'message' => 'Param ?method=... not exist!' | ||||||
|  |         ])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getData() | ||||||
|  |     { | ||||||
|  |         return $this->_responseOk([ | ||||||
|  |             'status' => true, | ||||||
|  |             'data' => [] | ||||||
|  |         ]); | ||||||
|  |         // return $this->_responseMethodFail();
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function postData() | ||||||
|  |     { | ||||||
|  |         parse_str( | ||||||
|  |             string: file_get_contents('php://input'), | ||||||
|  |             result: $payload | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |         return $this->_responseOk([ | ||||||
|  |             'status' => true, | ||||||
|  |             'data' => [], // TODO
 | ||||||
|  |             'payload' => $payload | ||||||
|  |         ]); | ||||||
|  | 
 | ||||||
|  |         // return $this->_responseMethodFail();
 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,23 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace IpSupply\SyncOrder\Api; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @api | ||||||
|  |  */ | ||||||
|  | interface RepositoryInterface | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * method: GET | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public function getData(); | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * methot: POST | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public function postData(); | ||||||
|  | } | ||||||
|  | @ -0,0 +1,29 @@ | ||||||
|  | <?php | ||||||
|  | namespace IpSupply\SyncOrder\Block\Adminhtml; | ||||||
|  | 
 | ||||||
|  | use Magento\Backend\Block\Template; | ||||||
|  | 
 | ||||||
|  | class Config extends Template | ||||||
|  | { | ||||||
|  |     protected $urlInterface; | ||||||
|  | 
 | ||||||
|  |     public function __construct( | ||||||
|  |         \Magento\Backend\Block\Template\Context $context, | ||||||
|  |         \Magento\Backend\Model\UrlInterface $urlInterface, | ||||||
|  |         $data = [] | ||||||
|  |     ) | ||||||
|  |     { | ||||||
|  |         $this->urlInterface = $urlInterface; | ||||||
|  |         parent::__construct($context, $data); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getSecretKey() | ||||||
|  |     { | ||||||
|  |         return $this->urlInterface->getSecretKey(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getApiKey() | ||||||
|  |     { | ||||||
|  |         return \IpSupply\SyncOrder\Helper::API_KEY; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,27 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace IpSupply\SyncOrder\Controller\Adminhtml\Config; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Index extends \Magento\Backend\App\Action | ||||||
|  | { | ||||||
|  |     protected $resultPageFactory = false; | ||||||
|  |     public function __construct( | ||||||
|  |         \Magento\Backend\App\Action\Context $context, | ||||||
|  |         \Magento\Framework\View\Result\PageFactory $resultPageFactory | ||||||
|  |     ) { | ||||||
|  |         parent::__construct($context); | ||||||
|  |         $this->resultPageFactory = $resultPageFactory; | ||||||
|  |     } | ||||||
|  |     public function execute() | ||||||
|  |     { | ||||||
|  |         $resultPage = $this->resultPageFactory->create(); | ||||||
|  |         $resultPage->setActiveMenu('IpSupply_SyncOrder::menu'); | ||||||
|  |         $resultPage->getConfig()->getTitle()->prepend(__('IpSupply | Sync Order')); | ||||||
|  |         return $resultPage; | ||||||
|  |     } | ||||||
|  |     protected function _isAllowed() | ||||||
|  |     { | ||||||
|  |         return $this->_authorization->isAllowed('IpSupply_SyncOrder::config'); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,7 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace IpSupply\SyncOrder; | ||||||
|  | 
 | ||||||
|  | final class Helper { | ||||||
|  |     public const API_KEY = 'IpSupply@123'; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,32 @@ | ||||||
|  | <?xml version="1.0"?> | ||||||
|  | <config | ||||||
|  |     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|  |     xsi:noNamespaceSchemaLocation="urn:magento:module:IpSupply_SyncOrder:etc/menu.xsd" | ||||||
|  | > | ||||||
|  |     <menu> | ||||||
|  |         <add | ||||||
|  |             id="IpSupply_SyncOrder::ipsupply" | ||||||
|  |             title="Ip Supply" | ||||||
|  |             module="IpSupply_SyncOrder" | ||||||
|  |             sortOrder="51" | ||||||
|  |             resource="IpSupply_SyncOrder::ipsupply" | ||||||
|  |         /> | ||||||
|  |         <add | ||||||
|  |             module="IpSupply_SyncOrder" | ||||||
|  |             parent="IpSupply_SyncOrder::ipsupply" | ||||||
|  |             title="Sync Order" | ||||||
|  |             sortOrder="10" | ||||||
|  |             id="IpSupply_SyncOrder::config" | ||||||
|  |             resource="IpSupply_SyncOrder::config" | ||||||
|  |             action="syncorder/config/index" | ||||||
|  |         /> | ||||||
|  |             <!-- | ||||||
|  |                 Parent: Value is the ID of the main menu. It specifies the sub menu belongs to parentory menu. | ||||||
|  |                 Action: Direct URL if clicking to the menu, as format [router_name]/[controller_name]/[action_name]. | ||||||
|  |                     – In our example, menu links with module Bss, controller Create and action Index | ||||||
|  |                         + router_name: etc/adminhtml/routes.xml as route[id="router_name"] | ||||||
|  |                         + controller_name: Controller/Adminhtml/[controller_name]/ | ||||||
|  |                         + action_name: Controller/Adminhtml/[controller_name]/[action_name].php | ||||||
|  |             --> | ||||||
|  |     </menu> | ||||||
|  | </config> | ||||||
|  | @ -0,0 +1,11 @@ | ||||||
|  | <?xml version="1.0"?> | ||||||
|  | <config | ||||||
|  |     xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd" | ||||||
|  |     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|  | > | ||||||
|  |     <router id="admin"> | ||||||
|  |         <route id="syncorder" frontName="syncorder"> | ||||||
|  |             <module name="IpSupply_SyncOrder" before="Magento_Backend" /> | ||||||
|  |         </route> | ||||||
|  |     </router> | ||||||
|  | </config> | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | <?xml version="1.0"?> | ||||||
|  | <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||||||
|  |     <module name="IpSupply_SyncOrder" setup_version="1.0.1"/> | ||||||
|  | </config> | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | <?xml version="1.0"?> | ||||||
|  | <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> | ||||||
|  |     <route url="ipsupply/syncorder/sync" method="GET"> | ||||||
|  |         <service class="IpSupply\SyncOrder\Api\RepositoryInterface" method="getData"/> | ||||||
|  |         <resources> | ||||||
|  |             <resource ref="anonymous"/> | ||||||
|  |         </resources> | ||||||
|  |     </route> | ||||||
|  |     <route url="ipsupply/syncorder/sync" method="POST"> | ||||||
|  |         <service class="IpSupply\SyncOrder\Api\RepositoryInterface" method="postData"/> | ||||||
|  |         <resources> | ||||||
|  |             <resource ref="anonymous"/> | ||||||
|  |         </resources> | ||||||
|  |     </route> | ||||||
|  | </routes> | ||||||
|  | @ -0,0 +1,6 @@ | ||||||
|  | <?php | ||||||
|  | \Magento\Framework\Component\ComponentRegistrar::register( | ||||||
|  |     \Magento\Framework\Component\ComponentRegistrar::MODULE, | ||||||
|  |     'IpSupply_SyncOrder', | ||||||
|  |     __DIR__ | ||||||
|  | ); | ||||||
|  | @ -0,0 +1,14 @@ | ||||||
|  | <?xml version="1.0"?> | ||||||
|  | <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||||||
|  |     <head> | ||||||
|  |        <css src="IpSupply_SyncOrder::css/config.css"/> | ||||||
|  |     </head> | ||||||
|  |     <body> | ||||||
|  |         <referenceContainer name="content"> | ||||||
|  |             <block class="IpSupply\SyncOrder\Block\Adminhtml\Config" template="IpSupply_SyncOrder::syncorder_config.phtml"/> | ||||||
|  |             <!-- | ||||||
|  |                 Template: IpSupply_SyncOrder::syncorder_config.phtml to ../templates/syncorder_config.phtml | ||||||
|  |             --> | ||||||
|  |         </referenceContainer> | ||||||
|  |     </body> | ||||||
|  | </page> | ||||||
		Loading…
	
		Reference in New Issue