如何从分组产品中查找关联产品是否被禁用?

时间:2013-10-31 15:14:17

标签: magento magento-1.7

我正在尝试从分组产品中获取相关产品。我可以这样做,但不能用于禁用它们的产品。我尝试了一个解决方案,提到设置:Use Flat Catalog Product为“否”,但我仍然不能。还有其他想法吗?我尝试加载一个集合并使用像IS_ENABLED或DISABLED这样的过滤器,并加载像

这样的模型
$product = Mage::getModel('catalog/product')->load($id);
 $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

还有其他想法吗?

1 个答案:

答案 0 :(得分:2)

让我们看一下getAssociatedProducts()类的Mage_Catalog_Model_Product_Type_Grouped方法。这是有趣的部分:


if (!Mage::app()->getStore()->isAdmin()) {
    $this->setSaleableStatus($product);
}

$collection = $this->getAssociatedProductCollection($product)
    ->addAttributeToSelect('*')
    ->addFilterByRequiredOptions()
    ->setPositionOrder()
    ->addStoreFilter($this->getStoreFilter($product))
    ->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));

正如您所见,Magento为收集过滤器添加了状态。方法getStatusFilters()返回要应用于过滤器的产品状态。如果您查看此方法的主体,您会看到它基本上返回$product->getData($this->_keyStatusFitlers)

此方法需要返回2个值(2个状态)。但事实并非如此。在收集设置之前负责if声明:


if (!Mage::app()->getStore()->isAdmin()) {
    $this->setSaleableStatus($product);
}

此部件仅在产品状态过滤器上设置ENABLED状态。

如果您想从分组产品中获取已停用的产品,则需要重写Mage_Catalog_Model_Product_Type_Grouped类并删除if语句和/或设置正确的过滤器。

如果您不知道如何重写Magento课程,请告诉我,然后我会扩展此答案。

相关问题