From f8a4e0cb88487786d8a2e78a50fa7ede80b9c6f9 Mon Sep 17 00:00:00 2001
From: tbradbury <tbradbury@acromediainc.com>
Date: Fri, 10 Feb 2017 17:05:25 -0800
Subject: [PATCH 1/2] Allow printing labels that have taxonomy term reference
 attribute fields.

---
 modules/label/commerce_pos_label.module | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/modules/label/commerce_pos_label.module b/modules/label/commerce_pos_label.module
index f8fee5e..0c624fc 100644
--- a/modules/label/commerce_pos_label.module
+++ b/modules/label/commerce_pos_label.module
@@ -212,12 +212,21 @@ function commerce_pos_label_attributes_string($product) {
     $wrapper = entity_metadata_wrapper('commerce_product', $product);
 
     foreach ($attribute_fields as $field_name) {
+      $field = field_info_field($field_name);
       $field_info = field_info_instance('commerce_product', $field_name, $product->type);
 
-      if (isset($wrapper->{$field_name}) && $attribute_value = $wrapper->{$field_name}->value()) {
+      $properties = _options_properties('select', FALSE, TRUE, TRUE);
+      $options = _options_get_options($field, $field_info, $properties, 'commerce_product', $product);
+      if (isset($wrapper->{$field_name}) && $attribute_value = $wrapper->{$field_name}->raw()) {
         if (is_array($attribute_value)) {
+          $attribute_value = array_map(function ($item) use ($options) {
+            return $options[$item];
+          }, $attribute_value);
           $attribute_value = implode(', ', $attribute_value);
         }
+        else {
+          $attribute_value = $options[$attribute_value];
+        }
 
         $attributes[] = $field_info['label'] . ': ' . $attribute_value;
       }

From e8440f06b8874b78f4a8162e38029273b8bd98a0 Mon Sep 17 00:00:00 2001
From: tbradbury <tbradbury@acromediainc.com>
Date: Mon, 13 Feb 2017 17:16:35 -0800
Subject: [PATCH 2/2] Add comments to calls to options module functions.

---
 modules/label/commerce_pos_label.module | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/modules/label/commerce_pos_label.module b/modules/label/commerce_pos_label.module
index 0c624fc..2b4fc60 100644
--- a/modules/label/commerce_pos_label.module
+++ b/modules/label/commerce_pos_label.module
@@ -212,12 +212,19 @@ function commerce_pos_label_attributes_string($product) {
     $wrapper = entity_metadata_wrapper('commerce_product', $product);
 
     foreach ($attribute_fields as $field_name) {
-      $field = field_info_field($field_name);
-      $field_info = field_info_instance('commerce_product', $field_name, $product->type);
-
-      $properties = _options_properties('select', FALSE, TRUE, TRUE);
-      $options = _options_get_options($field, $field_info, $properties, 'commerce_product', $product);
       if (isset($wrapper->{$field_name}) && $attribute_value = $wrapper->{$field_name}->raw()) {
+        // Values of fields can be a string, taxonomy term, or other unexpected
+        // data types. We don't necessarily know how to render those as a string
+        // but any field that is a commerce_cart attribute field must implement
+        // hook_options_list, and we can use those options to get a
+        // human-readable string for the field.
+        $field = field_info_field($field_name);
+        $field_info = field_info_instance('commerce_product', $field_name, $product->type);
+        $properties = _options_properties('select', FALSE, TRUE, TRUE);
+        $options = _options_get_options($field, $field_info, $properties, 'commerce_product', $product);
+
+        // Despite multi-value fields not being eligible to be attribute fields,
+        // a user could configure them as one anyway.
         if (is_array($attribute_value)) {
           $attribute_value = array_map(function ($item) use ($options) {
             return $options[$item];
