1

How to get configurable child cost price get in magento 2.

Thanks.

1
  • Do you want child products data from configurable product?
    – ZealousWeb
    Apr 23, 2021 at 4:48

1 Answer 1

2

You get cost price of child product like below.

$configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
 
$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
$price = 0;
foreach ($_children as $child){
    $price = $price + $child->getPrice();
}
echo "Total Price:". $price;

If you want price range of configurable product then you can do it by below

<?php
$currentProduct = $this->getProduct();
$regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price');
?>
<div class='price-box'>
    <span class="price">
        <?php
            echo $regularPrice->getMinRegularAmount().'-'.$regularPrice->getMaxRegularAmount();
        ?>
    </span>
</div>

Please check and let me know if you have any query.

8
  • i want count all cost price. Apr 23, 2021 at 5:05
  • Ok, i will update my asnwer for you
    – ZealousWeb
    Apr 23, 2021 at 5:07
  • I have updated answer. Please check
    – ZealousWeb
    Apr 23, 2021 at 5:10
  • i am not want to child price but i want to cost price. Apr 23, 2021 at 5:21
  • So you can get cost price , same as price
    – ZealousWeb
    Apr 23, 2021 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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