Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Foundation.Cms/Extensions/ContentReferenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,19 @@ public static Uri GetUri(this ContentReference contentRef, string lang, bool isA
//Work out the correct domain to use from the hosts defined in the site definition
var siteDefinition = SiteDefinitionResolver.Value.GetByContent(contentRef, true, true);
var host = siteDefinition.Hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Primary) ?? siteDefinition.Hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Undefined);
var baseUrl = (host?.Name ?? "*").Equals("*") ? siteDefinition.SiteUrl : new Uri($"http{((host.UseSecureConnection ?? false) ? "s" : string.Empty)}://{host.Name}");
Uri baseUrl;

if (host != null)
{
baseUrl = (host?.Name ?? "*").Equals("*") ? siteDefinition.SiteUrl : new Uri($"http{((host.UseSecureConnection ?? false) ? "s" : string.Empty)}://{host.Name}");
}
else
{
var siteDef = SiteDefinitionResolver.Value.GetByContent(ContentReference.StartPage, true, true);
var siteDefHost = siteDef.Hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Primary) ?? siteDefinition.Hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Undefined);
baseUrl = (siteDefHost?.Name ?? "*").Equals("*") ? siteDef.SiteUrl : new Uri($"http{((siteDefHost.UseSecureConnection ?? false) ? "s" : string.Empty)}://{siteDefHost.Name}");
}

return new Uri(baseUrl, urlString);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FoundationCommerce from "Assets/js/common/foundation.commerce";
import FoundationPersonalization from "Assets/js/common/foundation.cms.personalization";

feather.replace();
window.feather = feather;

