製品リストページから在庫切れの子供製品の可用性で設定可能な製品を隠す

magento.stackexchange https://magento.stackexchange.com//questions/65694

質問

私は、単一の関連する単純な製品でさえ在庫切れの製品リストページからのすべての設定可能な製品を隠したいと思います。まず最初に設定可能な製品をフィルタリングしようとしていますが、私は以下のエラーを獲得しています

SQLSTATE [42S22]:列見つかりません:1054不明な列 'e.type_id' 'where句'

catalog_block_product_list_collectionイベントを使用しています。

これはconfig.xmlからのイベントセクションコードです。

<events>
            <catalog_block_product_list_collection>
                <observers>
                    <retailon_configurable_list>
                        <type>singleton</type>
                        <class>retailon_configurable/observer</class>
                        <method>addInStockOnlyFilter</method>
                    -</retailon_configurable_list>              
                </observers>
            </catalog_block_product_list_collection>
        </events>
.

これはobserverコードです:

<?php

class Retailon_Configurable_Model_Observer {
    /**
   * Observes the catalog_block_product_list_collection event
   */
  public function addInStockOnlyFilter($observer){
  $productCollection = $observer->getEvent()->getCollection()->addAttributeToFilter('type_id', 'configurable');

    }
}
.

与えられた条件を提供した場合、observerで製品をフィルタリングする方法はありますか?

役に立ちましたか?

解決

私はそれを作業しました。これがオブザーバーコードです:

<?php

class Retailon_Configurable_Model_Observer {

  public function addInStockOnlyFilter($observer){
    $productCollection = $observer->getEvent()->getCollection();

    foreach ($productCollection as $product) {
        if ($product->getTypeId() == "configurable"){
            $product->getTypeInstance(true)->getUsedProducts ( null, $product);
            foreach ($product->getTypeInstance(true)->getUsedProducts ( null, $product) as $simple) {
            //all associated product
                if($simple->getStockItem()->getQty() < 1 ){
                    $proArray[] = $product->getId();
                }

            }
        }
    }

    if(count($proArray)){
        foreach ($proArray as $key) {
            $productCollection->removeItemByKey($key);
        }
    }

    $observer->getEvent()->setCollection($productCollection);
        }

}
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top