1

I'm very new to Magento. I installed version 2.4.6.

And I'm trying to make a shipping method to estimate the cost of shipping.

I created three new products' attributes (height, width, and length), plus the weight that comes by default.

And I need to calculate the shipping cost with a formula based on those four values.

But I only get the weight in the method collectRates() using $request->getPackageWeight()

Is there a way to get all the other custom attributes?

Thanks

carlos
  • 37
  • 3

1 Answers1

0

when I interact with shipping methods, I tend to have the follwing

  • create a custom shipping method (there are many answers on stack exchange to do this and probably you already have this in place)
  • collectRates method will call your custom shipping method and that is where it is possible to add custom logic
  • finally, you want to have the height, width and length of your product. This is probably what is most challenging
  1. I advise to add these attributes to your quote items data. When you add the items to the cart, these product data can be assigned to your quote items data
  2. because these data will be in your quote items, you will see them in your custom shipping method
  3. finally, perform the custom method cost calculation with these quote items data and with your custom shipping method

--> of course, you may find it complex to add data to the quote. The reason is for your checkout shipping method to remain fast to process. The alternative (much simpler) is to fetch the product data in your custom shipping method. That will work and will be simpler but you will need to bear in mind a small impact on performance in your site.