@@ -66,7 +66,7 @@ public function mapByProduct(ProductInterface $product): array
6666
6767 $ productFields = $ this ->getProductFields ();
6868 foreach ($ productFields as $ productAttributeCode ) {
69- $ dataLayerKey = $ prefix . $ productAttributeCode ;
69+ $ dataLayerKey = $ prefix. $ productAttributeCode ;
7070 $ attributeValue = $ this ->getAttributeValue ->getProductAttributeValue ($ product , $ productAttributeCode );
7171 if ($ attributeValue === null ) {
7272 continue ;
@@ -77,17 +77,23 @@ public function mapByProduct(ProductInterface $product): array
7777
7878 try {
7979 $ category = $ this ->getProductCategory ($ product );
80- $ productData [$ prefix . 'list_id ' ] = $ category ->getId ();
81- $ productData [$ prefix . 'list_name ' ] = $ category ->getName ();
80+ $ productData [$ prefix. 'list_id ' ] = $ category ->getId ();
81+ $ productData [$ prefix. 'list_name ' ] = $ category ->getName ();
8282 } catch (NoSuchEntityException $ noSuchEntityException ) {
8383 }
8484
85- $ productData ['price ' ] = $ this ->priceFormatter ->format ((float ) $ product ->getPriceInfo ()->getPrice (FinalPrice::PRICE_CODE )->getValue ());
85+ $ price = (float )$ product ->getPriceInfo ()->getPrice (FinalPrice::PRICE_CODE )->getValue ();
86+ $ productData ['price ' ] = $ this ->priceFormatter ->format ($ price );
8687
8788 $ simpleProductOption = $ product ->getCustomOption ('simple_product ' );
88- if ($ simpleProductOption && method_exists ($ simpleProductOption , 'getProduct ' ) && $ simpleProductOption ->getProduct ()) {
89+ if ($ simpleProductOption && method_exists (
90+ $ simpleProductOption ,
91+ 'getProduct '
92+ ) && $ simpleProductOption ->getProduct ()) {
8993 $ simpleProduct = $ simpleProductOption ->getProduct ();
90- $ productData ['price ' ] = $ this ->priceFormatter ->format ((float ) $ simpleProduct ->getPriceInfo ()->getPrice (FinalPrice::PRICE_CODE )->getValue ());
94+ $ productData ['price ' ] = $ this ->priceFormatter ->format (
95+ (float )$ simpleProduct ->getPriceInfo ()->getPrice (FinalPrice::PRICE_CODE )->getValue ()
96+ );
9197 }
9298
9399 $ productData = $ this ->attachCategoriesData ($ product , $ productData );
@@ -102,15 +108,17 @@ public function mapByProduct(ProductInterface $product): array
102108 /**
103109 * @param ProductInterface $product
104110 * @return CategoryInterface
111+ * @throws NoSuchEntityException
105112 */
106- private function getProductCategory ($ product )
113+ private function getProductCategory (ProductInterface $ product ): CategoryInterface
107114 {
108115 /** @var Product $product */
109116 if ($ this ->config ->getProductListValueOnCategory () == ProductListValue::CURRENT_CATEGORY
110- && $ product ->getCategory ()
117+ && $ product ->getCategory () instanceof CategoryInterface
111118 ) {
112119 return $ product ->getCategory ();
113120 }
121+
114122 return $ this ->categoryProvider ->getFirstByProduct ($ product );
115123 }
116124
@@ -142,7 +150,7 @@ private function attachCategoriesData(ProductInterface $product, array $data): a
142150 continue ;
143151 }
144152
145- $ key = 'item_category ' . ($ currentCategoriesCount === 1 ? '' : $ currentCategoriesCount );
153+ $ key = 'item_category ' . ($ currentCategoriesCount === 1 ? '' : $ currentCategoriesCount );
146154 $ data [$ key ] = $ category ->getName ();
147155
148156 $ currentCategoriesCount ++;
0 commit comments