Algolia_Algoliasearch_Helper_Entity_Categoryhelper::getIndexSettings PHP Method

getIndexSettings() public method

public getIndexSettings ( $storeId )
    public function getIndexSettings($storeId)
    {
        $attributesToIndex = array();
        $unretrievableAttributes = array();
        foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
            if ($attribute['searchable'] == '1') {
                if ($attribute['order'] == 'ordered') {
                    $attributesToIndex[] = $attribute['attribute'];
                } else {
                    $attributesToIndex[] = 'unordered(' . $attribute['attribute'] . ')';
                }
            }
            if ($attribute['retrievable'] != '1') {
                $unretrievableAttributes[] = $attribute['attribute'];
            }
        }
        $customRankings = $this->config->getCategoryCustomRanking($storeId);
        $customRankingsArr = array();
        foreach ($customRankings as $ranking) {
            $customRankingsArr[] = $ranking['order'] . '(' . $ranking['attribute'] . ')';
        }
        // Default index settings
        $indexSettings = array('attributesToIndex' => array_values(array_unique($attributesToIndex)), 'customRanking' => $customRankingsArr, 'unretrievableAttributes' => $unretrievableAttributes);
        // Additional index settings from event observer
        $transport = new Varien_Object($indexSettings);
        Mage::dispatchEvent('algolia_index_settings_prepare', array('store_id' => $storeId, 'index_settings' => $transport));
        $indexSettings = $transport->getData();
        $this->algolia_helper->mergeSettings($this->getIndexName($storeId), $indexSettings);
        return $indexSettings;
    }

Usage Example

Beispiel #1
0
 public function saveConfigurationToAlgolia($storeId, $saveToTmpIndicesToo = false)
 {
     $this->algolia_helper->resetCredentialsFromConfig();
     if (!($this->config->getApplicationID() && $this->config->getAPIKey())) {
         return;
     }
     if ($this->config->isEnabledBackend($storeId) === false) {
         $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
         return;
     }
     $this->algolia_helper->setSettings($this->category_helper->getIndexName($storeId), $this->category_helper->getIndexSettings($storeId));
     $this->algolia_helper->setSettings($this->page_helper->getIndexName($storeId), $this->page_helper->getIndexSettings($storeId));
     $this->algolia_helper->setSettings($this->suggestion_helper->getIndexName($storeId), $this->suggestion_helper->getIndexSettings($storeId));
     foreach ($this->config->getAutocompleteSections() as $section) {
         if ($section['name'] === 'products' || $section['name'] === 'categories' || $section['name'] === 'pages' || $section['name'] === 'suggestions') {
             continue;
         }
         $this->algolia_helper->setSettings($this->additionalsections_helper->getIndexName($storeId) . '_' . $section['name'], $this->additionalsections_helper->getIndexSettings($storeId));
     }
     $this->product_helper->setSettings($storeId, $saveToTmpIndicesToo);
 }