1

製品コレクションをフィルタリングして、子の 1 つが在庫切れのバンドル製品を含まないコレクションを返すにはどうすればよいですか。

4

2 に答える 2

1

代替回答

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        $otherProductIds = $collection->getAllIds();

        //get only bundle
        $collection = Mage::getResourceModel('catalog/product_collection')
                                        ->addAttributeToFilter('type_id','bundle');
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        $bundleIds = $collection->getAllIds();


        //checking bundle associate product stock status
        $readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');

        $select = $readAdapter->select()
                    ->from(array('css'=> Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status')),array())
                    ->join(
                        array('bs'=> Mage::getSingleton('core/resource')->getTableName('bundle/selection')),
                        'bs.product_id = css.product_id',
                        array('parent_product_id')
                    )
                    ->where('bs.parent_product_id IN (?)',$bundleIds)
                    ->where('css.stock_status = 0')
                    ->group('bs.parent_product_id');
        $excludeBundleIds = $readAdapter->fetchCol($select);//return outstock associated products parent ids

        $allIds =   array_merge($otherProductIds, array_diff($bundleIds,$excludeBundleIds));

        $collection = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToFilter('entity_id',array( 'in' => $allIds))

                    ->addMinimalPrice()
                    ->addFinalPrice();

        return $collection

これが役立つことを願っています

于 2013-09-30T05:18:04.160 に答える