Also I didn't exactly understand what your shipping calculation is, I would suggest the following solution - if you need the calculated value for the weight everywhere in the store:
Create a plugin after the public method Magento\Catalog\Model\Product::getWeight()
and overwrite the return value (i.e. the original product weight value) with your calculation. In this way you have to add a single 1-2 lines method and the di.xml
configuration and will get your custom weight everywhere you call getWeight()
of the product.
If you need the original value of the weight in some places of your store and the calculated value only in the shipping calculation, please provide some more information about that code. There are many different possibilities where you can plugin and add your calculated value to the product object.
For setting the custom weight based on selected custom options you may plug in before \Magento\Quote\Model\Quote\Item::setWeight
. The quote item model has the selected custom options and the products original weight, so you might calculate your custom weight there.