Skip to content

Commit a128f39

Browse files
committed
Fix #24091 - Selected configurable product attribute options are not displaying in wishlist page.
1 parent 6b6f428 commit a128f39

File tree

4 files changed

+84
-24
lines changed

4 files changed

+84
-24
lines changed

app/code/Magento/Wishlist/Block/AddToWishlist.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
namespace Magento\Wishlist\Block;
88

9+
use Magento\Framework\View\Element\Template;
10+
911
/**
1012
* Wishlist js plugin initialization block
1113
*
1214
* @api
1315
* @since 100.1.0
1416
*/
15-
class AddToWishlist extends \Magento\Framework\View\Element\Template
17+
class AddToWishlist extends Template
1618
{
1719
/**
1820
* Product types
@@ -21,20 +23,6 @@ class AddToWishlist extends \Magento\Framework\View\Element\Template
2123
*/
2224
private $productTypes;
2325

24-
/**
25-
* @param \Magento\Framework\View\Element\Template\Context $context
26-
* @param array $data
27-
*/
28-
public function __construct(
29-
\Magento\Framework\View\Element\Template\Context $context,
30-
array $data = []
31-
) {
32-
parent::__construct(
33-
$context,
34-
$data
35-
);
36-
}
37-
3826
/**
3927
* Returns wishlist widget options
4028
*
@@ -43,7 +31,10 @@ public function __construct(
4331
*/
4432
public function getWishlistOptions()
4533
{
46-
return ['productType' => $this->getProductTypes()];
34+
return [
35+
'productType' => $this->getProductTypes(),
36+
'isProductList' => (bool)$this->getData('is_product_list')
37+
];
4738
}
4839

4940
/**
@@ -56,7 +47,7 @@ private function getProductTypes()
5647
{
5748
if ($this->productTypes === null) {
5849
$this->productTypes = [];
59-
$block = $this->getLayout()->getBlock('category.products.list');
50+
$block = $this->getLayout()->getBlock($this->getProductListBlockName());
6051
if ($block) {
6152
$productCollection = $block->getLoadedProductCollection();
6253
$productTypes = [];
@@ -71,7 +62,18 @@ private function getProductTypes()
7162
}
7263

7364
/**
74-
* {@inheritdoc}
65+
* Get product list block name in layout
66+
*
67+
* @return string
68+
*/
69+
private function getProductListBlockName(): string
70+
{
71+
return $this->getData('product_list_block') ?: 'category.products.list';
72+
}
73+
74+
/**
75+
* @inheritDoc
76+
*
7577
* @since 100.1.0
7678
*/
7779
protected function _toHtml()

app/code/Magento/Wishlist/view/frontend/layout/catalog_category_view.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
template="Magento_Wishlist::catalog/product/list/addto/wishlist.phtml"/>
2222
</referenceBlock>
2323
<referenceContainer name="category.product.list.additional">
24-
<block class="Magento\Wishlist\Block\AddToWishlist" name="category.product.list.additional.wishlist_addto" template="Magento_Wishlist::addto.phtml" />
24+
<block
25+
class="Magento\Wishlist\Block\AddToWishlist"
26+
name="category.product.list.additional.wishlist_addto"
27+
template="Magento_Wishlist::addto.phtml"
28+
>
29+
<arguments>
30+
<argument name="is_product_list" xsi:type="boolean">true</argument>
31+
</arguments>
32+
</block>
2533
</referenceContainer>
2634
</referenceContainer>
2735
</body>

app/code/Magento/Wishlist/view/frontend/layout/catalogsearch_result_index.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,17 @@
1414
template="Magento_Wishlist::catalog/product/list/addto/wishlist.phtml"/>
1515
</referenceBlock>
1616
</referenceContainer>
17+
<referenceBlock name="wishlist_page_head_components">
18+
<block
19+
class="Magento\Wishlist\Block\AddToWishlist"
20+
name="catalogsearch.wishlist_addto"
21+
template="Magento_Wishlist::addto.phtml"
22+
>
23+
<arguments>
24+
<argument name="is_product_list" xsi:type="boolean">true</argument>
25+
<argument name="product_list_block" xsi:type="string">search_result_list</argument>
26+
</arguments>
27+
</block>
28+
</referenceBlock>
1729
</body>
1830
</page>

app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ define([
1717
downloadableInfo: '#downloadable-links-list input',
1818
customOptionsInfo: '.product-custom-option',
1919
qtyInfo: '#qty',
20-
actionElement: '[data-action="add-to-wishlist"]'
20+
actionElement: '[data-action="add-to-wishlist"]',
21+
productListItem: '.item.product-item',
22+
productListPriceBox: '.price-box',
23+
isProductList: false
2124
},
2225

2326
/** @inheritdoc */
@@ -65,6 +68,7 @@ define([
6568
_updateWishlistData: function (event) {
6669
var dataToAdd = {},
6770
isFileUploaded = false,
71+
productId = null,
6872
self = this;
6973

7074
if (event.handleObj.selector == this.options.qtyInfo) { //eslint-disable-line eqeqeq
@@ -83,7 +87,19 @@ define([
8387
$(element).is('textarea') ||
8488
$('#' + element.id + ' option:selected').length
8589
) {
86-
if ($(element).data('selector') || $(element).attr('name')) {
90+
if (!($(element).data('selector') || $(element).attr('name'))) {
91+
return;
92+
}
93+
94+
if (self.options.isProductList) {
95+
productId = self.retrieveListProductId(this);
96+
97+
dataToAdd[productId] = $.extend(
98+
{},
99+
dataToAdd[productId] ? dataToAdd[productId] : {},
100+
self._getElementData(element)
101+
);
102+
} else {
87103
dataToAdd = $.extend({}, dataToAdd, self._getElementData(element));
88104
}
89105

@@ -107,18 +123,25 @@ define([
107123
* @private
108124
*/
109125
_updateAddToWishlistButton: function (dataToAdd) {
110-
var self = this;
126+
var productId = null,
127+
self = this;
111128

112129
$('[data-action="add-to-wishlist"]').each(function (index, element) {
113-
var params = $(element).data('post');
130+
var params = $(element).data('post'),
131+
dataToAddObj = dataToAdd;
132+
133+
if (self.options.isProductList) {
134+
productId = self.retrieveListProductId(element);
135+
dataToAddObj = typeof dataToAdd[productId] !== 'undefined' ? dataToAdd[productId] : {};
136+
}
114137

115138
if (!params) {
116139
params = {
117140
'data': {}
118141
};
119142
}
120143

121-
params.data = $.extend({}, params.data, dataToAdd, {
144+
params.data = $.extend({}, params.data, dataToAddObj, {
122145
'qty': $(self.options.qtyInfo).val()
123146
});
124147
$(element).data('post', params);
@@ -241,6 +264,21 @@ define([
241264

242265
return;
243266
}
267+
},
268+
269+
/**
270+
* Retrieve product id from element on products list
271+
*
272+
* @param {jQuery.Object} element
273+
* @private
274+
*/
275+
retrieveListProductId: function (element) {
276+
return parseInt(
277+
$(element).closest(this.options.productListItem)
278+
.find(this.options.productListPriceBox)
279+
.data('product-id'),
280+
10
281+
);
244282
}
245283
});
246284

0 commit comments

Comments
 (0)