@@ -154,15 +154,23 @@ def unserialize_compute(self, skel: "SkeletonInstance", name: str) -> bool:
154154 if skel ["is_frozen" ]: # locked, unserialize the latest stored value from entity
155155 return False
156156
157- if skel ["shipping_status" ] == ShippingStatus .CHEAPEST : # compute cheapest
157+ match skel ["shipping_status" ]:
158+ case ShippingStatus .CHEAPEST :
159+ func = min
160+ case ShippingStatus .MOST_EXPENSIVE :
161+ func = max
162+ case _:
163+ func = None
164+
165+ if func is not None : # compute cheapest & most expensive
158166 self ._prevent_compute = True
159167 try :
160168 applicable_shippings = SHOP_INSTANCE .get ().shipping .get_shipping_skels_for_cart (
161169 cart_skel = skel , use_cache = True ,
162170 )
163171 if applicable_shippings :
164- cheapest_shipping = min (applicable_shippings ,
165- key = lambda shipping : shipping ["dest" ]["shipping_cost" ] or 0 )
172+ cheapest_shipping = func (applicable_shippings ,
173+ key = lambda shipping : shipping ["dest" ]["shipping_cost" ] or 0 )
166174 skel .setBoneValue ("shipping" , cheapest_shipping ["dest" ]["key" ])
167175 finally :
168176 self ._prevent_compute = False
@@ -190,7 +198,7 @@ def _is_valid_user_shipping(self, skel: SkeletonInstance) -> bool:
190198 else :
191199 logger .warning (f"Invalid shipping. { shipping_key = !r} not found in applicable_shippings" )
192200 skel .setBoneValue ("shipping" , None )
193- skel .setBoneValue ("shipping_status" , ShippingStatus . CHEAPEST )
201+ skel .setBoneValue ("shipping_status" , skel . shipping_status . getDefaultValue () )
194202 return False
195203 finally :
196204 self ._prevent_compute = False
0 commit comments