├── Block └── Adminhtml │ ├── Region.php │ └── Region │ ├── Edit.php │ └── Edit │ └── Form.php ├── Controller └── Adminhtml │ ├── Region.php │ └── Region │ ├── Delete.php │ ├── Edit.php │ ├── Index.php │ ├── MassDelete.php │ ├── NewAction.php │ └── Save.php ├── Model ├── Region.php ├── RegionName.php └── ResourceModel │ ├── Region.php │ ├── Region │ ├── Collection.php │ ├── CollectionFactory.php │ └── Grid │ │ └── Collection.php │ ├── RegionName.php │ └── RegionName │ └── Collection.php ├── README.md ├── Setup ├── InstallData.php └── InstallSchema.php ├── Ui └── Component │ └── Listing │ └── Column │ └── RegionActions.php ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ ├── menu.xml │ └── routes.xml ├── di.xml └── module.xml ├── regions-manager.png ├── registration.php └── view ├── adminhtml ├── layout │ ├── phpcuong_region_edit.xml │ ├── phpcuong_region_index.xml │ └── phpcuong_region_new.xml ├── templates │ └── footer │ │ ├── copyright.phtml │ │ ├── report.phtml │ │ └── version.phtml └── ui_component │ └── region_listing.xml └── base └── web └── css └── faq-extension ├── Read Me.txt ├── demo-files ├── demo.css └── demo.js ├── demo.html ├── fonts ├── faq-extension.eot ├── faq-extension.svg ├── faq-extension.ttf └── faq-extension.woff ├── ie7 ├── ie7.css └── ie7.js ├── selection.json └── style.css /Block/Adminhtml/Region.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 00:05:54 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 00:12:38 9 | */ 10 | 11 | namespace PHPCuong\Region\Block\Adminhtml; 12 | 13 | /** 14 | * Adminhtml cms blocks content block 15 | */ 16 | class Region extends \Magento\Backend\Block\Widget\Grid\Container 17 | { 18 | /** 19 | * @return void 20 | */ 21 | protected function _construct() 22 | { 23 | $this->_blockGroup = 'PHPCuong_Region'; 24 | $this->_controller = 'adminhtml_region'; 25 | $this->_headerText = __('Regions Manager'); 26 | $this->_addButtonLabel = __('Add New Region'); 27 | parent::_construct(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Block/Adminhtml/Region/Edit.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 00:44:50 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 00:50:31 9 | */ 10 | 11 | namespace PHPCuong\Region\Block\Adminhtml\Region; 12 | 13 | use Magento\Backend\Block\Widget\Form\Container; 14 | 15 | class Edit extends Container 16 | { 17 | /** 18 | * Core registry 19 | * 20 | * @var \Magento\Framework\Registry 21 | */ 22 | protected $_coreRegistry = null; 23 | 24 | /** 25 | * @param \Magento\Backend\Block\Widget\Context $context 26 | * @param \Magento\Framework\Registry $registry 27 | * @param array $data 28 | */ 29 | public function __construct( 30 | \Magento\Backend\Block\Widget\Context $context, 31 | \Magento\Framework\Registry $registry, 32 | array $data = [] 33 | ) { 34 | $this->_coreRegistry = $registry; 35 | parent::__construct($context, $data); 36 | } 37 | 38 | /** 39 | * Department edit block 40 | * 41 | * @return void 42 | */ 43 | protected function _construct() 44 | { 45 | $this->_objectId = 'phpcuong_region_id'; 46 | $this->_blockGroup = 'PHPCuong_Region'; 47 | $this->_controller = 'adminhtml_region'; 48 | parent::_construct(); 49 | 50 | if ($this->_isAllowedAction('PHPCuong_Region::region_edit')) { 51 | $this->buttonList->update('save', 'label', __('Save Region')); 52 | $this->buttonList->add( 53 | 'saveandcontinue', 54 | [ 55 | 'label' => __('Save and Continue Edit'), 56 | 'class' => 'save', 57 | 'data_attribute' => [ 58 | 'mage-init' => [ 59 | 'button' => [ 60 | 'event' => 'saveAndContinueEdit', 61 | 'target' => '#edit_form' 62 | ], 63 | ], 64 | ] 65 | ], 66 | -100 67 | ); 68 | 69 | $region = $this->_coreRegistry->registry('phpcuong_region'); 70 | if(!empty($region)) { 71 | if ($region->getRegionId()) { 72 | $this->buttonList->add( 73 | 'delete', 74 | [ 75 | 'label' => __('Delete'), 76 | 'class' => 'delete', 77 | 'onclick' => 'deleteConfirm("Are you sure you want to delete this Region?", "'.$this->getDeleteUrl().'")' 78 | ], 79 | -100 80 | ); 81 | } 82 | } 83 | } else { 84 | $this->buttonList->remove('save'); 85 | } 86 | } 87 | 88 | /** 89 | * Check permission for passed action 90 | * 91 | * @param string $resourceId 92 | * @return bool 93 | */ 94 | protected function _isAllowedAction($resourceId) 95 | { 96 | return $this->_authorization->isAllowed($resourceId); 97 | } 98 | 99 | /** 100 | * Retrieve delete Url. 101 | * 102 | * @return string 103 | */ 104 | public function getDeleteUrl() 105 | { 106 | return $this->getUrl( 107 | '*/*/delete', 108 | [ 109 | '_current' => true, 110 | 'id' => $this->getRequest()->getParam('region_id') 111 | ] 112 | ); 113 | } 114 | 115 | /** 116 | * Getter of url for "Save and Continue" button 117 | * tab_id will be replaced by desired by JS later 118 | * 119 | * @return string 120 | */ 121 | protected function _getSaveAndContinueUrl() 122 | { 123 | return $this->getUrl( 124 | '*/*/save', 125 | [ 126 | '_current' => true, 127 | 'back' => 'edit', 128 | 'active_tab' => '' 129 | ] 130 | ); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Block/Adminhtml/Region/Edit/Form.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 00:49:46 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 15:45:47 9 | */ 10 | 11 | namespace PHPCuong\Region\Block\Adminhtml\Region\Edit; 12 | 13 | use \Magento\Backend\Block\Widget\Form\Generic; 14 | 15 | class Form extends Generic 16 | { 17 | protected $_coreRegistry = null; 18 | /** 19 | * @param \Magento\Backend\Block\Template\Context $context 20 | * @param \Magento\Framework\Registry $registry 21 | * @param \Magento\Framework\Data\FormFactory $formFactory 22 | * @param array $data 23 | */ 24 | public function __construct( 25 | \Magento\Backend\Block\Template\Context $context, 26 | \Magento\Framework\Registry $registry, 27 | \Magento\Framework\Data\FormFactory $formFactory, 28 | array $data = [] 29 | ) { 30 | $this->_coreRegistry = $registry; 31 | parent::__construct($context, $registry, $formFactory, $data); 32 | } 33 | 34 | /** 35 | * Init form 36 | * 37 | * @return void 38 | */ 39 | protected function _construct() 40 | { 41 | parent::_construct(); 42 | $this->setId('region_form'); 43 | $this->setTitle(__('Region Information')); 44 | } 45 | 46 | /** 47 | * Prepare form 48 | * 49 | * @return $this 50 | */ 51 | protected function _prepareForm() 52 | { 53 | $form = $this->_formFactory->create( 54 | [ 55 | 'data' => [ 56 | 'id' => 'edit_form', 57 | 'action' => $this->getData('action'), 58 | 'method' => 'post' 59 | ] 60 | ] 61 | ); 62 | 63 | $form->setHtmlIdPrefix('region_'); 64 | 65 | $fieldset = $form->addFieldset( 66 | 'base_fieldset', 67 | [ 68 | 'legend' => __('General Information'), 69 | 'class' => 'fieldset-wide' 70 | ] 71 | ); 72 | 73 | $country_list = $this->_coreRegistry->registry('phpcuong_region_country_list'); 74 | 75 | $fieldset->addField( 76 | 'country_id', 77 | 'select', 78 | [ 79 | 'name' => 'country_id', 80 | 'label' => __('Country'), 81 | 'title' => __('Country'), 82 | 'required' => true, 83 | 'values' => $country_list 84 | ] 85 | ); 86 | 87 | $fieldset->addField( 88 | 'code', 89 | 'text', 90 | [ 91 | 'name' => 'code', 92 | 'label' => __('State/Region/Province Code'), 93 | 'title' => __('State/Region/Province Code'), 94 | 'required' => true 95 | ] 96 | ); 97 | 98 | $fieldset->addField( 99 | 'default_name', 100 | 'text', 101 | [ 102 | 'name' => 'default_name', 103 | 'label' => __('State/Region/Province Name'), 104 | 'title' => __('State/Region/Province Name'), 105 | 'required' => true 106 | ] 107 | ); 108 | 109 | $formData = $this->_coreRegistry->registry('phpcuong_region'); 110 | if ($formData) { 111 | if ($formData->getRegionId()) { 112 | $fieldset->addField( 113 | 'region_id', 114 | 'hidden', 115 | ['name' => 'region_id'] 116 | ); 117 | } 118 | $form->setValues($formData->getData()); 119 | } 120 | 121 | $form->setUseContainer(true); 122 | $form->setMethod('post'); 123 | $this->setForm($form); 124 | 125 | return parent::_prepareForm(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 20:57:08 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 22:10:30 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml; 12 | 13 | abstract class Region extends \Magento\Backend\App\Action 14 | { 15 | /** 16 | * Mass Action Filter 17 | * 18 | * @var \Magento\Ui\Component\MassAction\Filter 19 | */ 20 | protected $_filter; 21 | /** 22 | * Collection Factory 23 | * 24 | * @var PHPCuong\Region\Model\ResourceModel\Region\CollectionFactory 25 | */ 26 | protected $_collectionFactory; 27 | 28 | protected $resultPageFactory; 29 | 30 | public function __construct( 31 | \Magento\Backend\App\Action\Context $context, 32 | \Magento\Framework\View\Result\PageFactory $resultPageFactory 33 | ) { 34 | $this->resultPageFactory = $resultPageFactory; 35 | parent::__construct($context); 36 | } 37 | 38 | /** 39 | * @return $this 40 | */ 41 | protected function _initAction() 42 | { 43 | $resultPage = $this->resultPageFactory->create(); 44 | return $resultPage; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/Delete.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 21:47:12 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 22:22:47 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | class Delete extends \Magento\Backend\App\Action 14 | { 15 | /** 16 | * Authorization level of a basic admin session 17 | * 18 | * @see _isAllowed() 19 | */ 20 | const ADMIN_RESOURCE = 'PHPCuong_Region::region_delete'; 21 | /** 22 | * 23 | * @return \Magento\Framework\View\Result\PageFactory 24 | */ 25 | public function execute() 26 | { 27 | // check if we know what should be deleted 28 | $region_id = $this->getRequest()->getParam('region_id'); 29 | /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ 30 | $resultRedirect = $this->resultRedirectFactory->create(); 31 | if ($region_id) { 32 | $region_name = ''; 33 | try { 34 | // init model and delete 35 | $model = $this->_objectManager->create('PHPCuong\Region\Model\Region'); 36 | $model->load($region_id); 37 | $region_name = $model->getDefaultName(); 38 | $model->delete(); 39 | $this->messageManager->addSuccess(__('The '.$region_name.' Region has been deleted.')); 40 | return $resultRedirect->setPath('*/*/'); 41 | } catch (\Exception $e) { 42 | // display error message 43 | $this->messageManager->addError($e->getMessage()); 44 | // go back to edit form 45 | return $resultRedirect->setPath('*/*/edit', ['region_id' => $region_id]); 46 | } 47 | } 48 | // display error message 49 | $this->messageManager->addError(__('Region to delete was not found.')); 50 | // go to grid 51 | return $resultRedirect->setPath('*/*/'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/Edit.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 22:29:31 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 15:12:07 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | use Magento\Backend\App\Action; 14 | 15 | class Edit extends \Magento\Backend\App\Action 16 | { 17 | /** 18 | * Authorization level of a basic admin session 19 | * 20 | * @see _isAllowed() 21 | */ 22 | const ADMIN_RESOURCE = 'PHPCuong_Region::region_edit'; 23 | 24 | /** 25 | * Core registry 26 | * 27 | * @var \Magento\Framework\Registry 28 | */ 29 | protected $_coreRegistry; 30 | 31 | /** 32 | * @var \Magento\Framework\View\Result\PageFactory 33 | */ 34 | protected $resultPageFactory; 35 | 36 | /** 37 | * @param Action\Context $context 38 | * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory 39 | * @param \Magento\Framework\Registry $registry 40 | */ 41 | public function __construct( 42 | Action\Context $context, 43 | \Magento\Framework\View\Result\PageFactory $resultPageFactory, 44 | \Magento\Framework\Registry $registry 45 | ) { 46 | $this->resultPageFactory = $resultPageFactory; 47 | $this->_coreRegistry = $registry; 48 | parent::__construct($context); 49 | } 50 | 51 | /** 52 | * Init actions 53 | * 54 | * @return \Magento\Backend\Model\View\Result\Page 55 | */ 56 | protected function _initAction() 57 | { 58 | // load layout, set active menu 59 | /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ 60 | $resultPage = $this->resultPageFactory->create(); 61 | $resultPage->setActiveMenu('Magento_Customer::customer'); 62 | return $resultPage; 63 | } 64 | 65 | /** 66 | * Edit Region page 67 | * 68 | * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect 69 | * @SuppressWarnings(PHPMD.NPathComplexity) 70 | */ 71 | public function execute() 72 | { 73 | // Get ID and create model 74 | $id = (int) $this->getRequest()->getParam('region_id'); 75 | $model = $this->_objectManager->create('PHPCuong\Region\Model\Region'); 76 | $model->setData([]); 77 | // Initial checking 78 | if ($id && $id > 0) { 79 | $model->load($id); 80 | if (!$model->getRegionId()) { 81 | $this->messageManager->addError(__('This region no longer exists.')); 82 | /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ 83 | $resultRedirect = $this->resultRedirectFactory->create(); 84 | return $resultRedirect->setPath('*/*/'); 85 | } 86 | $default_name = $model->getDefaultName(); 87 | } 88 | 89 | $FormData = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true); 90 | if (!empty($FormData)) { 91 | $model->setData($FormData); 92 | } 93 | 94 | $this->_coreRegistry->register('phpcuong_region', $model); 95 | 96 | $countryHelper = $this->_objectManager->get('Magento\Directory\Model\Config\Source\Country'); 97 | 98 | $this->_coreRegistry->register('phpcuong_region_country_list', $countryHelper->toOptionArray()); 99 | 100 | // Build edit form 101 | /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ 102 | $resultPage = $this->_initAction(); 103 | $resultPage->addBreadcrumb( 104 | $id ? __('Edit Region') : __('New Region'), 105 | $id ? __('Edit Region') : __('New Region') 106 | ); 107 | $resultPage->getConfig()->getTitle()->prepend(__('Regions Manager')); 108 | $resultPage->getConfig()->getTitle() 109 | ->prepend($id ? 'Edit: '.$default_name.' ('.$id.')' : __('New Region')); 110 | 111 | return $resultPage; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/Index.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 21:02:32 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 16:00:34 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | class Index extends \PHPCuong\Region\Controller\Adminhtml\Region 14 | { 15 | /** 16 | * @return \Magento\Framework\View\Result\PageFactory 17 | */ 18 | public function execute() 19 | { 20 | $resultPage = $this->_initAction(); 21 | $resultPage->addBreadcrumb( 22 | 'Regions Manager', 23 | 'Regions Manager' 24 | ); 25 | $resultPage->getConfig()->getTitle()->prepend(__('Customers')); 26 | $resultPage->getConfig()->getTitle() 27 | ->prepend('Regions Manager'); 28 | return $resultPage; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/MassDelete.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 01:12:57 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-15 23:30:16 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | use Magento\Framework\Controller\ResultFactory; 14 | use Magento\Backend\App\Action\Context; 15 | use Magento\Ui\Component\MassAction\Filter; 16 | use PHPCuong\Region\Model\ResourceModel\Region\CollectionFactory; 17 | 18 | class MassDelete extends \Magento\Backend\App\Action 19 | { 20 | /** 21 | * Authorization level of a basic admin session 22 | * 23 | * @see _isAllowed() 24 | */ 25 | const ADMIN_RESOURCE = 'PHPCuong_Region::region_delete'; 26 | /** 27 | * @var Filter 28 | */ 29 | protected $filter; 30 | 31 | /** 32 | * @var CollectionFactory 33 | */ 34 | protected $collectionFactory; 35 | 36 | /** 37 | * @param Context $context 38 | * @param Filter $filter 39 | * @param CollectionFactory $collectionFactory 40 | */ 41 | public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) 42 | { 43 | $this->filter = $filter; 44 | $this->collectionFactory = $collectionFactory; 45 | parent::__construct($context); 46 | } 47 | 48 | /** 49 | * Execute action 50 | * 51 | * @return \Magento\Backend\Model\View\Result\Redirect 52 | * @throws \Magento\Framework\Exception\LocalizedException|\Exception 53 | */ 54 | public function execute() 55 | { 56 | $collection = $this->filter->getCollection($this->collectionFactory->create()); 57 | $collectionSize = $collection->getSize(); 58 | 59 | foreach ($collection as $page) { 60 | $page->delete(); 61 | } 62 | 63 | $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize)); 64 | 65 | /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ 66 | $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); 67 | return $resultRedirect->setPath('*/*/'); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/NewAction.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 01:08:32 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2017-11-11 23:02:48 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | class NewAction extends \Magento\Backend\App\Action 14 | { 15 | protected $coreRegistry = null; 16 | /** 17 | * Authorization level of a basic admin session 18 | * 19 | * @see _isAllowed() 20 | */ 21 | const ADMIN_RESOURCE = 'PHPCuong_Region::region_create'; 22 | 23 | /** 24 | * @var \Magento\Backend\Model\View\Result\ForwardFactory 25 | */ 26 | protected $resultPageFactory; 27 | 28 | /** 29 | * @param \Magento\Backend\App\Action\Context $context 30 | * @param \Magento\Framework\Registry $coreRegistry 31 | * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory 32 | */ 33 | public function __construct( 34 | \Magento\Backend\App\Action\Context $context, 35 | \Magento\Framework\Registry $coreRegistry, 36 | \Magento\Framework\View\Result\PageFactory $resultPageFactory 37 | ) { 38 | $this->coreRegistry = $coreRegistry; 39 | $this->resultPageFactory = $resultPageFactory; 40 | parent::__construct($context); 41 | } 42 | 43 | /** 44 | * Create new Region 45 | * 46 | * @return \Magento\Framework\Controller\ResultInterface 47 | */ 48 | public function execute() 49 | { 50 | /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ 51 | $resultPageFactory = $this->resultPageFactory->create(); 52 | 53 | $FormData = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true); 54 | if (!empty($FormData)) { 55 | $model = $this->_objectManager->create('PHPCuong\Region\Model\Region'); 56 | $model->setData($FormData); 57 | $this->coreRegistry->register('phpcuong_region', $model); 58 | } 59 | 60 | $countryHelper = $this->_objectManager->get('Magento\Directory\Model\Config\Source\Country'); 61 | 62 | $this->coreRegistry->register('phpcuong_region_country_list', $countryHelper->toOptionArray()); 63 | 64 | return $resultPageFactory; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Controller/Adminhtml/Region/Save.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 01:36:35 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 14:29:04 9 | */ 10 | 11 | namespace PHPCuong\Region\Controller\Adminhtml\Region; 12 | 13 | use Magento\Backend\App\Action\Context; 14 | use Magento\Framework\Exception\LocalizedException; 15 | use Magento\TestFramework\Inspection\Exception; 16 | 17 | class Save extends \Magento\Backend\App\Action 18 | { 19 | /** 20 | * Core registry 21 | * 22 | * @var \Magento\Framework\Registry 23 | */ 24 | protected $_coreRegistry; 25 | /** 26 | * @param Context $context 27 | * @param \Magento\Framework\Registry $coreRegistry 28 | * @param DataPersistorInterface $dataPersistor 29 | */ 30 | public function __construct( 31 | Context $context, 32 | \Magento\Framework\Registry $coreRegistry 33 | ) { 34 | $this->_coreRegistry = $coreRegistry; 35 | parent::__construct($context); 36 | } 37 | 38 | /** 39 | * Save action 40 | * 41 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) 42 | * @return \Magento\Framework\Controller\ResultInterface 43 | */ 44 | public function execute() 45 | { 46 | /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ 47 | $resultRedirect = $this->resultRedirectFactory->create(); 48 | 49 | $data = $this->getRequest()->getPostValue(); 50 | if ($data) { 51 | 52 | $id = $this->getRequest()->getParam('region_id'); 53 | 54 | /** @var \PHPCuong\Region\Model\Region $model */ 55 | $model = $this->_objectManager->create('PHPCuong\Region\Model\Region')->load($id); 56 | if (!$model->getRegionId() && $id) { 57 | $this->messageManager->addError(__('This region no longer exists.')); 58 | return $resultRedirect->setPath('*/*/'); 59 | } 60 | 61 | $model->setData($data); 62 | 63 | try { 64 | $model->save(); 65 | $this->messageManager->addSuccess(__('You saved the region.')); 66 | 67 | if ($this->getRequest()->getParam('back')) { 68 | return $resultRedirect->setPath('*/*/edit', ['region_id' => $model->getRegionId()]); 69 | } 70 | return $resultRedirect->setPath('*/*/'); 71 | } catch (LocalizedException $e) { 72 | $this->messageManager->addError($e->getMessage()); 73 | } catch (\Exception $e) { 74 | $this->messageManager->addException($e, __('Something went wrong while saving the region.')); 75 | } 76 | 77 | $this->_getSession()->setFormData($data); 78 | if ($this->getRequest()->getParam('region_id')) { 79 | return $resultRedirect->setPath('*/*/edit', ['region_id' => $this->getRequest()->getParam('region_id')]); 80 | } 81 | return $resultRedirect->setPath('*/*/new'); 82 | } 83 | return $resultRedirect->setPath('*/*/'); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Model/Region.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 23:42:05 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 19:10:27 9 | */ 10 | 11 | namespace PHPCuong\Region\Model; 12 | 13 | class Region extends \Magento\Framework\Model\AbstractModel 14 | { 15 | /** 16 | * Cache tag 17 | * 18 | * @var string 19 | */ 20 | const CACHE_TAG = 'directory_country_region'; 21 | /** 22 | * Initialize resource model 23 | * 24 | * @return void 25 | */ 26 | protected function _construct() 27 | { 28 | $this->_init('PHPCuong\Region\Model\ResourceModel\Region'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Model/RegionName.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 18:23:48 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 18:25:24 9 | */ 10 | 11 | namespace PHPCuong\Region\Model; 12 | 13 | class RegionName extends \Magento\Framework\Model\AbstractModel 14 | { 15 | /** 16 | * Cache tag 17 | * 18 | * @var string 19 | */ 20 | const CACHE_TAG = 'directory_country_region_name'; 21 | /** 22 | * Initialize resource model 23 | * 24 | * @return void 25 | */ 26 | protected function _construct() 27 | { 28 | $this->_init('PHPCuong\Region\Model\ResourceModel\RegionName'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Model/ResourceModel/Region.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 23:45:27 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 17:43:20 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel; 12 | 13 | use Magento\Framework\Exception\LocalizedException; 14 | use Magento\Framework\Model\AbstractModel; 15 | 16 | class Region extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb 17 | { 18 | /** 19 | * construct 20 | * @return void 21 | */ 22 | protected function _construct() 23 | { 24 | $this->_init('directory_country_region', 'region_id'); 25 | } 26 | 27 | /** 28 | * Perform operations before object save 29 | * 30 | * @param AbstractModel $object 31 | * @return $this 32 | * @throws LocalizedException 33 | */ 34 | protected function _beforeSave(AbstractModel $object) 35 | { 36 | if (!$this->checkRegionAlreadyExist($object)) { 37 | throw new LocalizedException( 38 | __('The region already exists.') 39 | ); 40 | } 41 | } 42 | 43 | protected function checkSubRegionAlreadyExist(AbstractModel $object, $field) 44 | { 45 | $select = $this->getConnection()->select() 46 | ->from(['dcr' => $this->getMainTable()]) 47 | ->where('dcr.country_id = ?', $object->getData('country_id')) 48 | ->where('dcr.'.$field.' = ?', $object->getData($field)); 49 | if ($object->getData('region_id')) { 50 | $select->where('dcr.region_id <> ?', $object->getData('region_id')); 51 | } 52 | if ($this->getConnection()->fetchRow($select)) { 53 | return false; 54 | } 55 | return true; 56 | } 57 | 58 | protected function checkRegionAlreadyExist(AbstractModel $object) 59 | { 60 | if (!$this->checkSubRegionAlreadyExist($object, 'default_name') || !$this->checkSubRegionAlreadyExist($object, 'code')) { 61 | return false; 62 | } 63 | return true; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Model/ResourceModel/Region/Collection.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 23:48:21 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 17:58:16 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel\Region; 12 | 13 | class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection 14 | { 15 | protected $_idFieldName = 'region_id'; 16 | /** 17 | * Define resource model. 18 | */ 19 | protected function _construct() 20 | { 21 | $this->_init('PHPCuong\Region\Model\Region', 'PHPCuong\Region\Model\ResourceModel\Region'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Model/ResourceModel/Region/CollectionFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 02:07:14 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 04:52:51 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel\Region; 12 | 13 | class CollectionFactory { 14 | /** 15 | * Object Manager instance 16 | * 17 | * @var \Magento\Framework\ObjectManagerInterface 18 | */ 19 | protected $_objectManager = null; 20 | 21 | /** 22 | * Instance name to create 23 | * 24 | * @var string 25 | */ 26 | protected $_instanceName = null; 27 | 28 | /** 29 | * Factory constructor 30 | * 31 | * @param \Magento\Framework\ObjectManagerInterface $objectManager 32 | * @param string $instanceName 33 | */ 34 | public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\PHPCuong\\Region\\Model\\ResourceModel\\Region\\Collection') 35 | { 36 | $this->_objectManager = $objectManager; 37 | $this->_instanceName = $instanceName; 38 | } 39 | 40 | /** 41 | * Create class instance with specified parameters 42 | * 43 | * @param array $data 44 | * @return \PHPCuong\Region\Model\ResourceModel\Region\Collection 45 | */ 46 | public function create(array $data = array()) 47 | { 48 | return $this->_objectManager->create($this->_instanceName, $data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Model/ResourceModel/Region/Grid/Collection.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 23:53:28 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2017-11-22 03:03:03 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel\Region\Grid; 12 | 13 | class Collection extends \PHPCuong\Region\Model\ResourceModel\Region\Collection implements \Magento\Framework\Api\Search\SearchResultInterface 14 | { 15 | /** 16 | * Aggregations 17 | * 18 | * @var \Magento\Framework\Search\AggregationInterface 19 | */ 20 | protected $_aggregations; 21 | 22 | /** 23 | * constructor 24 | * 25 | * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory 26 | * @param \Psr\Log\LoggerInterface $logger 27 | * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy 28 | * @param \Magento\Framework\Event\ManagerInterface $eventManager 29 | * @param $mainTable 30 | * @param $eventPrefix 31 | * @param $eventObject 32 | * @param $resourceModel 33 | * @param $model 34 | * @param $connection 35 | * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource 36 | */ 37 | public function __construct( 38 | \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, 39 | \Psr\Log\LoggerInterface $logger, 40 | \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, 41 | \Magento\Framework\Event\ManagerInterface $eventManager, 42 | $mainTable = 'directory_country_region', 43 | $eventPrefix, 44 | $eventObject, 45 | $resourceModel, 46 | $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document', 47 | \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, 48 | \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null 49 | ) 50 | { 51 | parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); 52 | $this->_eventPrefix = $eventPrefix; 53 | $this->_eventObject = $eventObject; 54 | $this->_init($model, $resourceModel); 55 | $this->setMainTable($mainTable); 56 | } 57 | 58 | 59 | /** 60 | * @return \Magento\Framework\Search\AggregationInterface 61 | */ 62 | public function getAggregations() 63 | { 64 | return $this->_aggregations; 65 | } 66 | 67 | /** 68 | * @param \Magento\Framework\Search\AggregationInterface $aggregations 69 | * @return $this 70 | */ 71 | public function setAggregations($aggregations) 72 | { 73 | $this->_aggregations = $aggregations; 74 | } 75 | 76 | 77 | /** 78 | * Retrieve all ids for collection 79 | * Backward compatibility with EAV collection 80 | * 81 | * @param int $limit 82 | * @param int $offset 83 | * @return array 84 | */ 85 | public function getAllIds($limit = null, $offset = null) 86 | { 87 | return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); 88 | } 89 | 90 | /** 91 | * Get search criteria. 92 | * 93 | * @return \Magento\Framework\Api\SearchCriteriaInterface|null 94 | */ 95 | public function getSearchCriteria() 96 | { 97 | return null; 98 | } 99 | 100 | /** 101 | * Set search criteria. 102 | * 103 | * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria 104 | * @return $this 105 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 106 | */ 107 | public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null) 108 | { 109 | return $this; 110 | } 111 | 112 | /** 113 | * Get total count. 114 | * 115 | * @return int 116 | */ 117 | public function getTotalCount() 118 | { 119 | return $this->getSize(); 120 | } 121 | 122 | /** 123 | * Set total count. 124 | * 125 | * @param int $totalCount 126 | * @return $this 127 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 128 | */ 129 | public function setTotalCount($totalCount) 130 | { 131 | return $this; 132 | } 133 | 134 | /** 135 | * Set items list. 136 | * 137 | * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items 138 | * @return $this 139 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 140 | */ 141 | public function setItems(array $items = null) 142 | { 143 | return $this; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Model/ResourceModel/RegionName.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 18:24:39 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 18:26:26 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel; 12 | 13 | use Magento\Framework\Exception\LocalizedException; 14 | use Magento\Framework\Model\AbstractModel; 15 | 16 | class RegionName extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb 17 | { 18 | /** 19 | * construct 20 | * @return void 21 | */ 22 | protected function _construct() 23 | { 24 | $this->_init('directory_country_region_name', 'region_id'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Model/ResourceModel/RegionName/Collection.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-13 18:27:07 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 18:27:36 9 | */ 10 | 11 | namespace PHPCuong\Region\Model\ResourceModel\RegionName; 12 | 13 | class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection 14 | { 15 | protected $_idFieldName = 'region_id'; 16 | /** 17 | * Define resource model. 18 | */ 19 | protected function _construct() 20 | { 21 | $this->_init('PHPCuong\Region\Model\RegionName', 'PHPCuong\Region\Model\ResourceModel\RegionName'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Manage regions in Magento2 addresses 2 | Magento2 provides country and regions and cities as dropdown option in addresses This module provides flexibility of managing this regions for each country. 3 | 4 | Very Easy to use 5 | 6 | Test and working with Magento CE 2.x and Magento EE 2.x 7 | 8 | ### Benefits 9 | This module provides flexibility of managing the regions for each country in your Magento Admin. 10 | 11 | #### 1 - Installation Regions Manager 12 | ##### Manual Installation 13 | Install Regions Manager for Magento2 14 | * Download the extension 15 | * Unzip the file 16 | * Create a folder {Magento root}/app/code/PHPCuong/Region 17 | * Copy the content from the unzip folder 18 | 19 | 20 | ##### Using Composer 21 | 22 | ``` 23 | composer require php-cuong/magento2-regions-manager 24 | ``` 25 | 26 | #### 2 - Enable Regions Manager 27 | * php bin/magento module:enable PHPCuong_Region 28 | * php bin/magento setup:upgrade 29 | * php bin/magento cache:flush 30 | * php bin/magento setup:static-content:deploy 31 | 32 | #### 3 - See results 33 | Log into your Magento admin, goto Customers -> Manage Regions in Addresses 34 | 35 | ![ScreenShot](https://raw.githubusercontent.com/php-cuong/magento2-regions-manager/master/regions-manager.png) 36 | 37 | #### See the Regions Manager Pro Extension here 38 | https://github.com/php-cuong/magento2-city-dropdown 39 | 40 | Extension link: https://www.giaphugroup.com/magento-2-city-dropdown-extension.html 41 | 42 | ### Donations 43 | Please donate if you enjoy my extension. 44 | 45 | [![](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RUYCWQ3Q9YGH2) 46 | 47 | -------------------------------------------------------------------------------- /Setup/InstallData.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 03:46:38 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-13 18:02:07 9 | */ 10 | 11 | namespace PHPCuong\Region\Setup; 12 | 13 | use Magento\Framework\Setup\InstallDataInterface; 14 | use Magento\Framework\Setup\ModuleContextInterface; 15 | use Magento\Framework\Setup\ModuleDataSetupInterface; 16 | 17 | /** 18 | * Install Data 19 | */ 20 | class InstallData implements InstallDataInterface 21 | { 22 | /** 23 | * {@inheritdoc} 24 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) 25 | */ 26 | public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) 27 | { 28 | $setup->startSetup(); 29 | $vietnam_regions = [ 30 | ['country_id' => 'VN', 'code' => 'TPHANOI', 'default_name' => 'Thành phố Hà Nội'], 31 | ['country_id' => 'VN', 'code' => 'HAGIANG', 'default_name' => 'Hà Giang'], 32 | ['country_id' => 'VN', 'code' => 'CAOBANG', 'default_name' => 'Cao Bằng'], 33 | ['country_id' => 'VN', 'code' => 'BACKAN', 'default_name' => 'Bắc Kạn'], 34 | ['country_id' => 'VN', 'code' => 'TUYENQUANG', 'default_name' => 'Tuyên Quang'], 35 | ['country_id' => 'VN', 'code' => 'LAOCAI', 'default_name' => 'Lào Cai'], 36 | ['country_id' => 'VN', 'code' => 'DIENBIEN', 'default_name' => 'Điện Biên'], 37 | ['country_id' => 'VN', 'code' => 'LAICHAU', 'default_name' => 'Lai Châu'], 38 | ['country_id' => 'VN', 'code' => 'SONLA', 'default_name' => 'Sơn La'], 39 | ['country_id' => 'VN', 'code' => 'YENBAI', 'default_name' => 'Yên Bái'], 40 | ['country_id' => 'VN', 'code' => 'HOABINH', 'default_name' => 'Hoà Bình'], 41 | ['country_id' => 'VN', 'code' => 'THAINGUYEN', 'default_name' => 'Thái Nguyên'], 42 | ['country_id' => 'VN', 'code' => 'LANGSON', 'default_name' => 'Lạng Sơn'], 43 | ['country_id' => 'VN', 'code' => 'QUANGNINH', 'default_name' => 'Quảng Ninh'], 44 | ['country_id' => 'VN', 'code' => 'BACGIANG', 'default_name' => 'Bắc Giang'], 45 | ['country_id' => 'VN', 'code' => 'PHUTHO', 'default_name' => 'Phú Thọ'], 46 | ['country_id' => 'VN', 'code' => 'VINHPHUC', 'default_name' => 'Vĩnh Phúc'], 47 | ['country_id' => 'VN', 'code' => 'BACNINH', 'default_name' => 'Bắc Ninh'], 48 | ['country_id' => 'VN', 'code' => 'HAIDUONG', 'default_name' => 'Hải Dương'], 49 | ['country_id' => 'VN', 'code' => 'TPHAIPHONG', 'default_name' => 'Thành phố Hải Phòng'], 50 | ['country_id' => 'VN', 'code' => 'HUNGYEN', 'default_name' => 'Hưng Yên'], 51 | ['country_id' => 'VN', 'code' => 'THAIBINH', 'default_name' => 'Thái Bình'], 52 | ['country_id' => 'VN', 'code' => 'HANAM', 'default_name' => 'Hà Nam'], 53 | ['country_id' => 'VN', 'code' => 'NAMDINH', 'default_name' => 'Nam Định'], 54 | ['country_id' => 'VN', 'code' => 'NINHBINH', 'default_name' => 'Ninh Bình'], 55 | ['country_id' => 'VN', 'code' => 'THANHHOA', 'default_name' => 'Thanh Hóa'], 56 | ['country_id' => 'VN', 'code' => 'NGHEAN', 'default_name' => 'Nghệ An'], 57 | ['country_id' => 'VN', 'code' => 'HATINH', 'default_name' => 'Hà Tĩnh'], 58 | ['country_id' => 'VN', 'code' => 'QUANGBINH', 'default_name' => 'Quảng Bình'], 59 | ['country_id' => 'VN', 'code' => 'QUANGTRI', 'default_name' => 'Quảng Trị'], 60 | ['country_id' => 'VN', 'code' => 'THUATHIENHUE', 'default_name' => 'Thừa Thiên Huế'], 61 | ['country_id' => 'VN', 'code' => 'DANANG', 'default_name' => 'Thành phố Đà Nẵng'], 62 | ['country_id' => 'VN', 'code' => 'QUANGNAM', 'default_name' => 'Quảng Nam'], 63 | ['country_id' => 'VN', 'code' => 'QUANGNGAI', 'default_name' => 'Quảng Ngãi'], 64 | ['country_id' => 'VN', 'code' => 'BINHDINH', 'default_name' => 'Bình Định'], 65 | ['country_id' => 'VN', 'code' => 'PHUYEN', 'default_name' => 'Phú Yên'], 66 | ['country_id' => 'VN', 'code' => 'KHANHHOA', 'default_name' => 'Khánh Hòa'], 67 | ['country_id' => 'VN', 'code' => 'NINHTHUAN', 'default_name' => 'Ninh Thuận'], 68 | ['country_id' => 'VN', 'code' => 'BINHTHUAN', 'default_name' => 'Bình Thuận'], 69 | ['country_id' => 'VN', 'code' => 'KONTUM', 'default_name' => 'Kon Tum'], 70 | ['country_id' => 'VN', 'code' => 'GIALAI', 'default_name' => 'Gia Lai'], 71 | ['country_id' => 'VN', 'code' => 'DAKLAK', 'default_name' => 'Đắk Lắk'], 72 | ['country_id' => 'VN', 'code' => 'DAKNONG', 'default_name' => 'Đắk Nông'], 73 | ['country_id' => 'VN', 'code' => 'LAMDONG', 'default_name' => 'Lâm Đồng'], 74 | ['country_id' => 'VN', 'code' => 'BINHPHUOC', 'default_name' => 'Bình Phước'], 75 | ['country_id' => 'VN', 'code' => 'TAYNINH', 'default_name' => 'Tây Ninh'], 76 | ['country_id' => 'VN', 'code' => 'BINHDUONG', 'default_name' => 'Bình Dương'], 77 | ['country_id' => 'VN', 'code' => 'DONGNAI', 'default_name' => 'Đồng Nai'], 78 | ['country_id' => 'VN', 'code' => 'BARIAVUNGTAU', 'default_name' => 'Bà Rịa - Vũng Tàu'], 79 | ['country_id' => 'VN', 'code' => 'TPHOCHIMINH', 'default_name' => 'Thành phố Hồ Chí Minh'], 80 | ['country_id' => 'VN', 'code' => 'LONGAN', 'default_name' => 'Long An'], 81 | ['country_id' => 'VN', 'code' => 'TIENGIANG', 'default_name' => 'Tiền Giang'], 82 | ['country_id' => 'VN', 'code' => 'BENTRE', 'default_name' => 'Bến Tre'], 83 | ['country_id' => 'VN', 'code' => 'TRAVINH', 'default_name' => 'Trà Vinh'], 84 | ['country_id' => 'VN', 'code' => 'VINHLONG', 'default_name' => 'Vĩnh Long'], 85 | ['country_id' => 'VN', 'code' => 'DONGTHAP', 'default_name' => 'Đồng Tháp'], 86 | ['country_id' => 'VN', 'code' => 'ANGIANG', 'default_name' => 'An Giang'], 87 | ['country_id' => 'VN', 'code' => 'KIENGIANG', 'default_name' => 'Kiên Giang'], 88 | ['country_id' => 'VN', 'code' => 'TPCANTHO', 'default_name' => 'Thành phố Cần Thơ'], 89 | ['country_id' => 'VN', 'code' => 'HAUGIANG', 'default_name' => 'Hậu Giang'], 90 | ['country_id' => 'VN', 'code' => 'SOCTRANG', 'default_name' => 'Sóc Trăng'], 91 | ['country_id' => 'VN', 'code' => 'BACLIEU', 'default_name' => 'Bạc Liêu'], 92 | ['country_id' => 'VN', 'code' => 'CAMAU', 'default_name' => 'Cà Mau'], 93 | ]; 94 | // insert the regions for Vietnam 95 | foreach ($vietnam_regions as $key => $value) { 96 | $select = $setup->getConnection()->select() 97 | ->from(['dcr' => $setup->getTable('directory_country_region')]) 98 | ->where('dcr.country_id = ?', $value['country_id']) 99 | ->where('dcr.code = ?', $value['code']) 100 | ->where('dcr.default_name = ?', $value['default_name']); 101 | if (!$setup->getConnection()->fetchRow($select)) { 102 | $setup->getConnection()->insertForce( 103 | $setup->getTable('directory_country_region'), 104 | $value 105 | ); 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Setup/InstallSchema.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 21:31:45 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 22:27:59 9 | */ 10 | 11 | namespace PHPCuong\Region\Setup; 12 | 13 | class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface 14 | { 15 | /** 16 | * install tables 17 | * 18 | * @param \Magento\Framework\Setup\SchemaSetupInterface $setup 19 | * @param \Magento\Framework\Setup\ModuleContextInterface $context 20 | * @return void 21 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) 22 | */ 23 | public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context) 24 | { 25 | $installer = $setup; 26 | $installer->startSetup(); 27 | if ($installer->tableExists('directory_country_region')) { 28 | $installer->getConnection()->addIndex( 29 | $installer->getTable('directory_country_region'), 30 | $setup->getIdxName( 31 | $installer->getTable('directory_country_region'), 32 | ['default_name'], 33 | \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT 34 | ), 35 | ['default_name'], 36 | \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT 37 | ); 38 | } 39 | $installer->endSetup(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Ui/Component/Listing/Column/RegionActions.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-12 00:43:31 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 22:16:00 9 | */ 10 | 11 | namespace PHPCuong\Region\Ui\Component\Listing\Column; 12 | 13 | class RegionActions extends \Magento\Ui\Component\Listing\Columns\Column 14 | { 15 | /** 16 | * Url path to edit 17 | * 18 | * @var string 19 | */ 20 | const URL_PATH_EDIT = 'phpcuong/region/edit'; 21 | /** 22 | * Url path to delete 23 | * 24 | * @var string 25 | */ 26 | const URL_PATH_DELETE = 'phpcuong/region/delete'; 27 | /** 28 | * URL builder 29 | * 30 | * @var \Magento\Framework\UrlInterface 31 | */ 32 | protected $_urlBuilder; 33 | /** 34 | * constructor 35 | * 36 | * @param \Magento\Framework\UrlInterface $urlBuilder 37 | * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context 38 | * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory 39 | * @param array $components 40 | * @param array $data 41 | */ 42 | public function __construct( 43 | \Magento\Framework\UrlInterface $urlBuilder, 44 | \Magento\Framework\View\Element\UiComponent\ContextInterface $context, 45 | \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory, 46 | array $components = [], 47 | array $data = [] 48 | ) 49 | { 50 | $this->_urlBuilder = $urlBuilder; 51 | parent::__construct($context, $uiComponentFactory, $components, $data); 52 | } 53 | /** 54 | * Prepare Data Source 55 | * 56 | * @param array $dataSource 57 | * @return array 58 | */ 59 | public function prepareDataSource(array $dataSource) 60 | { 61 | if (isset($dataSource['data']['items'])) { 62 | foreach ($dataSource['data']['items'] as & $item) { 63 | if (isset($item['region_id'])) { 64 | $item[$this->getData('name')] = [ 65 | 'edit' => [ 66 | 'href' => $this->_urlBuilder->getUrl( 67 | static::URL_PATH_EDIT, 68 | [ 69 | 'region_id' => $item['region_id'] 70 | ] 71 | ), 72 | 'label' => __('Edit') 73 | ], 74 | 'delete' => [ 75 | 'href' => $this->_urlBuilder->getUrl( 76 | static::URL_PATH_DELETE, 77 | [ 78 | 'region_id' => $item['region_id'] 79 | ] 80 | ), 81 | 'label' => __('Delete'), 82 | 'confirm' => [ 83 | 'title' => __('Delete "${ $.$data.default_name }"'), 84 | 'message' => __('Are you sure you wan\'t to delete the Region "${ $.$data.default_name }" ?') 85 | ] 86 | ] 87 | ]; 88 | } 89 | } 90 | } 91 | return $dataSource; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-cuong/magento2-regions-manager", 3 | "description":"Manage regions in magento2 addresses", 4 | "keywords": [ 5 | "magento 2", 6 | "Regions", 7 | "States", 8 | "Provinces", 9 | "Addresses", 10 | "Manage regions in magento2 addresses" 11 | ], 12 | "require": { 13 | "php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0", 14 | "magento/module-backend": "100.0.*|100.1.*|100.2.*", 15 | "magento/framework": "100.0.*|100.1.*|101.0.*" 16 | }, 17 | "type": "magento2-module", 18 | "version": "2.2.1", 19 | "license": [ 20 | "OSL-3.0", 21 | "AFL-3.0" 22 | ], 23 | "authors": [ 24 | { 25 | "name": "Cuong NQ", 26 | "email": "bestearnmoney87@gmail.com", 27 | "role": "Developer" 28 | } 29 | ], 30 | "autoload": { 31 | "files": [ 32 | "registration.php" 33 | ], 34 | "psr-4": { 35 | "PHPCuong\\Region\\": "" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /etc/acl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /etc/adminhtml/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /etc/adminhtml/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter 7 | Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter 8 | 9 | 10 | 11 | 12 | 13 | PHPCuong\Region\Model\ResourceModel\Region\Collection 14 | PHPCuongRegionGirdFilterPool 15 | 16 | 17 | 18 | 19 | directory_country_region 20 | directory_country_region_grid_collection 21 | region_grid_collection 22 | PHPCuong\Region\Model\ResourceModel\Region 23 | 24 | 25 | 26 | 27 | 28 | PHPCuong\Region\Model\ResourceModel\Region\Grid\Collection 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /regions-manager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-cuong/magento2-regions-manager/d79722f7f157c78672d0a032858248eeacd3c756/regions-manager.png -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 6 | * @Date 2016-12-11 02:38:44 7 | * @Last modified by: nquangcuong 8 | * @Last Modified time: 2016-12-12 02:58:45 9 | */ 10 | 11 | \Magento\Framework\Component\ComponentRegistrar::register( 12 | \Magento\Framework\Component\ComponentRegistrar::MODULE, 13 | 'PHPCuong_Region', 14 | __DIR__ 15 | ); 16 | -------------------------------------------------------------------------------- /view/adminhtml/layout/phpcuong_region_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /view/adminhtml/layout/phpcuong_region_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Magento_Customer::customer 8 | 9 | 10 | 11 | 12 | Manage regions in addresses 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /view/adminhtml/layout/phpcuong_region_new.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /view/adminhtml/templates/footer/copyright.phtml: -------------------------------------------------------------------------------- 1 | " id="footer_bug_tracking"> 2 | 3 | -------------------------------------------------------------------------------- /view/adminhtml/templates/footer/version.phtml: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |

5 | -------------------------------------------------------------------------------- /view/adminhtml/ui_component/region_listing.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | region_listing.region_listing_data_source 6 | region_listing.region_listing_data_source 7 | 8 | phpcuong_region_region_columns 9 | 10 | 11 | add 12 | Add New Region 13 | primary 14 | */*/new 15 | 16 | 17 | 18 | 19 | 20 | PHPCuongRegionRegionGridDataProvider 21 | region_listing_data_source 22 | region_id 23 | region_id 24 | 25 | 26 | Magento_Ui/js/grid/provider 27 | 28 | 29 | region_id 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | ui/grid/toolbar 39 | ui/grid/sticky/toolbar 40 | 41 | 42 | 43 | 44 | 45 | 46 | region_listing 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | region_listing.region_listing.phpcuong_region_region_columns 56 | 57 | Magento_Ui/js/grid/controls/columns 58 | dataGridActions 59 | 60 | 61 | 62 | 63 | 64 | 65 | region_listing.region_listing.phpcuong_region_region_columns.ids 66 | 67 | 68 | 69 | 70 | 71 | 72 | region_listing.region_listing_data_source 73 | region_listing.region_listing.listing_top.listing_filters_chips 74 | 75 | region_listing.region_listing.listing_top.bookmarks 76 | current.search 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | region_listing.region_listing.phpcuong_region_region_columns 85 | 86 | region_listing.region_listing.listing_top.bookmarks 87 | current.filters 88 | 89 | 90 | 91 | 92 | Magento_Ui/js/form/element/ui-select 93 | ui/grid/filters/elements/ui-select 94 | 95 | 96 | 97 | 98 | region_listing.region_listing.listing_top.listing_filters 99 | 100 | region_listing.region_listing.phpcuong_region_region_columns.${ $.index }:visible 101 | 102 | 103 | 104 | 105 | column 106 | 107 | 108 | 109 | 110 | 111 | 112 | region_listing.region_listing.phpcuong_region_region_columns.ids 113 | region_id 114 | 115 | 116 | 117 | 118 | 119 | delete 120 | Delete 121 | 122 | 123 | Delete Regions 124 | Are you sure you wan't to delete selected Regions? 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | region_listing.region_listing.listing_top.bookmarks 135 | current.paging 136 | 137 | region_listing.region_listing.phpcuong_region_region_columns.ids 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | false 147 | 55 148 | region_id 149 | 150 | 151 | 152 | 153 | 154 | 155 | textRange 156 | desc 157 | ID 158 | 159 | 160 | 161 | 162 | 163 | Magento\Config\Model\Config\Source\Locale\Country 164 | 165 | select 166 | Country 167 | Magento_Ui/js/grid/columns/select 168 | select 169 | 170 | 171 | 172 | 173 | 174 | 175 | text 176 | Region Name 177 | text 178 | 179 | 180 | 181 | 182 | 183 | 184 | text 185 | Region code 186 | text 187 | 188 | 189 | 190 | 191 | 192 | 193 | false 194 | 107 195 | region_id 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/Read Me.txt: -------------------------------------------------------------------------------- 1 | Open *demo.html* to see a list of all the glyphs in your font along with their codes/ligatures. 2 | 3 | To use the generated font in desktop programs, you can install the TTF font. In order to copy the character associated with each icon, refer to the text box at the bottom right corner of each glyph in demo.html. The character inside this text box may be invisible; but it can still be copied. See this guide for more info: https://icomoon.io/#docs/local-fonts 4 | 5 | You won't need any of the files located under the *demo-files* directory when including the generated font in your own projects. 6 | 7 | You can import *selection.json* back to the IcoMoon app using the *Import Icons* button (or via Main Menu → Manage Projects) to retrieve your icon selection. 8 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/demo-files/demo.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 0; 3 | margin: 0; 4 | font-family: sans-serif; 5 | font-size: 1em; 6 | line-height: 1.5; 7 | color: #555; 8 | background: #fff; 9 | } 10 | h1 { 11 | font-size: 1.5em; 12 | font-weight: normal; 13 | } 14 | small { 15 | font-size: .66666667em; 16 | } 17 | a { 18 | color: #e74c3c; 19 | text-decoration: none; 20 | } 21 | a:hover, a:focus { 22 | box-shadow: 0 1px #e74c3c; 23 | } 24 | .bshadow0, input { 25 | box-shadow: inset 0 -2px #e7e7e7; 26 | } 27 | input:hover { 28 | box-shadow: inset 0 -2px #ccc; 29 | } 30 | input, fieldset { 31 | font-family: sans-serif; 32 | font-size: 1em; 33 | margin: 0; 34 | padding: 0; 35 | border: 0; 36 | } 37 | input { 38 | color: inherit; 39 | line-height: 1.5; 40 | height: 1.5em; 41 | padding: .25em 0; 42 | } 43 | input:focus { 44 | outline: none; 45 | box-shadow: inset 0 -2px #449fdb; 46 | } 47 | .glyph { 48 | font-size: 16px; 49 | width: 15em; 50 | padding-bottom: 1em; 51 | margin-right: 4em; 52 | margin-bottom: 1em; 53 | float: left; 54 | overflow: hidden; 55 | } 56 | .liga { 57 | width: 80%; 58 | width: calc(100% - 2.5em); 59 | } 60 | .talign-right { 61 | text-align: right; 62 | } 63 | .talign-center { 64 | text-align: center; 65 | } 66 | .bgc1 { 67 | background: #f1f1f1; 68 | } 69 | .fgc1 { 70 | color: #999; 71 | } 72 | .fgc0 { 73 | color: #000; 74 | } 75 | p { 76 | margin-top: 1em; 77 | margin-bottom: 1em; 78 | } 79 | .mvm { 80 | margin-top: .75em; 81 | margin-bottom: .75em; 82 | } 83 | .mtn { 84 | margin-top: 0; 85 | } 86 | .mtl, .mal { 87 | margin-top: 1.5em; 88 | } 89 | .mbl, .mal { 90 | margin-bottom: 1.5em; 91 | } 92 | .mal, .mhl { 93 | margin-left: 1.5em; 94 | margin-right: 1.5em; 95 | } 96 | .mhmm { 97 | margin-left: 1em; 98 | margin-right: 1em; 99 | } 100 | .mls { 101 | margin-left: .25em; 102 | } 103 | .ptl { 104 | padding-top: 1.5em; 105 | } 106 | .pbs, .pvs { 107 | padding-bottom: .25em; 108 | } 109 | .pvs, .pts { 110 | padding-top: .25em; 111 | } 112 | .unit { 113 | float: left; 114 | } 115 | .unitRight { 116 | float: right; 117 | } 118 | .size1of2 { 119 | width: 50%; 120 | } 121 | .size1of1 { 122 | width: 100%; 123 | } 124 | .clearfix:before, .clearfix:after { 125 | content: " "; 126 | display: table; 127 | } 128 | .clearfix:after { 129 | clear: both; 130 | } 131 | .hidden-true { 132 | display: none; 133 | } 134 | .textbox0 { 135 | width: 3em; 136 | background: #f1f1f1; 137 | padding: .25em .5em; 138 | line-height: 1.5; 139 | height: 1.5em; 140 | } 141 | #testDrive { 142 | display: block; 143 | padding-top: 24px; 144 | line-height: 1.5; 145 | } 146 | .fs0 { 147 | font-size: 16px; 148 | } 149 | .fs1 { 150 | font-size: 32px; 151 | } 152 | .fs2 { 153 | font-size: 32px; 154 | } 155 | 156 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/demo-files/demo.js: -------------------------------------------------------------------------------- 1 | if (!('boxShadow' in document.body.style)) { 2 | document.body.setAttribute('class', 'noBoxShadow'); 3 | } 4 | 5 | document.body.addEventListener("click", function(e) { 6 | var target = e.target; 7 | if (target.tagName === "INPUT" && 8 | target.getAttribute('class').indexOf('liga') === -1) { 9 | target.select(); 10 | } 11 | }); 12 | 13 | (function() { 14 | var fontSize = document.getElementById('fontSize'), 15 | testDrive = document.getElementById('testDrive'), 16 | testText = document.getElementById('testText'); 17 | function updateTest() { 18 | testDrive.innerHTML = testText.value || String.fromCharCode(160); 19 | if (window.icomoonLiga) { 20 | window.icomoonLiga(testDrive); 21 | } 22 | } 23 | function updateSize() { 24 | testDrive.style.fontSize = fontSize.value + 'px'; 25 | } 26 | fontSize.addEventListener('change', updateSize, false); 27 | testText.addEventListener('input', updateTest, false); 28 | testText.addEventListener('change', updateTest, false); 29 | updateSize(); 30 | }()); 31 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IcoMoon Demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |

Font Name: faq-extension (Glyphs: 9)

17 |
18 |
19 |

Grid Size: Unknown

20 |
21 |
22 | 23 | 24 | 25 | faq-iconicon-gpg 26 |
27 |
28 | 29 | 30 |
31 |
32 | liga: 33 | 34 |
35 |
36 |
37 |
38 | 39 | 40 | 41 | faq-iconfaq-icon 42 |
43 |
44 | 45 | 46 |
47 |
48 | liga: 49 | 50 |
51 |
52 |
53 |
54 |

Grid Size: 16

55 |
56 |
57 | 58 | 59 | 60 | faq-iconcalendar 61 |
62 |
63 | 64 | 65 |
66 |
67 | liga: 68 | 69 |
70 |
71 |
72 |
73 | 74 | 75 | 76 | faq-iconuser 77 |
78 |
79 | 80 | 81 |
82 |
83 | liga: 84 | 85 |
86 |
87 |
88 |
89 | 90 | 91 | 92 | faq-iconeye 93 |
94 |
95 | 96 | 97 |
98 |
99 | liga: 100 | 101 |
102 |
103 |
104 |
105 | 106 | 107 | 108 | faq-iconhappy 109 |
110 |
111 | 112 | 113 |
114 |
115 | liga: 116 | 117 |
118 |
119 |
120 |
121 | 122 | 123 | 124 | faq-iconangry 125 |
126 |
127 | 128 | 129 |
130 |
131 | liga: 132 | 133 |
134 |
135 |
136 |
137 | 138 | 139 | 140 | faq-iconplus 141 |
142 |
143 | 144 | 145 |
146 |
147 | liga: 148 | 149 |
150 |
151 |
152 |
153 | 154 | 155 | 156 | faq-iconminus 157 |
158 |
159 | 160 | 161 |
162 |
163 | liga: 164 | 165 |
166 |
167 |
168 | 169 | 170 |
171 |

Font Test Drive

172 | 177 | 179 |
  180 |
181 |
182 | 183 |
184 |

Generated by IcoMoon

185 |
186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/fonts/faq-extension.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-cuong/magento2-regions-manager/d79722f7f157c78672d0a032858248eeacd3c756/view/base/web/css/faq-extension/fonts/faq-extension.eot -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/fonts/faq-extension.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Generated by IcoMoon 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/fonts/faq-extension.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-cuong/magento2-regions-manager/d79722f7f157c78672d0a032858248eeacd3c756/view/base/web/css/faq-extension/fonts/faq-extension.ttf -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/fonts/faq-extension.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-cuong/magento2-regions-manager/d79722f7f157c78672d0a032858248eeacd3c756/view/base/web/css/faq-extension/fonts/faq-extension.woff -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/ie7/ie7.css: -------------------------------------------------------------------------------- 1 | .faq-iconicon-gpg { 2 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 3 | } 4 | .faq-iconfaq-icon { 5 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 6 | } 7 | .faq-iconcalendar { 8 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 9 | } 10 | .faq-iconuser { 11 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 12 | } 13 | .faq-iconeye { 14 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 15 | } 16 | .faq-iconhappy { 17 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 18 | } 19 | .faq-iconangry { 20 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 21 | } 22 | .faq-iconplus { 23 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 24 | } 25 | .faq-iconminus { 26 | *zoom: expression(this.runtimeStyle['zoom'] = '1', this.innerHTML = ''); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/ie7/ie7.js: -------------------------------------------------------------------------------- 1 | /* To avoid CSS expressions while still supporting IE 7 and IE 6, use this script */ 2 | /* The script tag referencing this file must be placed before the ending body tag. */ 3 | 4 | /* Use conditional comments in order to target IE 7 and older: 5 | 6 | 7 | 8 | */ 9 | 10 | (function() { 11 | function addIcon(el, entity) { 12 | var html = el.innerHTML; 13 | el.innerHTML = '' + entity + '' + html; 14 | } 15 | var icons = { 16 | 'faq-iconicon-gpg': '', 17 | 'faq-iconfaq-icon': '', 18 | 'faq-iconcalendar': '', 19 | 'faq-iconuser': '', 20 | 'faq-iconeye': '', 21 | 'faq-iconhappy': '', 22 | 'faq-iconangry': '', 23 | 'faq-iconplus': '', 24 | 'faq-iconminus': '', 25 | '0': 0 26 | }, 27 | els = document.getElementsByTagName('*'), 28 | i, c, el; 29 | for (i = 0; ; i += 1) { 30 | el = els[i]; 31 | if(!el) { 32 | break; 33 | } 34 | c = el.className; 35 | c = c.match(/faq-icon[^\s'"]+/); 36 | if (c && icons[c[0]]) { 37 | addIcon(el, icons[c[0]]); 38 | } 39 | } 40 | }()); 41 | -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/selection.json: -------------------------------------------------------------------------------- 1 | { 2 | "IcoMoonType": "selection", 3 | "icons": [ 4 | { 5 | "icon": { 6 | "paths": [ 7 | "M442.288 20.347c-72.714 7.672-162.439 44.029-225.814 91.393-173.78 130.085-242.158 357.9-171.445 570.705 8.672 25.35 37.691 84.055 52.701 106.403 23.682 35.023 47.364 62.707 78.384 92.060 141.759 133.42 353.23 166.775 529.678 82.721 157.769-75.049 261.504-226.147 278.515-404.93 6.004-64.375-0.334-125.749-19.346-190.124-24.683-84.055-67.711-155.435-129.751-215.474-106.403-102.4-242.491-148.764-392.922-132.753zM318.541 383.25c9.339 4.003 21.014 11.341 26.35 16.344 9.006 8.339 25.35 38.025 25.35 46.030 0 4.67-51.367 16.010-52.701 11.674-0.667-1.668-5.337-9.339-10.674-16.678-11.674-16.010-29.352-22.014-55.369-18.679-23.682 3.002-37.691 13.008-48.698 34.689-16.010 31.687-12.008 81.72 9.006 109.071 17.345 22.681 57.371 27.351 90.392 11.007 15.343-7.338 16.344-9.006 17.345-22.014l1.001-14.009-58.705-2.001-1.001-22.681-1.001-22.348h113.741v102.734l-11.674 9.006c-6.671 5.003-24.349 13.342-39.359 19.012-62.040 23.015-129.418 8.005-160.104-36.357-17.011-24.683-24.016-49.032-23.682-86.056 0-28.352 1.334-36.357 8.672-54.369 15.677-37.024 33.355-54.035 70.046-67.711 25.016-9.339 77.384-7.672 101.066 3.336zM811.195 380.248c22.681 7.005 43.362 24.349 54.035 45.696 9.673 19.346 7.672 23.349-13.676 27.685-10.674 2.001-22.681 4.67-26.35 5.67-5.337 1.001-7.672-0.334-9.339-6.671-1.001-4.67-7.005-12.675-13.342-18.345-31.354-27.351-90.726-10.007-102.066 29.686-4.336 15.010-4.336 61.373 0.334 77.384 11.007 40.36 59.038 56.704 104.068 35.69 15.010-7.005 15.677-8.005 15.677-22.014v-14.343l-55.036-2.001-1.001-22.681-1.001-22.348h110.405v51.033c0 60.039 0.667 58.705-38.358 75.382-33.689 14.009-62.707 18.679-90.392 14.009-44.029-7.672-76.383-31.354-93.728-68.711-8.672-18.679-9.339-23.015-9.339-63.375 0-43.028 0-43.362 11.341-64.375 14.676-27.018 38.358-48.365 63.041-56.704 26.017-9.339 66.377-9.339 94.728-0.667zM572.039 386.919c53.368 26.684 50.7 116.743-4.336 140.758-10.34 4.67-25.683 7.005-55.703 8.339l-41.694 2.001v92.393h-53.368v-254.165l69.379 1.001c65.709 1.334 69.712 1.668 85.722 9.673z", 8 | "M470.306 456.964v33.355h28.352c40.693 0 55.036-8.672 55.036-33.355 0-24.349-15.343-33.355-56.704-33.355h-26.684v33.355z" 9 | ], 10 | "attrs": [ 11 | {}, 12 | {} 13 | ], 14 | "width": 1001, 15 | "isMulticolor": false, 16 | "isMulticolor2": false, 17 | "grid": 0, 18 | "tags": [ 19 | "icon-gpg" 20 | ] 21 | }, 22 | "attrs": [ 23 | {}, 24 | {} 25 | ], 26 | "properties": { 27 | "order": 2, 28 | "id": 0, 29 | "name": "icon-gpg", 30 | "prevSize": 32, 31 | "code": 59649 32 | }, 33 | "setIdx": 0, 34 | "setId": 4, 35 | "iconIdx": 0 36 | }, 37 | { 38 | "icon": { 39 | "paths": [ 40 | "M127.052 67.002c-75.22 37.926-91.022 87.862-86.598 270.538 4.425 192.158 18.331 223.763 109.353 256l52.464 18.963v224.395l123.891-113.778 123.259-113.778 147.279-4.425c228.188-6.953 250.311-31.605 249.679-282.548-0.632-271.17-1.264-271.802-397.59-271.802-207.328 0.632-299.615 5.057-321.738 16.435zM715.536 246.519c34.765 34.765 40.454 194.686 7.585 205.432-8.217 3.16-15.17 0-15.17-6.953s-24.020-9.481-54.993-5.689c-48.040 5.057-58.153 1.896-82.173-28.444-87.862-111.881 45.511-262.953 144.751-164.346zM316.049 246.519c0 13.906-14.538 18.963-56.889 18.963-49.304 0-56.889 3.793-56.889 26.548 0 22.123 6.321 25.284 47.407 22.123 35.398-3.16 47.407 0 47.407 14.538 0 12.642-15.17 20.227-47.407 22.756-44.879 3.793-47.407 6.321-47.407 47.407 0 35.398-5.057 43.615-25.284 43.615-23.388 0-25.284-8.217-25.284-107.457v-107.457h82.173c64.474 0 82.173 3.793 82.173 18.963zM485.452 325.531c18.331 53.728 32.869 102.4 32.869 107.457 0 21.491-48.040 7.585-54.36-15.802-4.425-18.331-17.067-25.284-44.247-25.284s-39.19 6.953-44.247 25.284c-3.793 15.17-17.067 25.284-32.869 25.284-25.916 0-25.916 0-2.528-60.049 12.642-32.869 29.709-81.541 38.558-107.457 27.812-85.965 67.635-67.002 106.825 50.568zM317.946 518.321c32.869 0 42.983 26.548 17.067 45.511-22.756 17.067-65.106 5.057-84.069-24.020-11.378-17.699 17.699-47.407 32.869-32.869 6.321 6.321 22.123 11.378 34.133 11.378z", 41 | "M616.296 266.746c-25.916 15.17-30.973 98.607-6.953 122.627 22.123 22.123 45.511 18.331 43.615-6.953-1.264-14.538 5.689-20.859 20.227-18.331 32.869 5.689 30.973-80.277-2.528-97.975-29.077-15.802-26.548-15.802-54.36 0.632z", 42 | "M412.76 309.728c-12.642 32.869-10.114 44.247 10.746 44.247s24.652-22.123 7.585-48.672c-8.217-13.274-12.010-12.642-18.331 4.425z", 43 | "M897.58 361.56c0 250.311-30.341 283.18-261.689 283.812h-136.533l-53.728 50.568c-69.531 65.738-68.267 67.002 25.284 56.889l79.644-8.217 118.202 120.731c65.106 66.37 120.731 120.731 123.259 120.731s4.425-54.36 4.425-120.099c0-120.099 0-120.099 32.237-120.099 122.627 0 157.393-60.049 157.393-271.802 0-166.874-8.849-203.536-61.946-251.575l-26.548-24.020v163.081z" 44 | ], 45 | "attrs": [ 46 | { 47 | "fill": "rgb(255, 255, 255)" 48 | }, 49 | { 50 | "fill": "rgb(255, 255, 255)" 51 | }, 52 | { 53 | "fill": "rgb(255, 255, 255)" 54 | }, 55 | { 56 | "fill": "rgb(255, 255, 255)" 57 | } 58 | ], 59 | "isMulticolor": false, 60 | "isMulticolor2": false, 61 | "tags": [ 62 | "faq-icon" 63 | ], 64 | "grid": 0 65 | }, 66 | "attrs": [ 67 | { 68 | "fill": "rgb(255, 255, 255)" 69 | }, 70 | { 71 | "fill": "rgb(255, 255, 255)" 72 | }, 73 | { 74 | "fill": "rgb(255, 255, 255)" 75 | }, 76 | { 77 | "fill": "rgb(255, 255, 255)" 78 | } 79 | ], 80 | "properties": { 81 | "order": 5, 82 | "id": 0, 83 | "name": "faq-icon", 84 | "prevSize": 32, 85 | "code": 59648 86 | }, 87 | "setIdx": 1, 88 | "setId": 3, 89 | "iconIdx": 0 90 | }, 91 | { 92 | "icon": { 93 | "paths": [ 94 | "M320 384h128v128h-128zM512 384h128v128h-128zM704 384h128v128h-128zM128 768h128v128h-128zM320 768h128v128h-128zM512 768h128v128h-128zM320 576h128v128h-128zM512 576h128v128h-128zM704 576h128v128h-128zM128 576h128v128h-128zM832 0v64h-128v-64h-448v64h-128v-64h-128v1024h960v-1024h-128zM896 960h-832v-704h832v704z" 95 | ], 96 | "attrs": [], 97 | "isMulticolor": false, 98 | "isMulticolor2": false, 99 | "tags": [ 100 | "calendar", 101 | "date", 102 | "schedule", 103 | "time", 104 | "day" 105 | ], 106 | "defaultCode": 59731, 107 | "grid": 16 108 | }, 109 | "attrs": [], 110 | "properties": { 111 | "ligatures": "calendar, date", 112 | "name": "calendar", 113 | "order": 8, 114 | "id": 0, 115 | "prevSize": 32, 116 | "code": 59731 117 | }, 118 | "setIdx": 2, 119 | "setId": 2, 120 | "iconIdx": 0 121 | }, 122 | { 123 | "icon": { 124 | "paths": [ 125 | "M576 706.612v-52.78c70.498-39.728 128-138.772 128-237.832 0-159.058 0-288-192-288s-192 128.942-192 288c0 99.060 57.502 198.104 128 237.832v52.78c-217.102 17.748-384 124.42-384 253.388h896c0-128.968-166.898-235.64-384-253.388z" 126 | ], 127 | "attrs": [], 128 | "isMulticolor": false, 129 | "isMulticolor2": false, 130 | "tags": [ 131 | "user", 132 | "profile", 133 | "avatar", 134 | "person", 135 | "member" 136 | ], 137 | "defaultCode": 59761, 138 | "grid": 16 139 | }, 140 | "attrs": [], 141 | "properties": { 142 | "ligatures": "user, profile2", 143 | "name": "user", 144 | "order": 7, 145 | "id": 1, 146 | "prevSize": 32, 147 | "code": 59761 148 | }, 149 | "setIdx": 2, 150 | "setId": 2, 151 | "iconIdx": 1 152 | }, 153 | { 154 | "icon": { 155 | "paths": [ 156 | "M512 192c-223.318 0-416.882 130.042-512 320 95.118 189.958 288.682 320 512 320 223.312 0 416.876-130.042 512-320-95.116-189.958-288.688-320-512-320zM764.45 361.704c60.162 38.374 111.142 89.774 149.434 150.296-38.292 60.522-89.274 111.922-149.436 150.296-75.594 48.218-162.89 73.704-252.448 73.704-89.56 0-176.858-25.486-252.452-73.704-60.158-38.372-111.138-89.772-149.432-150.296 38.292-60.524 89.274-111.924 149.434-150.296 3.918-2.5 7.876-4.922 11.86-7.3-9.96 27.328-15.41 56.822-15.41 87.596 0 141.382 114.616 256 256 256 141.382 0 256-114.618 256-256 0-30.774-5.452-60.268-15.408-87.598 3.978 2.378 7.938 4.802 11.858 7.302v0zM512 416c0 53.020-42.98 96-96 96s-96-42.98-96-96 42.98-96 96-96 96 42.982 96 96z" 157 | ], 158 | "attrs": [], 159 | "isMulticolor": false, 160 | "isMulticolor2": false, 161 | "tags": [ 162 | "eye", 163 | "views", 164 | "vision", 165 | "visit" 166 | ], 167 | "defaultCode": 59854, 168 | "grid": 16 169 | }, 170 | "attrs": [], 171 | "properties": { 172 | "ligatures": "eye, views", 173 | "name": "eye", 174 | "order": 6, 175 | "id": 2, 176 | "prevSize": 32, 177 | "code": 59854 178 | }, 179 | "setIdx": 2, 180 | "setId": 2, 181 | "iconIdx": 2 182 | }, 183 | { 184 | "icon": { 185 | "paths": [ 186 | "M512 1024c282.77 0 512-229.23 512-512s-229.23-512-512-512-512 229.23-512 512 229.23 512 512 512zM512 96c229.75 0 416 186.25 416 416s-186.25 416-416 416-416-186.25-416-416 186.25-416 416-416zM512 598.76c115.95 0 226.23-30.806 320-84.92-14.574 178.438-153.128 318.16-320 318.16-166.868 0-305.422-139.872-320-318.304 93.77 54.112 204.050 85.064 320 85.064zM256 352c0-53.019 28.654-96 64-96s64 42.981 64 96c0 53.019-28.654 96-64 96s-64-42.981-64-96zM640 352c0-53.019 28.654-96 64-96s64 42.981 64 96c0 53.019-28.654 96-64 96s-64-42.981-64-96z" 187 | ], 188 | "attrs": [], 189 | "isMulticolor": false, 190 | "isMulticolor2": false, 191 | "tags": [ 192 | "happy", 193 | "emoticon", 194 | "smiley", 195 | "face" 196 | ], 197 | "defaultCode": 59871, 198 | "grid": 16 199 | }, 200 | "attrs": [], 201 | "properties": { 202 | "ligatures": "happy, emoticon", 203 | "name": "happy", 204 | "order": 4, 205 | "id": 3, 206 | "prevSize": 32, 207 | "code": 59871 208 | }, 209 | "setIdx": 2, 210 | "setId": 2, 211 | "iconIdx": 3 212 | }, 213 | { 214 | "icon": { 215 | "paths": [ 216 | "M512 1024c282.77 0 512-229.23 512-512s-229.23-512-512-512-512 229.23-512 512 229.23 512 512 512zM512 96c229.75 0 416 186.25 416 416s-186.25 416-416 416-416-186.25-416-416 186.25-416 416-416zM704.098 780.74c-39.174-65.148-110.544-108.74-192.098-108.74-81.556 0-152.924 43.592-192.098 108.74l-82.328-49.396c55.96-93.070 157.916-155.344 274.426-155.344 116.508 0 218.464 62.274 274.426 155.344l-82.328 49.396zM767.042 280.24c4.284 17.144-6.14 34.518-23.282 38.804-17.626 4.45-38.522 12.12-56.936 21.35 10.648 11.43 17.174 26.752 17.174 43.606 0 35.346-28.654 64-64 64s-64-28.654-64-64c0-1.17 0.036-2.33 0.098-3.484 2.032-47.454 45.212-78.946 81.592-97.138 34.742-17.37 69.102-26.060 70.548-26.422 17.146-4.288 34.518 6.138 38.806 23.284zM256.958 280.24c4.288-17.146 21.66-27.572 38.806-23.284 1.446 0.362 35.806 9.052 70.548 26.422 36.38 18.192 79.56 49.684 81.592 97.138 0.062 1.154 0.098 2.314 0.098 3.484 0 35.346-28.654 64-64 64s-64-28.654-64-64c0-16.854 6.526-32.176 17.174-43.606-18.414-9.23-39.31-16.9-56.936-21.35-17.142-4.286-27.566-21.66-23.282-38.804z" 217 | ], 218 | "attrs": [], 219 | "isMulticolor": false, 220 | "isMulticolor2": false, 221 | "tags": [ 222 | "angry", 223 | "emoticon", 224 | "smiley", 225 | "face", 226 | "rage" 227 | ], 228 | "defaultCode": 59885, 229 | "grid": 16 230 | }, 231 | "attrs": [], 232 | "properties": { 233 | "ligatures": "angry, emoticon15", 234 | "name": "angry", 235 | "order": 5, 236 | "id": 4, 237 | "prevSize": 32, 238 | "code": 59885 239 | }, 240 | "setIdx": 2, 241 | "setId": 2, 242 | "iconIdx": 4 243 | }, 244 | { 245 | "icon": { 246 | "paths": [ 247 | "M992 384h-352v-352c0-17.672-14.328-32-32-32h-192c-17.672 0-32 14.328-32 32v352h-352c-17.672 0-32 14.328-32 32v192c0 17.672 14.328 32 32 32h352v352c0 17.672 14.328 32 32 32h192c17.672 0 32-14.328 32-32v-352h352c17.672 0 32-14.328 32-32v-192c0-17.672-14.328-32-32-32z" 248 | ], 249 | "attrs": [], 250 | "isMulticolor": false, 251 | "isMulticolor2": false, 252 | "tags": [ 253 | "plus", 254 | "add", 255 | "sum" 256 | ], 257 | "defaultCode": 59914, 258 | "grid": 16 259 | }, 260 | "attrs": [], 261 | "properties": { 262 | "ligatures": "plus, add", 263 | "name": "plus", 264 | "order": 2, 265 | "id": 5, 266 | "prevSize": 32, 267 | "code": 59914 268 | }, 269 | "setIdx": 2, 270 | "setId": 2, 271 | "iconIdx": 5 272 | }, 273 | { 274 | "icon": { 275 | "paths": [ 276 | "M0 416v192c0 17.672 14.328 32 32 32h960c17.672 0 32-14.328 32-32v-192c0-17.672-14.328-32-32-32h-960c-17.672 0-32 14.328-32 32z" 277 | ], 278 | "attrs": [], 279 | "isMulticolor": false, 280 | "isMulticolor2": false, 281 | "tags": [ 282 | "minus", 283 | "subtract", 284 | "minimize", 285 | "line" 286 | ], 287 | "defaultCode": 59915, 288 | "grid": 16 289 | }, 290 | "attrs": [], 291 | "properties": { 292 | "ligatures": "minus, subtract", 293 | "name": "minus", 294 | "order": 3, 295 | "id": 6, 296 | "prevSize": 32, 297 | "code": 59915 298 | }, 299 | "setIdx": 2, 300 | "setId": 2, 301 | "iconIdx": 6 302 | } 303 | ], 304 | "height": 1024, 305 | "metadata": { 306 | "name": "faq-extension" 307 | }, 308 | "preferences": { 309 | "showGlyphs": true, 310 | "showQuickUse": true, 311 | "showQuickUse2": true, 312 | "showSVGs": true, 313 | "fontPref": { 314 | "prefix": "faq-icon", 315 | "metadata": { 316 | "fontFamily": "faq-extension", 317 | "majorVersion": 1, 318 | "minorVersion": 0 319 | }, 320 | "metrics": { 321 | "emSize": 1024, 322 | "baseline": 6.25, 323 | "whitespace": 50 324 | }, 325 | "embed": false, 326 | "ie7": true, 327 | "noie8": false, 328 | "showSelector": false 329 | }, 330 | "imagePref": { 331 | "prefix": "icon-", 332 | "png": true, 333 | "useClassSelector": true, 334 | "color": 0, 335 | "bgColor": 16777215, 336 | "classSelector": ".icon" 337 | }, 338 | "historySize": 100, 339 | "showCodes": true, 340 | "gridSize": 16 341 | } 342 | } -------------------------------------------------------------------------------- /view/base/web/css/faq-extension/style.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'faq-extension'; 3 | src: url('fonts/faq-extension.eot?e7yg6v'); 4 | src: url('fonts/faq-extension.eot?e7yg6v#iefix') format('embedded-opentype'), 5 | url('fonts/faq-extension.ttf?e7yg6v') format('truetype'), 6 | url('fonts/faq-extension.woff?e7yg6v') format('woff'), 7 | url('fonts/faq-extension.svg?e7yg6v#faq-extension') format('svg'); 8 | font-weight: normal; 9 | font-style: normal; 10 | } 11 | 12 | [class^="faq-icon"], [class*=" faq-icon"] { 13 | /* use !important to prevent issues with browser extensions that change fonts */ 14 | font-family: 'faq-extension' !important; 15 | speak: none; 16 | font-style: normal; 17 | font-weight: normal; 18 | font-variant: normal; 19 | text-transform: none; 20 | line-height: 1; 21 | 22 | /* Better Font Rendering =========== */ 23 | -webkit-font-smoothing: antialiased; 24 | -moz-osx-font-smoothing: grayscale; 25 | } 26 | 27 | .faq-iconicon-gpg:before { 28 | content: "\e901"; 29 | } 30 | .faq-iconfaq-icon:before { 31 | content: "\e900"; 32 | color: #fff; 33 | } 34 | .faq-iconcalendar:before { 35 | content: "\e953"; 36 | } 37 | .faq-iconuser:before { 38 | content: "\e971"; 39 | } 40 | .faq-iconeye:before { 41 | content: "\e9ce"; 42 | } 43 | .faq-iconhappy:before { 44 | content: "\e9df"; 45 | } 46 | .faq-iconangry:before { 47 | content: "\e9ed"; 48 | } 49 | .faq-iconplus:before { 50 | content: "\ea0a"; 51 | } 52 | .faq-iconminus:before { 53 | content: "\ea0b"; 54 | } 55 | --------------------------------------------------------------------------------