0

I'm having troubles with trying to get city_id extension attribute from a RateRequest object to use it with in_array PHP function, but I'm getting: Cannot use object of type Magento\Quote\Api\Data\AddressExtension as array

The thing is that I've a logger set and doing json_encode($request->getData()) returns the following JSON:

{"all_items":[{}],"dest_country_id":"CL","dest_region_id":913,"dest_region_code":"R02","dest_street":"","dest_city":"OLLAGUE","dest_postcode":"-","package_value":42990,"package_value_with_discount":42990,"package_weight":0.907,"package_qty":1,"extension_attributes":{"city_id":"903"},"package_physical_value":42990,"free_method_weight":0.907,"store_id":"1","website_id":"1","free_shipping":false,"base_currency":{},"package_currency":{},"limit_carrier":null,"base_subtotal_incl_tax":42990,"country_id":"CL","region_id":"809","city":null,"postcode":"83200"}

As you can see, there's city_id value on extension_attributes key, assuming json_encode return a string, I tried to get with $request['extension_attributes']['city_id'] but it's returning the error. How is that possible? I'm doing something wrong?

Thanks in advance!

2 Answers 2

0

You have converted it to json_encode, if you want to get it as $request['extension_attributes']['city_id'] then you need to use json_decode to decode the returned json function first

0

In your first json_encode it change first level json to array but city is again it slef an object "extension_attributes":{"city_id":"903"} either again use json_encode or use like following

$request['extension_attributes']->city_id to get city value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.