Alright, so first things first. We need to find where things are happening. I searched the vendor/magento folder for
carts/mine/items and that came up with
module-quote/etc/webapi.xml. Which shows that
getList is what is used for the output.
The interface we found obviously doesn't return anything, but Magento tends to preference them somewhere with a class, so a quick search turned up
module-quote/etc/di.xml which has
<preference for="Magento\Quote\Api\CartItemRepositoryInterface" type="Magento\Quote\Model\Quote\Item\Repository" /> in it.
And now we're talking! This
Reposity class implements the
getList. Though it doesn't actually show us anything useful in regards to the options for bundles. However, that method does show us this:
$item = $this->getCartItemOptionsProcessor()->addProductOptions($item->getProductType(), $item);.
From that it's reasonable to deduct that there's a product type specific options processor. Our type is a bundle, so we take a look in
module-bundle and there it is!
In that class there's a
processOptions method which seems to be the place where we want to work.
So, we create a fresh module of our own and create a Plugin:
And then in our Plugin file (
public function afterprocessOptions($subject, $result)
* @var Magento\Quote\Api\Data\CartItemInterface $result
* @var \Magento\Bundle\Model\CartItemProcessor $subject
$extensionAttributes = $result->getProductOption()->getExtensionAttributes();
// here is where you go through the result of extensionAttributes
// and load up the bundle selectionsCollection
// which you can then use to find the associated
// product and it's sku. You can then add that
// sku to the result.
If I have time later I might implement the actual solution, but this should get you there, I think.