Returning the name of a rate when .first is used in Shipping Scripts

Returning the name of a rate when .first is used in Shipping Scripts

Ez4
Shopify Partner
1 0 0

Hi all

 

I'm hoping someone can help with this one! When using .first with the below shipping script to attempt to isolate the cheapest expedited rate, the shipping rate name is not returned, but rather "#<ShippingRate:0x7XXXXXXXXX0>" so I cannot isolate which expedited rate is the cheapest (or at least not to my knowledge).

 

ELIGIBLE_RATE =
Input.shipping_rates.each do |shipping_rate|
   if shipping_rate.name.include?("Expedited")
  end
end

ELIGIBLE_RATE = ELIGIBLE_RATE.sort_by!(&:price)

LOWESTRATE = ELIGIBLE_RATE.first

Does anyone have any tips or examples for this or maybe has a better suggestion on isolating the cheapest expedited rate? The rates are live carrier rates so they change each time. Using something fixed is unfortunately not an option.

Replies 0 (0)