Correct Magento 2 price calculation

Job ID: 38717227

Budget: €8 – €30 EUR

I have a code that calculates shipping costs for products. You can specify the shipping price for each product separately under the product, and that works too.

There is also the function that the shipping costs should be calculated per product, i.e. multiplied if there are several products. However, this only works for “Simple Products”.

The problem occurs with the "simple products" that are part of a "configurable product". If I enter the value directly in the configurable product, the shipping costs are calculated several times for the variants if there are several items in the shopping cart. However, if I specify the value in the variant itself, the price for shipping costs is only calculated once, even though there are several products in the shopping cart.

Who can correct the code so that the shipping costs are also multiplied when I specify the value in the variant?

The code is in the appendix.
Related categories: Magento eCommerce