Skip to content

Instantly share code, notes, and snippets.

@genee19
Created April 26, 2012 13:22
Show Gist options
  • Save genee19/2499515 to your computer and use it in GitHub Desktop.
Save genee19/2499515 to your computer and use it in GitHub Desktop.
A simple script that wouldn't allow to open product details page, redirecting to its category view instead. Usage: prohibitEcwidProductDetails() to prohibit all product details, prohibitEcwidProductDetails(3003, 3004); to prohibit only in some categories
function prohibitEcwidProductDetails() {
var categories,
__slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
categories = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
Ecwid.OnPageLoad.add(function(page) {
var _ref;
if (page.type === 'PRODUCT' && ((_ref = page.categoryId, __indexOf.call(categories, _ref) >= 0) || categories.length === 0)) {
window.location.hash = "ecwid:mode=category&category=" + page.categoryId;
}
});
};
/*
Usage:
Disallow viewing of all product details in the whole shop:
prohibitEcwidProductDetails();
Disallow viewing product details in some particular category by its ID:
prohibitEcwidProductDetails(3003);
(where 3003 is the category ID)
Disallow viewing product details in a few category by their IDs:
prohibitEcwidProductDetails(3003, 3004, 3005);
(where 3003, 3004, 3005 are the category IDs)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment