三江源大家幫我出這個問題。
我已經找到了soloution,其簡單,並有一個addItem(),它可以很容易地幫助將新產品添加到_productCollection對象。
我唯一的技巧就是加載一個空的集合
//load an empty collection (filter-less collections will auto-lazy-load everything)
$merged = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id',-1);
,並同時增加產品的空表我們需要舒爾檢查產品標識不重複,Magento的不允許添加複製到產品收集
if(!$merged->getItemById($product->getId()))
{
$merged->addItem($product);
}
產品下面的整個代碼是按我的要求
$this->_productCollection = $layer->getProductCollection();
//load an empty collection (filter-less collections will auto-lazy-load everything)
$merged = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id',-1);
/**** Sorting the backorder product first ****/
foreach($this->_productCollection as $product)
{
if($product->getTypeId()=="simple" && $product->isSaleable())
{
if(!$merged->getItemById($product->getId()))
{
$merged->addItem($product);
}
}
}
/**** Sorting the avilable product second ****/
foreach($this->_productCollection as $product)
{
if($product->getTypeId()=="configurable" && $product->isSaleable())
{
if(!$merged->getItemById($product->getId()))
{
$merged->addItem($product);
}
}
}
/**** Sorting the sold out product last ****/
foreach($this->_productCollection as $product)
{
if(!$product->isSaleable())
{
if(!$merged->getItemById($product->getId()))
{
$merged->addItem($product);
}
}
}
/* Now assigning to the mergerd collection to the product Collection */
$this->_productCollection = $merged;
你有錯誤?如果是,它是什麼? –
不,我沒有得到任何錯誤,我認爲是陣列和對象類型之間的類型不匹配,我很困惑... –
好吧,我會檢查它 –