15
15
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
16
16
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
17
17
use Magento \Catalog \Pricing \Price \FinalPrice ;
18
+ use Magento \Catalog \ViewModel \Product \OptionsData ;
18
19
use Magento \CatalogWidget \Model \Rule ;
19
20
use Magento \Framework \App \ActionInterface ;
20
21
use Magento \Framework \App \Http \Context as HttpContext ;
@@ -130,6 +131,11 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
130
131
*/
131
132
private $ categoryRepository ;
132
133
134
+ /**
135
+ * @var OptionsData
136
+ */
137
+ private OptionsData $ optionsData ;
138
+
133
139
/**
134
140
* @param Context $context
135
141
* @param CollectionFactory $productCollectionFactory
@@ -143,6 +149,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
143
149
* @param LayoutFactory|null $layoutFactory
144
150
* @param EncoderInterface|null $urlEncoder
145
151
* @param CategoryRepositoryInterface|null $categoryRepository
152
+ * @param OptionsData|null $optionsData
146
153
*
147
154
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
148
155
*/
@@ -158,7 +165,8 @@ public function __construct(
158
165
Json $ json = null ,
159
166
LayoutFactory $ layoutFactory = null ,
160
167
EncoderInterface $ urlEncoder = null ,
161
- CategoryRepositoryInterface $ categoryRepository = null
168
+ CategoryRepositoryInterface $ categoryRepository = null ,
169
+ OptionsData $ optionsData = null
162
170
) {
163
171
$ this ->productCollectionFactory = $ productCollectionFactory ;
164
172
$ this ->catalogProductVisibility = $ catalogProductVisibility ;
@@ -171,6 +179,7 @@ public function __construct(
171
179
$ this ->urlEncoder = $ urlEncoder ?: ObjectManager::getInstance ()->get (EncoderInterface::class);
172
180
$ this ->categoryRepository = $ categoryRepository ?? ObjectManager::getInstance ()
173
181
->get (CategoryRepositoryInterface::class);
182
+ $ this ->optionsData = $ optionsData ?: ObjectManager::getInstance ()->get (OptionsData::class);
174
183
parent ::__construct (
175
184
$ context ,
176
185
$ data
@@ -306,6 +315,17 @@ public function getAddToCartPostParams(Product $product)
306
315
];
307
316
}
308
317
318
+ /**
319
+ * Return product options
320
+ *
321
+ * @param Product $product
322
+ * @return array
323
+ */
324
+ public function getOptionsData (Product $ product ): array
325
+ {
326
+ return $ this ->optionsData ->getOptionsData ($ product );
327
+ }
328
+
309
329
/**
310
330
* @inheritdoc
311
331
*/
0 commit comments