Magento - Get Custom Option Value details from Option Value ID

前端 未结 4 1725
余生分开走
余生分开走 2021-02-02 15:31

I have some intriguing questions related to Custom Options of Product:-

  1. Is there any difference between Options & Custom Options? This is because I have foun

4条回答
  •  灰色年华
    2021-02-02 16:18

    First load the products from the collection then loop as follows :

    $product = 100; // product id, you should get first
    
    foreach($product->getOptions() as $options)
    {
        $options->getType(); // get option type
    
        $optionValues = $options->getValues();
    
        foreach($optionValues as $optVal)
        {
           print_r($optVal->getData());
           // or $optVal->getData('option_id')
        }
    }
    

    * Modified *

    $prdSku = 125; // sample sku  
    $product = Mage::getModel('catalog/product');  
    $prdId = $product->getIdBySku($prdSku);  
    $product->load($prdId);  
    
    if ($product->getId()) {  
      if ($product->hasCustomOptions()) {  
        foreach ($product->getOptions() as $opt) {  
          $optionType = $opt->getType();  
    
          if ($optionType == 'drop_down') {  
            $values = $opt->getValues();  
    
            foreach ($values as $k => $v) {  
              Mage::log("Array Key = $k;");  
              Mage::log("Array Value: $v");  
            }  
          }  
        }  
     }  
    

提交回复
热议问题