私はそれをしました。私はあなたと私の方法を共有したいと思います。すでにマジェンタで働いていた人には非常に簡単ですが、初心者には適していません。
'CatalogSearch'モジュールは、製品カタログによる検索を担当します。モジュールのパスは 'DOC_ROOT/app/code/core/Mage/CatalogSearch'です。
最初に、コアファイル( 'Mage'フォルダ内のファイル)を編集してコアクラスと機能を無効にする必要があります。 私の目標(私のトピックの質問)を達成するには、異なるクラスのいくつかの関数を編集する必要があるので、この関数をオーバーライドする必要があります。
シンプルとアドバンス(多分、私は別のことは分かっていません)という2種類の検索思考商品カタログです。これらの2つのタイプに影響を与えます。
ステップ1: Magentoエンジンに、コアクラスのいくつかを上書きしたいことを伝えてください。したがって、独自のモジュールを作成します。 '/アプリの/ etc /モジュール/' に移動し、ファイルを作成する 'YourCompany_YourModuleName.xml' フォローの内容で:
<?xml version="1.0"?>
<config>
<modules>
<YourCompany_YourModuleName>
<active>true</active>
<codePool>local</codePool>
</YourCompany_YourModuleName>
</modules>
</config>
ステップ2: は今、私たちは私たちのモジュールを作成する必要があります。 '/ app/code/local/YourCompany/YourModuleName /'に移動し、フォルダ 'etc'を作成します。この 'etc'フォルダに 'config.xml'ファイルを置くと、どのファイル/クラスを上書きするかをmagetnoに伝えなければなりません。
config.xmlの内容は:
<?xml version="1.0"?>
<config>
<modules>
<yourcompany_yourmodulename>
<version>0.1.0</version>
</yourcompany_yourmodulename>
</modules>
<global>
<models>
<catalogsearch>
<rewrite>
<layer>YourCompany_YourModuleName_Model_CatalogSearch_Layer</layer>
<advanced>YourCompany_YourModuleName_CatalogSearch_Advanced</advanced>
</rewrite>
</catalogsearch>
<catalogsearch_mysql4>
<rewrite>
<fulltext_collection>YourCompany_YourModuleName_Model_CatalogSearch_Mysql4_Fulltext_Collection</fulltext_collection>
<advanced_collection>YourCompany_YourModuleName_Model_CatalogSearch_Mysql4_Advanced_Collection</advanced_collection>
</rewrite>
</catalogsearch_mysql4>
</models>
</global>
</config>
今、あなたは、私たちは4クラスで4関数をオーバーライドすることに気づいたかもしれません。
ステップ3: フォローの内容と、当社のモジュール内の4つの新しいファイルを作成します。
'/app/code/local/YourCompany/YourModuleName/Model/CatalogSearch/Advanced.php'
class YourCompany_YourModuleName_Model_CatalogSearch_Advanced extends Mage_CatalogSearch_Model_Advanced
{
/**
* Retrieve advanced search product collection
*
* @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection
*/
public function getProductCollection(){
if (is_null($this->_productCollection)) {
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addTaxPercents()
->addStoreFilter();
$this->_productCollection->getSelect()->joinLeft(
array('_inventory_table'=>'cataloginventory_stock_item'),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock', 'manage_stock')
);
$this->_productCollection->addExpressionAttributeToSelect('on_top',
'(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)',
array());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
}
return $this->_productCollection;
}
}
を
/app/code/local/YourCompany/YourModuleName/Model/CatalogSearch/Layer。PHPの
class YourCompany_YourModuleName_Model_CatalogSearch_Layer extends Mage_CatalogSearch_Model_Layer
{
public function prepareProductCollection($collection)
{
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
$collection->getSelect()->joinLeft(
array('_inventory_table'=>'cataloginventory_stock_item'),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock', 'manage_stock')
);
$collection->addExpressionAttributeToSelect('on_top',
'(CASE WHEN (((_inventory_table.use_config_manage_stock = 1)
AND (_inventory_table.is_in_stock = 1)) OR ((_inventory_table.use_config_manage_stock = 0)
AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1)))
THEN 1 ELSE 0 END)',
array());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
}
/app/code/local/YourCompany/YourModuleName/Model/CatalogSearch/Mysql4/Advanced/Collection.php「
class YourCompany_YourModuleName_Model_CatalogSearch_Mysql4_Advanced_Collection extends
Mage_CatalogSearch_Model_Mysql4_Advanced_Collection
{
public function setOrder($attribute, $dir='desc')
{
$this->addAttributeToSort('on_top', 'desc');
parent::setOrder($attribute, $dir);
return $this;
}
}
「/アプリ/コード/ローカル/ YourCompanyそれだ/YourModuleName/Model/CatalogSearch/Mysql4/Fulltext/Collection.php」
class YourCompany_YourModuleName_Model_CatalogSearch_Mysql4_Fulltext_Collection
extends Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection
{
public function setOrder($attribute, $dir = 'desc')
{
if ($attribute == 'relevance') {
$this->getSelect()->order("on_top DESC")->order("relevance {$dir}");
}
else {
parent::setOrder('on_top', 'DESC');
parent::setOrder($attribute, $dir);
}
return $this;
}
}
。検索されたデータを入手して在庫切れの商品を検出し、商品の追加注文を追加する際に、 'cataloginventory_stock_item'テーブルに接続するだけでどのように見ることができますか。
何も特別なことはありませんが、私は目標を達成するためにどこで問題を抱えていましたか?
p.s.誰かがこれを行うためのより良い方法を提供できる場合 - あなたは歓迎です。しかし、私はこれを行うための適切なチュートリアルを見つけることができませんでした。
上記のコードは検索結果ページにのみ影響しますか、またはナビゲーションメニューのカテゴリページは、在庫切れの商品がリストの最後に移動しても影響を受けますか? – SarthakGupta
このソリューションは、以下の拡張モジュールに実装されています。https://github.com/r-martins/Magento-OutOfStockLast * Magento 1.9では、検索が中断されます。 @レクサ:あなたはそれのための修正を持っていますか? –