2016-10-03 2 views
0

fishpigでブログに関連付けられている商品の数を表示しようとしています。Fishpigブログの関連商品を取得する

私は以下のメソッドを試していますが、null値が返されています。

public function getAssociatedProducts($post) 
    { 
     if ($post instanceof Fishpig_Wordpress_Model_Post) { 
      $productIds = $this->_getAssociatedWpEntityIds($post->getId(), 'product', 'post', 'post_id'); 

      try { 
       foreach($post->getParentCategories() as $category) { 
        $productIds = array_merge($productIds, $this->_getAssociatedWpEntityIds($category->getId(), 'product', 'category', 'category_id')); 
       } 
      } 
      catch (Exception $e) { 
       $this->log($e->getMessage()); 
      } 
      if (count($productIds) > 0) { 
       $collection = Mage::getResourceModel('catalog/product_collection');  
       Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); 
       $collection->addAttributeToFilter('status', 1); 
       $collection->addAttributeToFilter('entity_id', array('in' => $productIds)); 

       return $collection; 
      } 
     } 

     return false; 
    } 

$post->getAssociatedProducts(); 

機能は、本製品の数を返すのだろうか?

答えて

2

リストされている関数はnullを返すことはできません。唯一の戻り値の型は、falseまたはプロダクトの集合です。

コードベースを検索しましたが、そのメソッドは存在するクラスの一部ではないため、どこから取得したのかわかりません。古いバージョンのものかもしれませんか?

// Get the associations helper 
$associationsHelper = Mage::helper('wordpress/associations'); 

// Load a product collection based on $post 
$products = $associationsHelper->getAssociatedProductsByPost($post); 

// Get the number of products 
$productCount = count($products); 
+0

おかげで、それが働いた@Ben:

は延長の最新バージョンを使用してポストのために関連した製品を入手するには、次の使用します! :) –

関連する問題