0

I’d like to be able to show an attribute from the selected simple on my configurable pages in M2.2.5

Using the example attribute with name of ‘serves’

Each simple has a value in serves e.g, 5 or 10-12

It’s an attribute I use to show how many portions you get from a meat joint so as the confurable uses weight as the drop down, I need to then show average servings or portions.

When someone picks a simple, I want to show that attribute above the SKU and have it dynamically update from simple to simple.

I don’t need to carry it through checkout or anything, it’s only really needed on the product page.

Would appreciate your help everyone.

1 Answer 1

0

You will need to use the getUsedProducts method to get the child products. From there you can get any attribute value for the child product.

$configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

When (on value change, on click, on page load) you need to display this information will dictate if you should just pass it along to the initial page rendering or fetch that info later with some JavaScript.

1
  • Thanks Haim. I’m not a very advanced level of developer so I get the principle but don’t know how to implement your suggestion. I’ll google it and see if I can find an example.
    – wjp_bill
    Commented Oct 24, 2018 at 8:41

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.