Drupal 9 image field migration

It's really nice module which makes customers flow better on website with no need to reload the page on every action. https://www.drupal.org/project/commerce_cart_flyout 
One thing I dont like is a lot of not needed information was present in responses from cart or product. In my case there were internal fields of Product Variations entity which are not displayed for customers.
There is no default settings to handle that case so optimization should be done. You need custom Normalizations for cart and variation cases.

Variations normalization. Add to services.yml in your module
    class: Drupal\my_commerce\Normalizer\VariationCartNormalizer
      - { name: normalizer, priority: 2 }

then add a file to my_commerce/src/Normalizer/VariationCartNormalizer.php.
The main idea is to have an array $whitelistFields for fields that need to be in response.



For Order items I use

    class: Drupal\my_commerce\Normalizer\OrderItemCartNormalizer
      - { name: normalizer, priority: 2 }
and fields variable
  private $whitelistFields = [

For order itself:

    class: Drupal\my_commerce\Normalizer\OrderCartNormalizer
      - { name: normalizer, priority: 2 }

It's a bit different variable here, since this array describes blocked fields.

  private $blockedFields = [

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.