Skip to content

M2.2.4 : Extension attributes of quote models are not properly encoded to the frontend #15959

@kanduvisla

Description

@kanduvisla

When I add extension attributes to a quote, they are not properly encoded to the frontend.

Preconditions

  1. Magento 2.2.4

Steps to reproduce

  1. Create extension attributes for a quote object
  2. Populate it with something
  3. Check window.checkoutConfig.quoteData.extension_attributes on the checkout page.

For example:

<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
    <attribute code="order_reference_customer" type="string">
        <join reference_table="sales_order_reference" join_on_field="entity_id" reference_field="quote_id">
            <field>customer_reference</field>
        </join>
    </attribute>
</extension_attributes>

In plugin / interceptor for Magento\Quote\Api\CartRepositoryInterface:

/**
 * @param CartRepositoryInterface $subject
 * @param CartInterface $quote
 * @return CartInterface
 */
public function afterGet(CartRepositoryInterface $subject, CartInterface $quote)
{
    $quote->getExtensionAttributes()->setOrderReferenceCustomer('foo');
    return $quote;
}

I've tested if the intercepter worked by good old var_dump and die. The extension attribute is populated and it is present in the quote on the checkout page.

Expected result

window.checkoutConfig.quoteData.extension_attributes should be populated with the extension attributes.

Actual result

Instead it is an empty object {}.

My guesses of what might cause this:

  • Magento\Checkout\Model\DefaultConfigProvider::getQuoteData() : Here there is a method called $quote->toArray(), but it does not serialize the extension attributes (these are still objects, and not plain data). or:
  • Magento\Checkout\Block\Onepage::getSerializedCheckoutConfig() : This does a simple json_encode() on the data provided by the DefaultConfigProvider. My guess is that it ignores objects.

Possibly related to #15928

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CheckoutFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasehelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions