@@ -62,24 +62,33 @@ public function resolve(
62
62
63
63
/** @var Product $product */
64
64
$ product = $ value ['model ' ];
65
+ $ imageType = $ value ['image_type ' ];
66
+ $ imagePath = $ product ->getData ($ imageType );
67
+ $ productId = (int )$ product ->getEntityId ();
68
+
69
+ // null if image is not set
70
+ if (null === $ imagePath ) {
71
+ return $ this ->getAttributeValue ($ productId , 'name ' );
72
+ }
73
+
74
+ $ imageLabel = $ this ->getAttributeValue ($ productId , $ imageType . '_label ' );
75
+ if (null === $ imageLabel ) {
76
+ $ imageLabel = $ this ->getAttributeValue ($ productId , 'name ' );
77
+ }
65
78
66
- $ imageLabel = $ this ->getImageLabel ((int )$ product ->getEntityId (), $ value ['image_type ' ]);
67
79
return $ imageLabel ;
68
80
}
69
81
70
82
/**
71
83
* @param int $productId
72
- * @param string $imageType
73
- * @return string
84
+ * @param string $attributeCode
85
+ * @return null| string Null if attribute value is not exists
74
86
*/
75
- private function getImageLabel (int $ productId , string $ imageType ): string
87
+ private function getAttributeValue (int $ productId , string $ attributeCode ): ? string
76
88
{
77
89
$ storeId = $ this ->storeManager ->getStore ()->getId ();
78
90
79
- $ imageLabel = $ this ->productResource ->getAttributeRawValue ($ productId , $ imageType . '_label ' , $ storeId );
80
- if (empty ($ imageLabel )) {
81
- $ imageLabel = $ this ->productResource ->getAttributeRawValue ($ productId , 'name ' , $ storeId );
82
- }
83
- return $ imageLabel ;
91
+ $ value = $ this ->productResource ->getAttributeRawValue ($ productId , $ attributeCode , $ storeId );
92
+ return is_array ($ value ) && empty ($ value ) ? null : $ value ;
84
93
}
85
94
}
0 commit comments