2011-12-06 4 views
0

MagentoとPHPを初めて使用していて、オブジェクトから値を取得しようとしています。Magento - Mage_Catalog_Model_Resource_Product_Collectionオブジェクトの値にアクセスする

$_productCollection=$this->getLoadedProductCollection(); 

私は

Mage_Catalog_Model_Resource_Product_Collection Object 
(
    [_flatEnabled:protected] => Array 
     (
      [1] => 
     ) 

    [_productWebsiteTable:protected] => sn_catalog_product_website 
    [_productCategoryTable:protected] => sn_catalog_category_product 
    [_addUrlRewrite:protected] => 1 
    [_urlRewriteCategory:protected] => 3 
    [_addMinimalPrice:protected] => 
    [_addFinalPrice:protected] => 
    [_allIdsCache:protected] => 
    [_addTaxPercents:protected] => 1 
    [_productLimitationFilters:protected] => Array 
     (
      [category_id] => 3 
      [category_is_anchor] => 1 
      [store_id] => 1 
      [use_price_index] => 1 
      [customer_group_id] => 0 
      [website_id] => 1 
      [visibility] => Array 
       (
        [0] => 2 
        [1] => 4 
       ) 

     ) 
) 

以下のようなものをprint_r()を取得していないと私は、この中に、カテゴリIDを取得する必要があります。 は、誰かがあなたが取得しようとすると、この最初の

$_productCollection=$this->getLoadedProductCollection(); 

foreach($_productCollection as $product){ 

//display data that object contains 
//print_r($product->getData()); 

//display category id's that product is associated with 
//print_r($product->getCategoryIds()); 

} 
+0

FYI:Magentoでは、コレクションはデータモデルのコレクションを含む可能性のある反復可能なリソースオブジェクトです。閉じ込められたアイテムのデータについて知るために、 'foreach($ collection as $ item)'と内部で '$ item-> debug()'を使うことができます。 – benmarks

答えて

1

を助けてください商品リストがカテゴリの一部であるため、商品リストからのカテゴリは遠くにあります。私はあなたがカテゴリページでこれをやっていると仮定します(そうでなければ検索ページのような複数のカテゴリを扱っています)。

$category = Mage::registry('current_category'); 
$categoryId = $category->getId(); 

// to find out what other info is stored, temporarily use this 
print_r($category->debug()); 
2

を反復処理する必要があり外のため、データを取得するために、複数のコレクションアイテム(オブジェクト)を含む大規模でコレクションを扱っている私に

関連する問題