File tree Expand file tree Collapse file tree 4 files changed +28
-9
lines changed
Expand file tree Collapse file tree 4 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -153,4 +153,24 @@ protected function getPrice(Product $product): string
153153 $ price = $ priceInfo ->getValue ();
154154 return $ this ->formatPrice ($ price );
155155 }
156+
157+ /**
158+ * @param Product $product
159+ * @param string $attributeCode
160+ * @return string
161+ */
162+ protected function getProductAttributeValue (Product $ product , ?string $ attributeCode ): string
163+ {
164+ if ($ attributeCode ) {
165+ $ result = $ product ->getData ($ attributeCode );
166+ if (is_numeric ($ result ) && 'sku ' != $ attributeCode ) {
167+ $ result = $ product ->getResource ()->getAttribute ($ attributeCode )->getFrontend ()->getValue ($ product );
168+ }
169+ if ($ result ) {
170+ return (string )$ result ;
171+ }
172+ }
173+
174+ return '' ;
175+ }
156176}
Original file line number Diff line number Diff line change @@ -23,11 +23,10 @@ public function get(\Magento\Quote\Model\Quote\Item $quoteItem): array
2323 return array_merge (array_filter ([
2424 'item_id ' => ($ this ->config ->getProductAttribute () == 'sku ' )
2525 ? $ quoteItem ->getSku ()
26- : $ product -> getData ( $ this ->config ->getProductAttribute ()),
26+ : $ this -> getProductAttributeValue ( $ product , $ this ->config ->getProductAttribute ()),
2727 'item_name ' => $ quoteItem ->getName (),
2828 'discount ' => $ this ->formatPrice ((float )$ quoteItem ->getDiscountAmount ()),
29- 'item_brand ' => $ this ->config ->getBrandAttribute () ?
30- $ product ->getData ($ this ->config ->getBrandAttribute ()) : '' ,
29+ 'item_brand ' => $ this ->getProductAttributeValue ($ product , $ this ->config ->getBrandAttribute ()),
3130 'price ' => $ this ->formatPrice ((float )$ quoteItem ->getPrice ()),
3231 'quantity ' => $ quoteItem ->getQty () * 1
3332 ]), $ categoryNames );
Original file line number Diff line number Diff line change @@ -22,11 +22,12 @@ public function get(OrderItemInterface $orderItem): array
2222 $ product = $ orderItem ->getProduct ();
2323 $ categoryNames = $ this ->getCategoryNames ($ product );
2424 return array_merge (array_filter ([
25- 'item_id ' => $ product ->getData ($ this ->config ->getProductAttribute ()),
25+ 'item_id ' => ($ this ->config ->getProductAttribute () == 'sku ' )
26+ ? $ orderItem ->getSku ()
27+ : $ this ->getProductAttributeValue ($ product , $ this ->config ->getProductAttribute ()),
2628 'item_name ' => $ orderItem ->getName (),
2729 'discount ' => $ this ->formatPrice ((float )$ orderItem ->getDiscountAmount ()),
28- 'item_brand ' => $ this ->config ->getBrandAttribute () ?
29- $ product ->getData ($ this ->config ->getBrandAttribute ()) : '' ,
30+ 'item_brand ' => $ this ->getProductAttributeValue ($ product , $ this ->config ->getBrandAttribute ()),
3031 'price ' => $ this ->formatPrice ((float )$ orderItem ->getPrice ()),
3132 'quantity ' => $ orderItem ->getQtyOrdered () * 1
3233 ]), $ categoryNames );
Original file line number Diff line number Diff line change @@ -21,10 +21,9 @@ public function get(Product $product): array
2121 {
2222 $ categoryNames = $ this ->getCategoryNames ($ product );
2323 return array_merge (array_filter ([
24- 'item_id ' => $ product -> getData ( $ this ->config ->getProductAttribute ()),
24+ 'item_id ' => $ this -> getProductAttributeValue ( $ product , $ this ->config ->getProductAttribute ()),
2525 'item_name ' => $ product ->getName (),
26- 'item_brand ' => $ this ->config ->getBrandAttribute () ?
27- $ product ->getData ($ this ->config ->getBrandAttribute ()) : '' ,
26+ 'item_brand ' => $ this ->getProductAttributeValue ($ product , $ this ->config ->getBrandAttribute ()),
2827 'price ' => $ this ->getPrice ($ product )
2928 ]), $ categoryNames );
3029 }
You can’t perform that action at this time.
0 commit comments