إخفاء المنتج القابل للتكوين مع توفر المنتج الفرعي خارج المخزون من صفحة قائمة المنتجات

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

سؤال

أرغب في إخفاء جميع المنتجات القابلة للتكوين من صفحة قائمة المنتجات التي نفد مخزونها من منتج واحد بسيط مرتبط بها.أولاً وقبل كل شيء، أحاول تصفية جميع المنتجات القابلة للتكوين ولكنني أتلقى الخطأ أدناه

SQLSTATE [42S22]:لم يتم العثور على العمود:1054 عمود غير معروف '

أنا استخدم 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