3

「在庫あり」または「販売可能」であるすべての構成可能な製品の製品コレクションを構築しようとしています。これらには、2 つの異なるモデルを使用する必要があります。私の作業方法は次のとおりです。

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'));

foreach ($collectionConfigurable as $_configurableproduct) {
    $product = Mage::getModel('catalog/product')->load($_configurableproduct->getId());

    if ($product->isSaleable()) { 
// do something
}
}

ただし、このスクリプトは非常に遅く、構成可能なすべての製品を読み込んで通過するため、実行中のリソースを浪費しているように感じます。

私が達成しようとしているのは、 $collectionConfigurable を取得して、在庫のあるアイテムのみにすることです。

別のリソースは、これを在庫品を入手する方法として挙げています。

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($this->_productCollection);

しかし、それらを組み合わせる方法や適切に使用する方法がわからないので、これを試しました:

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'));
$instockConfigs = Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collectionconfigurable);

これにより、次のエラーが返されます。

  Fatal error: Call to a member function joinField() on a non-object in /srv/magento/app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php on line 197
4

1 に答える 1