I am trying to pull configurable products option and price on product detail page on seprate section. on radio button. I've used below code to get detail of options but i can retrive price of options.

$blockObj = $block->getLayout()->createBlock('Magento\ConfigurableProduct\Block\Product\View\Type\Configurable');

$_attributes = $blockObj->decorateArray($blockObj->getAllowAttributes());

 foreach ($_attributes as $_attribute): ?>

    <?php foreach ($_attribute->getData('options') as $option):    ?>
        // option detail here
     <?php endforeach; ?>
 <?php endforeach; ?>

I've also try to get product id of options but i can get in above data. anyone have idea. how to get it? Note: I've used objectmanager for testing now. I'll use class to use once my code will be ready

  • Prices are associated with the child products of a configurable product, not options. You should just get the prices of the child products. Commented May 5, 2017 at 0:17
  • @subroutines But there will be some way to get child product id from option id. right? I didn't find it.
    – Kul
    Commented May 5, 2017 at 8:39

4 Answers 4


This code tested on Magento 2.1.4.

All you need is in getConfigurableOptions call.

67 - is a test product ID. In my installation that is a configurable product id. Change it to your product id.

Copy paste it to testfile.php and run php config.php inside magento root:

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');

$repository = $obj->create('Magento\Catalog\Model\ProductRepository');
$product = $repository->getById('67');

$data = $product->getTypeInstance()->getConfigurableOptions($product);

$options = array();

foreach($data as $attr){
  foreach($attr as $p){
    $options[$p['sku']][$p['attribute_code']] = $p['option_title'];

foreach($options as $sku =>$d){
  $pr = $repository->get($sku);
  foreach($d as $k => $v)
    echo $k.' - '.$v.' ';
  echo ' : '.$pr->getPrice()."\n";

Here is the output: enter image description here

  • Perfect! Thanks man. Just once correction use php testfile.php instead of php config.php
    – Kul
    Commented May 9, 2017 at 7:01
  • alright did I earn the bounty? Commented May 9, 2017 at 13:39
  • Ofcourse. sorry forgot to award bounty.
    – Kul
    Commented May 9, 2017 at 14:04
  • Please Update same code for Magento 2 Commented Mar 30, 2018 at 22:32
  • @KonstantinGerasimov, How to display that info like in the category list page? Commented Jul 16, 2019 at 7:23

Please try below code to get child product object.

 $_children = $_product->getTypeInstance()->getUsedProducts($_product);
    foreach ($_children as $child){
        $logger->info("Here are your child Product Ids ".$child->getID());

Hope this will help you.

  • Thanks. but i want to show price with option. not only child product of configrable product. How can i get relation of option and child product?
    – Kul
    Commented May 4, 2017 at 6:56

What if, not evenn tested but think should work, inject \Magento\Catalog\Model\ProductRepository, load some product with method: getById

    $result = [];
    $options = (array)$product->getOptions();
    foreach ($options as $option) {
        $optionValues = $option->getValues() ? $option->getValues() : [];
        $optionValuesArray = [];
        foreach ($optionValues as $optionValue) {
            $optionValuesArray[] =  [
                'option_id'  => $optionValue->getOptionTypeId(),
                'sku'                 => $optionValue->getSku(),
                'title'           => $optionValue->getTitle(),
                'price'           => $optionValue->getPrice(),
                'price_type'      => $optionValue->getPriceType()

        $resultOption = [
                    'option_id'  => $option->getOptionId(),
                    'title'      => $option->getTitle(), 
                    'type'       => $option->getType(),
                    'price'      => $option->getPrice(),
                    'price_type' => $option->getPriceType(),
                    'require' => $option->getIsRequire(),
                    'values' => $optionValuesArray

        $result[] = $resultOption;

To get the configurable option along with their price all you need to do is,

$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
foreach($product->getOptions() as $o) {
                foreach ($o->getValues() as $value) {

I have used objectManager though it is not the recommended way to do it. Just use this code for reference.You can do this by dependency injection. Hope it helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.