所以我們來看Mage_Catalog_Model_Product_Type_Grouped
類的getAssociatedProducts()
方法。下面是它的有趣的部分:
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類,那麼我將擴展這個答案。
我查了一些其他答案,像我之前提到的在我的問題,但似乎沒有工作。我會試試看!謝謝@Ventus – vbak
一個簡單的問題。如果我重寫Magento類,並改變,如果語句殘疾人產品也會出現在前端?我的意思是作爲分組產品的一部分?或者這與前端無關? – vbak
它與前端有關。這是返回相關產品的一般方法,因此希望禁用的產品在分組產品頁面上可見。 – Ventus