Example #1
0
 /**
  * Get options
  *
  * @return array
  */
 public function toOptionArray()
 {
     $options[] = ['label' => '', 'value' => ''];
     $availableOptions = $this->brandModel->getAvailableStatuses();
     foreach ($availableOptions as $key => $value) {
         $options[] = ['label' => $value, 'value' => $key];
     }
     return $options;
 }
Example #2
0
 public function _initBrand()
 {
     $brandId = (int) $this->getRequest()->getParam('brand_id', false);
     if (!$brandId) {
         return false;
     }
     try {
         $brand = $this->_brandModel->load($brandId);
     } catch (NoSuchEntityException $e) {
         return false;
     }
     $this->_coreRegistry->register('current_brand', $brand);
     return $brand;
 }
Example #3
0
 public function _initGroup()
 {
     $groupId = (int) $this->getRequest()->getParam('group_id', false);
     if (!$groupId) {
         return false;
     }
     try {
         $group = $this->_groupModel->load($groupId);
     } catch (NoSuchEntityException $e) {
         return false;
     }
     $this->_coreRegistry->register('current_group_brand', $group);
     return $group;
 }
Example #4
0
 public function getGroupList()
 {
     $collection = $this->_group->getCollection()->addFieldToFilter('status', 1)->addFieldToFilter('shown_in_sidebar', 1)->setOrder('position', 'ASC');
     return $collection;
 }
Example #5
0
 /**
  * @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]);
             }
         }
     }
 }