2014-01-10 78 views
2

我不確定爲什麼這不是Magento的庫存功能的一部分,但我希望客戶能夠通過兒童SKU搜索可配置產品。出於某種原因,Magento不會索引兒童SKU。將兒童SKU添加到Magento全文搜索索引

app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php

$dynamicFields = array(
    'int'  => array_keys($this->_getSearchableAttributes('int')), 
    'varchar' => array_keys($this->_getSearchableAttributes('varchar')), 
    'text'  => array_keys($this->_getSearchableAttributes('text')), 
    'decimal' => array_keys($this->_getSearchableAttributes('decimal')), 
    'datetime' => array_keys($this->_getSearchableAttributes('datetime')), 
); 

我試過幾個變化發現,沒有成功。 SKU是一個「靜態」屬性,可通過$this->_getSearchableAttributes('static')訪問。我沒有得到所有的靜態屬性,但它不工作。根據嘗試的結果,我得到的結果中沒有任何變化,或者靜態屬性表不存在(這是合理的,因爲靜態屬性在產品實體表中)。

有沒有人有解決這個問題的建議?

在線研究發現建議使用這些值添加隱藏屬性,但不應該需要這些值。我寧願妥善解決問題。

+0

「在線研究發現建議增加一個隱藏屬性使用這些值,但不應該是必要的。我寧願妥善解決問題。」 =>我會這樣做也與產品保存的觀察員更新此屬性 –

+0

我有困難實現您的解決方案任何指針? https://stackoverflow.com/questions/31812898/magento-return-grouped-product-when-searching-associated-products-sku – user552769

回答

2

這麼多的方式來做到這一點..

不過,我會的東西,我相信領導會更清潔,而不是在app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php實際全文圍繞擰。

問題是AFTER行是片斷你包括:

// status and visibility filter 
    $visibility  = $this->_getSearchableAttribute('visibility'); 
    $status   = $this->_getSearchableAttribute('status'); 
    $statusVals  = Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(); 
    $allowedVisibilityValues = $this->_engine->getAllowedVisibility(); 

最終導致:

核心/法師/ CatalogSearch /型號/資源/全文/ Engine.php

/** 
* Retrieve allowed visibility values for current engine 
* 
* @return array 
*/ 
public function getAllowedVisibility() 
{ 
    return Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds(); 
} 

然後:

核心/法師/目錄/型號/產品/ Visibility.php

public function getVisibleInSearchIds() 
{ 
    return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_BOTH); 
} 

因此,您需要做的是轉到與您的可配置關聯的簡單產品,並將可見性更改爲「搜索」。

Change in visibility options for simple product associated with config

然而,在這裏它是在現在就行動起來:

Zoinks! that doesn't look pretty at all

但是,是的,這看起來不漂亮的。下一個業務訂單正在修改搜索結果,以便當它列出與可配置產品相​​關聯的簡單產品項目時)。)可見性ID顯式設置爲Mage_Catalog_Model_Product_Visibility :: VISIBILITY_IN_SEARCH,您需要將項目搜索結果到實際可配置的產品父級(以及其他詳細信息,如圖像)。 (我會在稍後繼續,我的計算機決定廢on我,並且我失去了超過50%的寫作內容,甚至是我們修改全文類的部分!不過,請稍後再見。)

+0

這是一個有趣的方法。一旦父母替換結果中的孩子,您是否有任何提示,以防止同一父母產品在結果中多次顯示? – iJeep

0

有一個解決方案,但它是一種有償的擴展(我們許可的話),它是不是在建立到Magento的標準,所以你不能搜索的子節點屬性,就回到父配置/分組/包產品。

1

我用簡單的設置產品的知名度搜索的方法。然後,而不是顯示簡單的產品加載/顯示其父產品。

除了在循環性能問題的前端查詢我從來沒有發現這種解決方案非常滿意。所以在經過另一次重擊之後,我發現了另一種選擇。

我加入簡單的產品SKU的全文索引分組的產品,但同樣的方法應該可配置產品的工作。

這裏的理念是:

Mage_CatalogSearch_Model_Resource_Fulltext->_prepareProductIndex 

包含

$typeInstance = $this->_getProductTypeInstance($productData['type_id']); 
if ($data = $typeInstance->getSearchableData($product)) { 
    $index['options'] = $data; 
} 

因此,通過覆蓋在產品類型類getSearchableData方法,你可以將數據添加到全文索引。對於分組的產品我更新看起來像:

... extends Mage_Catalog_Model_Product_Type_Grouped 
{ 

/** 
* all child SKUs to search data 
*/ 
public function getSearchableData($product=null) 
{ 
    $searchData = parent::getSearchableData(); 
    $adapter = Mage::getSingleton('core/resource')->getConnection('core_read'); 
    $select = $adapter->select() 
     ->from(
      array('p' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 
      array('sku') 
     ) 
     ->joinLeft(
      array('r' => Mage::getSingleton('core/resource')->getTableName('catalog/product_relation')), 
      'r.child_id = p.entity_id', 
      array() 
     ) 
     ->where('r.parent_id = ?', $this->getProduct($product)->getId()); 
    $query = $adapter->query($select); 
    while ($row = $query->fetch()) { 
     $searchData[] = $row['sku']; 
    } 
    return $searchData; 
} 

重建索引搜索和catalogsearch_fulltext.dataindex應包含額外的數據。