8
8
9
9
namespace Magento \Wishlist \Helper ;
10
10
11
+ use Magento \Catalog \Model \Product ;
11
12
use Magento \Framework \App \ActionInterface ;
12
13
use Magento \Framework \App \ObjectManager ;
13
14
use Magento \Framework \DataObject ;
14
15
use Magento \Framework \Escaper ;
16
+ use Magento \Framework \Exception \NoSuchEntityException ;
15
17
use Magento \Wishlist \Controller \WishlistProviderInterface ;
18
+ use Magento \Wishlist \Model \Item ;
16
19
17
20
/**
18
21
* Wishlist Data Helper
@@ -319,14 +322,18 @@ public function getRemoveParams($item, $addReferer = false)
319
322
*/
320
323
public function getConfigureUrl ($ item )
321
324
{
322
- return $ this ->_getUrl (
325
+ $ query = $ this ->getItemQueryOptions ($ item );
326
+ $ url = $ this ->_getUrl (
323
327
'wishlist/index/configure ' ,
324
328
[
325
329
'id ' => $ item ->getWishlistItemId (),
326
330
'product_id ' => $ item ->getProductId (),
327
- 'qty ' => (int )$ item ->getQty ()
331
+ 'qty ' => (int )$ item ->getQty (),
328
332
]
329
333
);
334
+ $ url .= (isset ($ query ['fragment ' ]) && count ($ query ['fragment ' ])) ?
335
+ '# ' . http_build_query ($ query ['fragment ' ]) : '' ;
336
+ return $ url ;
330
337
}
331
338
332
339
/**
@@ -647,8 +654,29 @@ public function getProductUrl($item, $additional = [])
647
654
} else {
648
655
$ product = $ item ->getProduct ();
649
656
}
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 = [];
650
679
$ buyRequest = $ item ->getBuyRequest ();
651
- $ fragment = [];
652
680
if (is_object ($ buyRequest )) {
653
681
$ config = $ buyRequest ->getSuperProductConfig ();
654
682
if ($ config && !empty ($ config ['product_id ' ])) {
@@ -657,18 +685,14 @@ public function getProductUrl($item, $additional = [])
657
685
false ,
658
686
$ this ->_storeManager ->getStore ()->getStoreId ()
659
687
);
688
+ $ query ['product ' ] = $ product ;
660
689
}
661
- $ fragment = $ this ->getFragmentByProductType ($ buyRequest );
690
+ $ query [ ' fragment ' ] = $ this ->getFragmentByProductType ($ buyRequest );
662
691
if ($ buyRequest ->getQty ()) {
663
- $ additional ['_query ' ]['qty ' ] = $ buyRequest ->getQty ();
692
+ $ query [ ' additional ' ] ['_query ' ]['qty ' ] = $ buyRequest ->getQty ();
664
693
}
665
694
}
666
- $ url = $ product ->getUrlModel ()->getUrl ($ product , $ additional );
667
- if ($ fragment ) {
668
- $ url .= '# ' . http_build_query ($ fragment );
669
- }
670
-
671
- return $ url ;
695
+ return $ query ;
672
696
}
673
697
674
698
/**
0 commit comments