owebia / magento2-module-advanced-shipping

Other
91 stars 29 forks source link

How to get method name? #87

Closed marcinex closed 3 years ago

marcinex commented 3 years ago

Hi, I have a problem - I would like to hide some payment methods depends shipping method. I was thinking that method name created at addMethod('przedplacona01' <-- is what I'm looking but it doesn't work. I have listed all methods available in my store and Your modules gives an empty array ... why is that? Am i missed something? How can I get choosed shipping method name to use it in second step of default Onepage checkout?

owebia commented 3 years ago

Hi,

This value is stored in an instance of \Magento\Quote\Model\Quote\Address\RateResult\Method, in an attribute called method: see https://github.com/owebia/magento2-module-advanced-shipping/blob/00e856ffc9e567a2264966b08e9ac61298770f72/Model/Carrier.php#L173

I have listed all methods available in my store and Your modules gives an empty array ... why is that?

To retrieve them in a non checkout context, or when \Magento\Quote\Model\Quote\Address\RateRequest $request is not properly populated, you must not use if/else statements in Advanced Shipping's configuration but use the property enabled of addMethod instead.

How can I get choosed shipping method name to use it in second step of default Onepage checkout?

You can get it from the quote: $quote->getShippingAddress()->getShippingMethod(); This will be a concatenated value of the carrier code and the method code.

Best Regards, A.L.

marcinex commented 3 years ago

Works great. <3 for Your help!