2013-09-04 2 views
1

제품 속성 세트 값을 찾으려면 어떻게합니까?magento로 설정된 제품 속성 값을 나열하십시오.

예를 들어, 성별, 셔츠 크기 및 색상 속성이있는 셔츠 - T라는 속성 세트가있는 제품이 있습니다. $ _product 객체로 시작하여 속성 값을 어떻게 찾을 수 있습니까? 망, 녹색, 큰?

나는 다음과 같은 방법으로 속성 설정 값을 얻기에 수 있어요 :

$product = Mage::getModel('catalog/product')->load($productId); 
     $prodAttributeSet = Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId())->getAttributeSetName(); 

내가 설정 특정 속성에 사용할 수있는 모든 속성 설정 값과 코드를 얻으려면 -

답변

0
$_product = Mage::getModel('catalog/product')->load($productId); 
(즉, 셔츠 T를)

이제이 제품의 제조업체 값에 액세스하고 다음 코드를 고려한다고 가정합니다.

$manufacturerValue = $_product->getAttributeText('manufacturer'); 
+0

는 내가 보여주고 싶은 : 색상, 크기 ... 가능한 모든 속성 설정 값을 제품 – user2629419

+0

에 대한 다음 색상 제조 업체 –

+0

$ 색상의 insted 쓰기 = $ _ 제품 -> getAttributeText ('색상'); $ color = $ _ product-> getAttributeText ('size'); –

0

여기 크기 및 색상에 대한 의견에서 언급 한대로 사용할 샘플 코드를 하나 줄 수 있습니다.

속성이 select or multiselect 인 경우 옵션 ID 값을 옵션 값에 매핑해야합니다. 사람이 읽을 수있는 라벨 대신 정수 목록 (예 : 색상 또는 제조업체 속성)을 얻는 경우입니다. 이 작업을 수행 할 위치에 따라

// specify the select or multiselect attribute code 
$attributeCode = 'color'; 

// build and filter the product collection 
$products = Mage::getResourceModel('catalog/product_collection') 
     ->addAttributeToFilter($attributeCode, array('notnull' => true)) 
     ->addAttributeToFilter($attributeCode, array('neq' => '')) 
     ->addAttributeToSelect($attributeCode); 

$usedAttributeValues = array_unique($products->getColumnValues($attributeCode)); 

// ---- this is the different part compared to the previous example ---- 

// fetch the attribute model 
$attributeModel = Mage::getSingleton('eav/config') 
     ->getAttribute('catalog_product', $attributeCode); 

// map the option id's to option labels 
$usedAttributeValues = $attributeModel->getSource()->getOptionText(
    implode(',', $usedAttributeValues) 
); 

직접 DB 쿼리 예를 들어, 여기에 제품 컬렉션을 사용하지 않고 값을 가져 오는 예입니다. 약간 더 효율적입니다. DB 관련 코드가 속하는 자원 모델로만 자원 모델에서 다음 코드를 사용하십시오. Magento의 EAV 테이블을 사용하는 방법을 보여주는 교육용 예제입니다.

// specify the attribute code 
$attributeCode = 'color'; 

// get attribute model by attribute code, e.g. 'color' 
$attributeModel = Mage::getSingleton('eav/config') 
     ->getAttribute('catalog_product', $attributeCode); 

// build select to fetch used attribute value id's 
$select = Mage::getSingleton('core/resource') 
     ->getConnection('default_read')->select() 
     ->from($attributeModel->getBackend()->getTable(), 'value') 
     ->where('attribute_id=?', $attributeModel->getId()) 
     ->distinct(); 

// read used values from the db 
$usedAttributeValues = Mage::getSingleton('core/resource') 
     ->getConnection('default_read') 
     ->fetchCol($select); 

// map used id's to the value labels using the source model 
if ($attributeModel->usesSource()) 
{ 
    $usedAttributeValues = $attributeModel->getSource()->getOptionText(
     implode(',', $usedAttributeValues) 
    ); 
} 
0

속성 세트의 모든 속성을 원하면 다음을 수행 할 수 있습니다.

$product = Mage::getModel('catalog/product')->load($productId); 
$attributes = $eavConfig->getEntityAttributeCodes(Mage_Catalog_Model_Product::ENTITY, $product); 
print_r(attributes); 
관련 문제