rimmer333
4/26/2012 - 1:22 PM

A simple script that wouldn't allow to open product details page, redirecting to its category view instead. Usage: prohibitEcwidProductDetai

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)

*/