I am building a module that needs to display a second custom price value at all times. I have solved most of what this entails but got stuck with the quite item.

So far i added a column in the quote item table called something like "my_special_price".

I also added the extension attributes to the TotalsItemInterface:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Quote\Api\Data\TotalsItemInterface">
        <attribute code="my_special_price" type="float"></attribute>

I then proceded to set the value using a plugin:


    $result->setData('my_special_price', $item->getData('my_special_price'));

    return $result;

I do this with a around on modelToDataObject which is in the class Magento\Quote\Model\Cart\Totals\ItemConverter.

I also created a class that implements "TotalsItemExtensionInterface" where setMySpecialPrice etc is implemented because of the interface.

Then, when I instantiate \Magento\Checkout\Api\Data\PaymentDetailsInterface and set all the details for that interface(totals, etc) it shows up under:

items[0][_data][extension_attributes(My TotalsItemExtension class)[_data][my_special_price] = 123

I then proceed to return that PaymentDetailsInterface through the API. But the value is not included in the response.

I am obviously doing something wrong here, but what? Some input would be greatly appreciated.

| improve this question | | | | |

Your Answer

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

Browse other questions tagged or ask your own question.