Optimize createWithSampleValues method in ProductVariationStorage

Created on 19 June 2024, 9 days ago

What

I have a project Drupal Commerce and need to prepare some automated tests.
Before automated tests, the project is almost clear of content (no products, product variations, orders, etc)

Steps to reproduce

The issue can be reproduced with the Layout Builder module (in Drupal Core), and have the similar behavior as in the Drupal Core issue - https://www.drupal.org/project/drupal/issues/3069001 🐛 Layout builder's use of sample data can cause exceptions during rendering of default entity view displays Needs work .

In short:

  1. The Layout Builder module, to generate routes needs to have sample values of the Product Variation entity.
  2. Calling ProductVariationStorage::createWithSampleValues() method which extended from ContentEntityStorageBase Drupal Core class.
  3. The ProductVariationStorage::createWIthSampleValues() method creates a variation, but according to the product_id field, it creates a product
  4. Then the system starts to create a Product entity with sample values, and creates quite a lot of other data.

Proposed solution

Include the ProductVariationStorage::createWithSampleValues() method and prevent creating a product with data, and attach an empty product.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Product

Created by

🇺🇦Ukraine tibezh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024