Created
April 17, 2020 08:26
-
-
Save zivce/e95924f0ecc8c0acefcf70dea80cad3f to your computer and use it in GitHub Desktop.
Removing products from wishlist. A lot of if blocks, hard to follow paths.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static removeProductFromWishListHandler(e) { | |
e.stopPropagation(); | |
const target = $(e.currentTarget); | |
const $wishlistList = $(".wishlist-list__body"); | |
const productCode = target.data("product-code"); | |
const $myFavouritesRollover = $(".mini-favourites"); | |
const $myFavouritesSendList = $(".wishlist-send-list"); | |
const emptyWishlistHTML = $("#emptyWishlistPopupTemplate").html(); | |
const $myFavouritesRolloverContainer = $( | |
".my-favourites-rollover__content", | |
$myFavouritesRollover | |
); | |
const $myFavouritesRolloverControls = $( | |
".my-favourites-rollover__controls", | |
$myFavouritesRollover | |
); | |
if ($wishlistList.length) startRefreshEffects($wishlistList); | |
const setAsEmpty = () => { | |
$myFavouritesSendList.remove(); | |
if ($myFavouritesRolloverContainer.length) { | |
$myFavouritesRolloverContainer.remove(); | |
$myFavouritesRolloverControls.remove(); | |
$myFavouritesRollover.prepend(emptyWishlistHTML); | |
} | |
}; | |
requestPost("/favourites/remove", { productCode }, { format: "text" }).then( | |
response => { | |
const $wishlistCount = $("[data-wishlist-item-count]"); | |
const count = parseInt( | |
$(response) | |
.find("[data-wishlist-item-count]") | |
.attr("data-wishlist-item-count"), | |
10 | |
); | |
if (count === 0) { | |
setAsEmpty(); | |
} | |
if (count <= 12) { | |
$(".js-load-more-favourites").hide(); | |
$(".column-block").show(); | |
} | |
if ($wishlistList.length) { | |
if ($(".wishlist--limit-achieved").length) | |
$(".wishlist--limit-achieved").remove(); | |
$wishlistList.html( | |
$(response) | |
.find(".wishlist-list__body") | |
.html() | |
); | |
window.BB.product.bindToAddToCartForm(); | |
if ($(".js-load-more-favourites").length) { | |
$(".js-load-more-favourites") | |
.find("span") | |
.html(`(${count})`); | |
} else { | |
$(".column-block").show(); | |
} | |
$(".remove-favourite") | |
.removeAttr("disabled") | |
.removeClass("disabled"); | |
initWishlistATB(); | |
setTimeout(() => endRefreshEffects($wishlistList), 500); | |
} | |
if (!$(response).find(".wishlist-list__body").length) { | |
const $listerContainer = $(".wishlist"); | |
$listerContainer.html( | |
$(response) | |
.find(".wishlist") | |
.html() | |
); | |
} | |
$wishlistCount.html(count); | |
$wishlistCount.attr("data-wishlist-item-count", count); | |
this.refreshWishListRollover(); | |
} | |
); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment