11
11
use Magento \Framework \Pricing \PriceCurrencyInterface ;
12
12
use Magento \Framework \Serialize \Serializer \Json ;
13
13
use Magento \Widget \Block \BlockInterface ;
14
+ use Magento \Framework \Url \EncoderInterface ;
14
15
15
16
/**
16
17
* Catalog Products List widget block
17
18
*
18
19
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
19
21
*/
20
22
class ProductsList extends \Magento \Catalog \Block \Product \AbstractProduct implements BlockInterface, IdentityInterface
21
23
{
@@ -94,6 +96,11 @@ class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implem
94
96
*/
95
97
private $ json ;
96
98
99
+ /**
100
+ * @var \Magento\Framework\Url\EncoderInterface|null
101
+ */
102
+ private $ urlEncoder ;
103
+
97
104
/**
98
105
* @param \Magento\Catalog\Block\Product\Context $context
99
106
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
@@ -104,6 +111,7 @@ class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implem
104
111
* @param \Magento\Widget\Helper\Conditions $conditionsHelper
105
112
* @param array $data
106
113
* @param Json|null $json
114
+ * @param \Magento\Framework\Url\EncoderInterface|null $urlEncoder
107
115
*/
108
116
public function __construct (
109
117
\Magento \Catalog \Block \Product \Context $ context ,
@@ -114,7 +122,8 @@ public function __construct(
114
122
\Magento \CatalogWidget \Model \Rule $ rule ,
115
123
\Magento \Widget \Helper \Conditions $ conditionsHelper ,
116
124
array $ data = [],
117
- Json $ json = null
125
+ Json $ json = null ,
126
+ EncoderInterface $ urlEncoder = null
118
127
) {
119
128
$ this ->productCollectionFactory = $ productCollectionFactory ;
120
129
$ this ->catalogProductVisibility = $ catalogProductVisibility ;
@@ -123,6 +132,7 @@ public function __construct(
123
132
$ this ->rule = $ rule ;
124
133
$ this ->conditionsHelper = $ conditionsHelper ;
125
134
$ this ->json = $ json ?: ObjectManager::getInstance ()->get (Json::class);
135
+ $ this ->urlEncoder = $ urlEncoder ?: ObjectManager::getInstance ()->get (EncoderInterface::class);
126
136
parent ::__construct (
127
137
$ context ,
128
138
$ data
@@ -153,6 +163,7 @@ protected function _construct()
153
163
* Get key pieces for caching block content
154
164
*
155
165
* @return array
166
+ * @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
156
167
*/
157
168
public function getCacheKeyInfo ()
158
169
{
@@ -230,6 +241,7 @@ protected function _beforeToHtml()
230
241
* Prepare and return product collection
231
242
*
232
243
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
244
+ * @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
233
245
*/
234
246
public function createCollection ()
235
247
{
@@ -409,6 +421,22 @@ private function getPriceCurrency()
409
421
return $ this ->priceCurrency ;
410
422
}
411
423
424
+ /**
425
+ * @inheritdoc
426
+ */
427
+ public function getAddToCartUrl ($ product , $ additional = [])
428
+ {
429
+ $ requestingPageUrl = $ this ->getRequest ()->getParam ('requesting_page_url ' );
430
+
431
+ if (!empty ($ requestingPageUrl )) {
432
+ $ additional ['useUencPlaceholder ' ] = true ;
433
+ $ url = parent ::getAddToCartUrl ($ product , $ additional );
434
+ return str_replace ('%25uenc%25 ' , $ this ->urlEncoder ->encode ($ requestingPageUrl ), $ url );
435
+ }
436
+
437
+ return parent ::getAddToCartUrl ($ product , $ additional );
438
+ }
439
+
412
440
/**
413
441
* Get widget block name
414
442
*
0 commit comments