I have been searching and cannot find the answer to this!
I have the following data being sent to my controller:
{
"93":"52",
"142":"173",
"product":"1799"
}
The product
key is the configurable product ID. The 2 numeric keys are attribute_id: atrribute_value_id
.
How do I go about loading the simple product based on these details?
Using version 2.1.5
Update
This is actually the same (minus a couple of irrelevant details) as what Magento uses to add a configurable product to the cart from the category listing page. So what I am asking is definitely possible!
I have tried tracing the steps that Magento goes through from /checkout/cart/add
but I am not seeing HOW Magento does this.
Another Update as there is no activity on this question
I have got the following code working to get the attribute codes and child IDs from the configurable parent. Can anyone come up with a way to filter these children by the attributes?
$attr = $this->eavAttribute->get('catalog_product', 93);
$attributeCodes[] = $attr->getAttributeCode();
$attr = $this->eavAttribute->get('catalog_product', 142);
$attributeCodes[] = $attr->getAttributeCode();
$product = $this->productRepository->getById($productId, false, $storeId
if ($product->getTypeId() == 'configurable') {
$ids = $this->configurable->getChildrenIds($productId);
}
PS
I hate to complain but my questions on here hardly ever get any attention at all and this is no different. I am starting to lose hope in magento.stackexchange as it seems like nobody comes on here to answer questions. I know there are Magento 2 gurus out there, but where are you?