The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.
 
 
Thread Tools Display Modes
  #1  
Old 03-19-2014, 05:32 PM
Danny3928729834792h823's Avatar
Danny3928729834792h823 is offline
Junior Member
 
Join Date: Mar 2014
Posts: 3
Default

Simultaneously Link Categories and Products to an External Site


I'm trying to set up categories and products that link to external sites via the same store page, but the javascript snippets are cancelling each other. How can i set this up so both kinds of redirects work simultaneously?

Code:
<!-- START category that links to an external site -->
 <script>
// categoryURLs array as category Id => redirection URL
// Please use this array to define your own redirection rules
var categoryURLs = {
  '1234567' : '/index.html', // Sample 01 Category Page redirects to Homepage
  '2345678' : '/index.html' // Sample 02 Category Page redirects to Homepage
};
 
// Add handler for Ecwid's OnPageLoad event
if (
  typeof(Ecwid) == 'object'
  && typeof(Ecwid.OnPageLoad) == 'object'
) {
  Ecwid.OnPageLoad.add(function(page) {
    // Redirect user if needed
    if (
      typeof(page) == 'object'
      && 'CATEGORY' == page.type
      && typeof(categoryURLs[page.categoryId]) == 'string'
      && categoryURLs[page.categoryId].length > 0
    ) {
      window.location = categoryURLs[page.categoryId];
    }
  });
}
</script>
<!-- END category that links to an external site -->

<!-- START product that links to an external site -->
<script>
// categoryURLs array as category Id => redirection URL
// Please use this array to define your own redirection rules
var categoryURLs = {
  '123456789' : '../sample-product-page.html'
};
 
// Add handler for Ecwid's OnPageLoad event
if (
  typeof(Ecwid) == 'object'
  && typeof(Ecwid.OnPageLoad) == 'object'
) {
  Ecwid.OnPageLoad.add(function(page) {
    // Redirect user if needed
    if (
      typeof(page) == 'object'
      && 'PRODUCT' == page.type
      && typeof(categoryURLs[page.productId]) == 'string'
      && categoryURLs[page.productId].length > 0
    ) {
      window.location = categoryURLs[page.productId];
    }
  });
}
</script>
<!-- END product that links to an external site -->

Also your js base file on github appears to be down:
[You can use the following js file as a base for your own one:
https://raw.github.com/gist/1373124/44bea3e8c112a4fcb9ad288ac2693b80dab073ed/ecwid_category_redirects.js]
  #2  
Old 03-21-2014, 05:13 AM
Maya's Avatar
Maya Maya is offline
Ecwid Team
 
Join Date: Feb 2010
Location: Ecwid headquarter
Posts: 5,876
Default

Hello,

Please, try following code to redirect customer to the custom page, when Ecwid category or product were clicked:

Code:
<script>
// categoryURLs array as category Id => redirection URL
// Please use this array to define your own redirection rules
var categoryURLs = {
  '1234567' : '/index.html', // Sample 01 Category Page redirects to Homepage
  '2345678' : '/index.html' // Sample 02 Category Page redirects to Homepage
};
 
// Add handler for Ecwid's OnPageLoad event
if (
  typeof(Ecwid) == 'object'
  && typeof(Ecwid.OnPageLoad) == 'object'
) {
  Ecwid.OnPageLoad.add(function(page) {
    // Redirect user if needed
    if (
      typeof(page) == 'object'
      && 'CATEGORY' == page.type
      && typeof(categoryURLs[page.categoryId]) == 'string'
      && categoryURLs[page.categoryId].length > 0
    ) {
      window.location = categoryURLs[page.categoryId];
    }
  });
}
</script>
<!-- END category that links to an external site -->

<!-- START product that links to an external site -->
<script>
// categoryURLs array as category Id => redirection URL
// Please use this array to define your own redirection rules
var productURLs = {
  '123456789' : '../sample-product-page.html'
};
 
// Add handler for Ecwid's OnPageLoad event
if (
  typeof(Ecwid) == 'object'
  && typeof(Ecwid.OnPageLoad) == 'object'
) {
  Ecwid.OnPageLoad.add(function(page) {
    // Redirect user if needed
    if (
      typeof(page) == 'object'
      && 'PRODUCT' == page.type
      && typeof(productURLs[page.productId]) == 'string'
      && productURLs[page.productId].length > 0
    ) {
      window.location = productURLs[page.productId];
    }
  });
}
</script>
<!-- END product that links to an external site -->
Use categoryURLs array as a list of categories IDs and productURLs as a list of product IDs.

Good luck!
__________________
Maya N., Ecwid Team

------------------
Welcome to our new Help Center!

Last edited by Maya; 03-25-2014 at 12:25 PM.
  #3  
Old 03-21-2014, 02:38 PM
Danny3928729834792h823's Avatar
Danny3928729834792h823 Danny3928729834792h823 is offline
Junior Member
 
Join Date: Mar 2014
Posts: 3
Default

One note on the script you pasted above:
I had to change
Code:
&& typeof(categoryURLs[page.productId]) == 'string'
to
Code:
&& typeof(productURLs[page.productId]) == 'string'
Otherwise, it all seems to be working now. Thanks!
The Following User Says Thank You to Danny3928729834792h823 For This Useful Post:
Maya (03-25-2014)
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:55 PM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.