Skip to content

Commit ddf5f29

Browse files
committed
ACP2E-1784: update update wishlist item link for configurable product
1 parent cb8c722 commit ddf5f29

File tree

1 file changed

+35
-11
lines changed
  • app/code/Magento/Wishlist/Helper

1 file changed

+35
-11
lines changed

app/code/Magento/Wishlist/Helper/Data.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
namespace Magento\Wishlist\Helper;
1010

11+
use Magento\Catalog\Model\Product;
1112
use Magento\Framework\App\ActionInterface;
1213
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\DataObject;
1415
use Magento\Framework\Escaper;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1517
use Magento\Wishlist\Controller\WishlistProviderInterface;
18+
use Magento\Wishlist\Model\Item;
1619

1720
/**
1821
* Wishlist Data Helper
@@ -319,14 +322,18 @@ public function getRemoveParams($item, $addReferer = false)
319322
*/
320323
public function getConfigureUrl($item)
321324
{
322-
return $this->_getUrl(
325+
$query = $this->getItemQueryOptions($item);
326+
$url = $this->_getUrl(
323327
'wishlist/index/configure',
324328
[
325329
'id' => $item->getWishlistItemId(),
326330
'product_id' => $item->getProductId(),
327-
'qty' => (int)$item->getQty()
331+
'qty' => (int)$item->getQty(),
328332
]
329333
);
334+
$url .= (isset($query['fragment']) && count($query['fragment'])) ?
335+
'#' . http_build_query($query['fragment']) : '';
336+
return $url;
330337
}
331338

332339
/**
@@ -647,8 +654,29 @@ public function getProductUrl($item, $additional = [])
647654
} else {
648655
$product = $item->getProduct();
649656
}
657+
658+
$query = $this->getItemQueryOptions($item);
659+
if (isset($query['product'])) {
660+
$product = $query['product'];
661+
}
662+
663+
$url = $product->getUrlModel()->getUrl($product, $query['additional'] ?? []);
664+
if (isset($query['fragment']) && count($query['fragment'])) {
665+
$url .= '#' . http_build_query($query['fragment']);
666+
}
667+
668+
return $url;
669+
}
670+
671+
/**
672+
* @param Item|Product $item
673+
* @return array
674+
* @throws NoSuchEntityException
675+
*/
676+
private function getItemQueryOptions(Item|Product $item): array
677+
{
678+
$query = [];
650679
$buyRequest = $item->getBuyRequest();
651-
$fragment = [];
652680
if (is_object($buyRequest)) {
653681
$config = $buyRequest->getSuperProductConfig();
654682
if ($config && !empty($config['product_id'])) {
@@ -657,18 +685,14 @@ public function getProductUrl($item, $additional = [])
657685
false,
658686
$this->_storeManager->getStore()->getStoreId()
659687
);
688+
$query['product'] = $product;
660689
}
661-
$fragment = $this->getFragmentByProductType($buyRequest);
690+
$query['fragment'] = $this->getFragmentByProductType($buyRequest);
662691
if ($buyRequest->getQty()) {
663-
$additional['_query']['qty'] = $buyRequest->getQty();
692+
$query['additional']['_query']['qty'] = $buyRequest->getQty();
664693
}
665694
}
666-
$url = $product->getUrlModel()->getUrl($product, $additional);
667-
if ($fragment) {
668-
$url .= '#' . http_build_query($fragment);
669-
}
670-
671-
return $url;
695+
return $query;
672696
}
673697

674698
/**

0 commit comments

Comments
 (0)