2016-07-20 3 views
5

제품에 대한 두 가지 사용자 지정 옵션이 있습니다. 색상 및 크기와 둘 다 드롭 다운입니다. 제품 세부 정보 페이지에서 해당 제품의 사용 가능한 모든 색상을 표시해야합니다.사용자 지정 옵션 얻기 magento 2의 값 2

다음 코드를 시도했지만 제대로 작동합니다. 그러나 Color와 Size의 모든 값을 반환합니다. 하지만 색상 값 만 있으면됩니다. 즉, 사용자 정의 옵션을 색상으로 선택하고 싶습니다.

$_product = $block->getProduct(); 

foreach($_product->getOptions() as $o){ 
    foreach($o->getValues() as $value){ 
    print_r($value->getData()); 
    } 
} 

답변

1

그래도 필요할지 모르겠지만 해결책을 찾았습니다.

foreach($product->getProductOptionsCollection() as $o){ 
    foreach($o->getValues() as $ov){ 
     // do whatever you want to it; 
     var_dump($ov->getData()); 
    } 
} 

덤프 (이 가져온 제품입니다) 모든 NULL을하지 않고, 이런 식으로 뭔가를 반환합니다

array(13) { 
    ["option_type_id"]=> 
    string(5) "23122" 
    ["option_id"]=> 
    string(4) "6045" 
    ["sku"]=> 
    string(1) "2" 
    ["sort_order"]=> 
    string(1) "2" 
    ["default_title"]=> 
    string(33) "Test Option" 
    ["store_title"]=> 
    NULL 
    ["title"]=> 
    string(33) "Test Option" 
    ["default_price"]=> 
    NULL 
    ["default_price_type"]=> 
    NULL 
    ["store_price"]=> 
    NULL 
    ["store_price_type"]=> 
    NULL 
    ["price"]=> 
    NULL 
    ["price_type"]=> 
    NULL 
} 
관련 문제