2015-07-20 37 views
0

這是什麼輸出的$selectionCollection給出的,如果沒有選擇產品在這段代碼找到了Magento的捆綁產品列表如何檢查編程是否Magento的getSelectionsCollection沒有任何產品

$bundled_product_custom = new Mage_Catalog_Model_Product(); 
$bundled_product_custom->load($bundleParentProductId); 
$selectionCollection = $bundled_product_custom->getTypeInstance(true)->getSelectionsCollection(
      $bundled_product_custom->getTypeInstance(true)->getOptionsIds($bundled_product_custom), $bundled_product_custom 
     ); 

其實我需要檢查,如果此捆綁產品是否具有選擇產品。

回答

1

首先,您應避免使用new運算符實例化對象。我建議你使用Magento的工廠方法,如下圖所示:

$bundled_product_custom = Mage::getModel('catalog/product'); 

如果第三方擴展覆蓋Mage_Catalog_Model_Product類這樣那麼工廠方法根據覆蓋規則實例化對象的權利。

要回答你的問題,試圖通過這種方式計算的元素集合中:

$selectionCollection->count(); 
// or 
count($selectionCollection); 
+0

感謝。有用。 –

相關問題