/** * Options getter * * @return array */ public function toOptionArray() { $groups = $this->_group->getCollection()->addFieldToFilter('status', '1'); $groupList = array(); foreach ($groups as $group) { $groupList[] = array('label' => $group->getName(), 'value' => $group->getId()); } return $groupList; }
/** * @param RequestInterface $request * @return \Magento\Framework\App\ActionInterface */ public function match(RequestInterface $request) { $_brandHelper = $this->_brandHelper; if (!$this->dispatched) { $urlKey = trim($request->getPathInfo(), '/'); $origUrlKey = $urlKey; /** @var Object $condition */ $condition = new DataObject(['url_key' => $urlKey, 'continue' => true]); $this->eventManager->dispatch('ves_brand_controller_router_match_before', ['router' => $this, 'condition' => $condition]); $urlKey = $condition->getUrlKey(); if ($condition->getRedirectUrl()) { $this->response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); } if (!$condition->getContinue()) { return null; } $route = $_brandHelper->getConfig('general_settings/route'); if ($urlKey == $route) { $request->setModuleName('vesbrand')->setControllerName('index')->setActionName('index'); $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } $url_prefix = $_brandHelper->getConfig('general_settings/url_prefix'); $url_suffix = $_brandHelper->getConfig('general_settings/url_suffix'); $identifiers = explode('/', $urlKey); //Check Group Url if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = ''; if (trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = str_replace($url_suffix, '', $identifiers[0]); } if (count($identifiers) == 2) { $brandUrl = str_replace($url_suffix, '', $identifiers[1]); } $group = $this->_groupCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem(); if ($group && $group->getId()) { $request->setModuleName('vesbrand')->setControllerName('group')->setActionName('view')->setParam('group_id', $group->getId()); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } // Check Brand Url Key if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) { if (count($identifiers) == 2) { $brandUrl = str_replace($url_suffix, '', $identifiers[1]); } if (trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = str_replace($url_suffix, '', $identifiers[0]); } $brand = $this->_brandCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem(); if ($brand && $brand->getId() && (in_array($this->storeManager->getStore()->getId(), $brand->getStoreId()) || in_array(0, $brand->getStoreId()))) { $request->setModuleName('vesbrand')->setControllerName('brand')->setActionName('view')->setParam('brand_id', $brand->getId()); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } } }