I am using Drupal Commerce Kickstart! I want to get 'Only' the country name from the shipping information of a particular order in a view, The shipping information field in my view shows the entire shipping address including the country at last, is there a way that I can extract only the country name from that? or a db query using the order_id?
Implying that you have the Order ID in your view:
- Add a relationship to Commerce Order: Referenced customer profile, for the shipping address (Relate this entity to the customer profile referenced by its commerce_customer_shipping value)
- Add field for Commerce Customer profile: Address - Country
My output after those steps:
Order ID: 4
Order ID: 5
FYI the data is located in field_data_commerce_customer_address table commerce_customer_address_country column.
Finally I did it by sending a DB query to get the address of a customer by an order id.
SELECT field_data_commerce_customer_address.commerce_customer_address_country as country
INNER JOIN field_data_commerce_customer_shipping
ON field_data_commerce_customer_address.entity_id = field_data_commerce_customer_shipping.commerce_customer_shipping_profile_id
WHERE field_data_commerce_customer_shipping.entity_id ='".$order_id."'"