@@ -77,16 +77,29 @@ private function getStringCustomAttributes(array $attributes): string
7777 {
7878 $ result = [];
7979 foreach ($ attributes as $ name => $ value ) {
80- $ result [] = $ name . '=" ' . $ value . '" ' ;
80+ if ($ name != 'class ' ) {
81+ $ result [] = $ name . '=" ' . $ value . '" ' ;
82+ }
8183 }
8284 return !empty ($ result ) ? implode (' ' , $ result ) : '' ;
8385 }
8486
87+ /**
88+ * Retrieve image class for HTML element
89+ *
90+ * @param array $attributes
91+ * @return string
92+ */
93+ private function getClass (array $ attributes ): string
94+ {
95+ return $ attributes ['class ' ] ?? 'product-image-photo ' ;
96+ }
97+
8598 /**
8699 * Calculate image ratio
87100 *
88- * @param $width
89- * @param $height
101+ * @param int $width
102+ * @param int $height
90103 * @return float
91104 */
92105 private function getRatio (int $ width , int $ height ): float
@@ -98,8 +111,9 @@ private function getRatio(int $width, int $height): float
98111 }
99112
100113 /**
101- * @param Product $product
114+ * Get image label
102115 *
116+ * @param Product $product
103117 * @param string $imageType
104118 * @return string
105119 */
@@ -114,6 +128,7 @@ private function getLabel(Product $product, string $imageType): string
114128
115129 /**
116130 * Create image block from product
131+ *
117132 * @param Product $product
118133 * @param string $imageId
119134 * @param array|null $attributes
@@ -154,6 +169,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
154169 'label ' => $ this ->getLabel ($ product , $ imageMiscParams ['image_type ' ]),
155170 'ratio ' => $ this ->getRatio ($ imageMiscParams ['image_width ' ], $ imageMiscParams ['image_height ' ]),
156171 'custom_attributes ' => $ this ->getStringCustomAttributes ($ attributes ),
172+ 'class ' => $ this ->getClass ($ attributes ),
157173 'product_id ' => $ product ->getId ()
158174 ],
159175 ];
0 commit comments