let foundationCms = new FoundationCms();
foundationCms.init();
Expand Down
360 changes: 180 additions & 180 deletions src/Foundation/Features/CatalogContent/product.js
Original file line number Diff line number Diff line change
@@ -1,188 +1,188 @@
export default class Product {
constructor(divId) {
if (divId) {
this.divContainerId = divId;
} else {
this.divContainerId = document;
}
}

init() {
this.addToWishlistClick();
this.addToSharedCartClick();
this.addToCartClick();
this.addAllToCartClick();
this.deleteWishlistClick();
constructor(divId) {
if (divId) {
this.divContainerId = divId;
} else {
this.divContainerId = document;
}

addToCart(data, url, callback, isAddToCart) {
$('body>.loading-box').show();
data.requestFrom = "axios";
axios.post(url, data)
.then(function (result) {
if (result.data.StatusCode == 0) {
notification.warning(result.data.Message);
}
if (result.data.StatusCode == 1) {
let checkoutLink = "";
let cartLink = "";
if ($('#checkoutBtnId')) {
checkoutLink = $('#checkoutBtnId').attr('href');
}

if ($('#cartBtnId')) {
cartLink = $('#cartBtnId').attr('href');
}

let message = result.data.Message;
if (isAddToCart) {
let bottomNotification = `\n<div style='display: flex; justify-content: space-between; margin-top: 15px;'>
}

init() {
this.addToWishlistClick();
this.addToSharedCartClick();
this.addToCartClick();
this.addAllToCartClick();
this.deleteWishlistClick();
}

addToCart(data, url, callback, isAddToCart) {
$('body>.loading-box').show();
data.requestFrom = "axios";
axios.post(url, data)
.then(function (result) {
if (result.data.StatusCode == 0) {
notification.warning(result.data.Message);
}
if (result.data.StatusCode == 1) {
let checkoutLink = "";
let cartLink = "";
if ($('#checkoutBtnId')) {
checkoutLink = $('#checkoutBtnId').attr('href');
}

if ($('#cartBtnId')) {
cartLink = $('#cartBtnId').attr('href');
}

let message = result.data.Message;
if (isAddToCart) {
let bottomNotification = `\n<div style='display: flex; justify-content: space-between; margin-top: 15px;'>
<a href='`+ cartLink + `' class='btn-notification'>View Cart</a>
<a href='`+ checkoutLink + `' class='btn-notification'>Checkout</a>
</div>`;
message += bottomNotification;
}

notification.success(message, false);

if (callback) callback(result.data.CountItems);
}
})
.catch(function (error) {
notification.error("Can not add the product to the cart.\n" + error.response.statusText);
})
.finally(function () {
$('body>.loading-box').hide();
});

return false;
}

// use in Wishlist Page
removeItem(data, url, message, callback) {
$('body>.loading-box').show();
axios.post(url, data)
.then(function (result) {
if (result.status == 200) {
notification.success(message);
$('#my-wishlist').html(result.data);
let product = new Product('#my-wishlist');
product.Init();
let count = $('#countWishListInPage').val();
if (callback) callback(count);

feather.replace();
}
if (result.status == 204) {
notification.error(result.statusText);
}
})
.catch(function (error) {
notification.error(error);
})
.finally(function () {
$('body>.loading-box').hide();
});
}

callbackAddToCart(selector, count) {
if (selector == ".jsCartBtn") { cartHelper.setCartReload(count); }
else if (selector == ".jsSharedCartBtn") { cartHelper.setSharedCartReload(count)}
else cartHelper.setWishlistReload(count);
}

addToSharedCartClick() {
let inst = this;
$(this.divContainerId).find('.addToSharedCart').each(function (i, e) {
$(e).click(function () {
let code = $(this).attr('data');

let callback = (count) => {
inst.callbackAddToCart('.jsSharedCartBtn', count);
};

inst.addToCart({ Code: code }, '/SharedCart/AddToCart', callback);
});
});
}

addToWishlistClick() {
let inst = this;

$(this.divContainerId).find('.addToWishlist').each(function (i, e) {
$(e).click(function () {
let code = $(this).attr('data');
message += bottomNotification;
}

let callback = (count) => {
inst.callbackAddToCart('#js-wishlist', count);
};
notification.success(message, false);

inst.addToCart({ Code: code }, '/Wishlist/AddToCart', callback);
});
});

}

addToCartClick() {
let inst = this;

$(this.divContainerId).find('.addToCart').each(function (i, e) {
$(e).attr("href", "javascript:void(0);")
$(e).click(function () {
let code = $(this).attr('data');
let data = {
Code: code
};

if ($(this).attr('qty')) data.Quantity = $(this).attr('qty');
if ($(this).attr('store')) data.Store = $(this).attr('store');
if ($(this).attr('selectedStore')) data.SelectedStore = $(this).attr('selectedStore');

let callback = (count) => {
inst.callbackAddToCart('.jsCartBtn', count);
};

inst.addToCart(data, '/DefaultCart/AddToCart', callback, true);
});
});
}

deleteWishlistClick() {
let inst = this;

$(this.divContainerId).find('.deleteLineItemWishlist').each(function (i, e) {
$(e).click(function () {
if (confirm("Are you sure?")) {
let code = $(e).attr('data');
let data = { Code: code, Quantity: 0, RequestFrom: "axios" };
let callback = (count) => {
inst.callbackAddToCart("#js-wishlist", count);
};
inst.removeItem(data, '/Wishlist/ChangeCartItem', "Removed " + code + " from wishlist", callback);
}
});
});
}

addAllToCartClick() {
$(this.divContainerId).find('.jsAddAllToCart').each(function (i, e) {
$(e).click(function () {
$('.loading-box').show();
let url = $(this).attr('url');
axios.post(url)
.then(function (result) {
notification.success(result.data.Message);
cartHelper.setCartReload(result.data.CountItems);
})
.catch(function (error) {
notification.error(error);
})
.finally(function () {
$('.loading-box').hide();
});

});
});

}
if (callback) callback(result.data.CountItems);
}
})
.catch(function (error) {
notification.error("Can not add the product to the cart.\n" + error.response.statusText);
})
.finally(function () {
$('body>.loading-box').hide();
});

return false;
}

// use in Wishlist Page
removeItem(data, url, message, callback) {
$('body>.loading-box').show();
axios.post(url, data)
.then(function (result) {
if (result.status == 200) {
notification.success(message);
$('#my-wishlist').html(result.data);
feather.replace();

let product = new Product('#my-wishlist');
product.init();
let count = $('#countWishListInPage').val();
if (callback) callback(count);
}
if (result.status == 204) {
notification.error(result.statusText);
}
})
.catch(function (error) {
notification.error(error);
})
.finally(function () {
$('body>.loading-box').hide();
});
}

callbackAddToCart(selector, count) {
if (selector == ".jsCartBtn") { cartHelper.setCartReload(count); }
else if (selector == ".jsSharedCartBtn") { cartHelper.setSharedCartReload(count) }
else cartHelper.setWishlistReload(count);
}

addToSharedCartClick() {
let inst = this;
$(this.divContainerId).find('.addToSharedCart').each(function (i, e) {
$(e).click(function () {
let code = $(this).attr('data');

let callback = (count) => {
inst.callbackAddToCart('.jsSharedCartBtn', count);
};

inst.addToCart({ Code: code }, '/SharedCart/AddToCart', callback);
});
});
}

addToWishlistClick() {
let inst = this;

$(this.divContainerId).find('.addToWishlist').each(function (i, e) {
$(e).click(function () {
let code = $(this).attr('data');

let callback = (count) => {
inst.callbackAddToCart('#js-wishlist', count);
};

inst.addToCart({ Code: code }, '/Wishlist/AddToCart', callback);
});
});

}

addToCartClick() {
let inst = this;

$(this.divContainerId).find('.addToCart').each(function (i, e) {
$(e).attr("href", "javascript:void(0);")
$(e).click(function () {
let code = $(this).attr('data');
let data = {
Code: code
};

if ($(this).attr('qty')) data.Quantity = $(this).attr('qty');
if ($(this).attr('store')) data.Store = $(this).attr('store');
if ($(this).attr('selectedStore')) data.SelectedStore = $(this).attr('selectedStore');

let callback = (count) => {
inst.callbackAddToCart('.jsCartBtn', count);
};

inst.addToCart(data, '/DefaultCart/AddToCart', callback, true);
});
});
}

deleteWishlistClick() {
let inst = this;

$(this.divContainerId).find('.deleteLineItemWishlist').each(function (i, e) {
$(e).click(function () {
if (confirm("Are you sure?")) {
let code = $(e).attr('data');
let data = { Code: code, Quantity: 0, RequestFrom: "axios" };
let callback = (count) => {
inst.callbackAddToCart("#js-wishlist", count);
};
inst.removeItem(data, '/Wishlist/ChangeCartItem', "Removed " + code + " from wishlist", callback);
}
});
});
}

addAllToCartClick() {
$(this.divContainerId).find('.jsAddAllToCart').each(function (i, e) {
$(e).click(function () {
$('.loading-box').show();
let url = $(this).attr('url');
axios.post(url)
.then(function (result) {
notification.success(result.data.Message);
cartHelper.setCartReload(result.data.CountItems);
})
.catch(function (error) {
notification.error(error);
})
.finally(function () {
$('.loading-box').hide();
});

});
});

}
}
Loading