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 04-22-2016, 03:07 PM
jefferis1's Avatar
jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default

what is the category identifier in scripts?


Hi folks,
I'm trying to get a function to NOT work on a single category. But I can't seem to fine the proper identifier...
Here is what works:
Code:
<script>
ecwidMessages = {
"ProductDetails.out_of_stock":"Price On Request"
}
</script>
BUT it changes the message on ALL Product pages. I want it to NOT change the message on our SOLD category. I have tried the category != as the category number alone and with a category DOT in front of it as below and neither works.... Perhaps category must be capitalized? but other scripts use page.type , e.g. Maybe it should be category.number???

Here is what does not work:
Code:
<script>
Ecwid.OnPageLoad.add(function (page) {
"use strict";
    if (categoryId != "category.18530265") {
ecwidMessages = {
"ProductDetails.out_of_stock":"Price On Request" }
}
}); 
 
</script>
TIA!
Jeff

Last edited by jefferis1; 04-22-2016 at 03:18 PM.
  #2  
Old 04-27-2016, 06:28 PM
jefferis1's Avatar
jefferis1 jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default

Bump... Anyone? Anyone?
Help!
  #3  
Old 04-28-2016, 12:10 AM
Cyril D's Avatar
Cyril D Cyril D is offline
Ecwid Team
 
Join Date: Feb 2015
Location: Ecwid HQ
Posts: 530
Default

Hi Jeff,
Quote:
Originally Posted by jefferis1 View Post
Maybe it should be category.number???
It should be the "categoryId" property of the "page" object. So, if you want to apply some code to products in a particular category, a script will look like as follows:

Code:
<script>
Ecwid.OnPageLoad.add(function (page) {
    if (page.type === "PRODUCT" && page.categoryId === CATEGORYID) {
        ecwidMessages = {
            "ProductDetails.out_of_stock":"Price On Request"
        }
        Ecwid.Cart.calculateTotal(function () { });
    }
});
</script>
The CATEGORYID marked in red should be replaced with an actual category ID. Feel free to take a look at our article on how to get a product or category ID if you don't know it already. Also, you can see the calculateTotal method at the end of the script. I've added it because if you want to apply the custom translations code to the storefront dynamically, you'll have to force Ecwid refresh its DOM and calling the calculateTotal method allows us to do that.

There's an alternative solution that's a bit faster. I've used jQuery to make the script simpler:

Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
Ecwid.OnPageLoad.add(function (page) {
    if (page.type === "PRODUCT" && page.categoryId === CATEGORYID) {
        $(".ecwid-productBrowser-details-outOfStockLabel").text("Price On Request");
});
</script>
Also, I suggest you check out our docs on the JavaScript API. They describe all properties, methods, objects you can use in your scripts.

Hope this was helpful.
__________________
Cyril D.
Ecwid Customer Care Team

More tips and hints on Ecwid use in our Help Center

⬇ Please click Thanks if my reply helped you.
  #4  
Old 04-28-2016, 08:00 PM
jefferis1's Avatar
jefferis1 jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default

Hi... well 2 problems with this code. First, it now works only on the individual product page and not on the category page.
Quote:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
Ecwid.OnPageLoad.add(function (page) {
if (page.type === "PRODUCT" && page.categoryId === 18530265) {
$(".ecwid-productBrowser-details-outOfStockLabel").text("Price On Request");
});
</script>
Whereas the simple script works on all category pages...

Quote:
<script>
ecwidMessages = {
"ProductDetails.out_of_stock":"Price On Request"
}
</script>
BUT, here's the kicker... We want this rewrite to show on all categories EXCEPT one (our sold category)

So if the code would work as above, would you write if (page.type === "PRODUCT" && page.categoryId != 18530265) I.E> NOT EQUALS?

BTW, I have checked the API pages... just not clear on how to implement it like we wish to do...
  #5  
Old 04-28-2016, 11:07 PM
Cyril D's Avatar
Cyril D Cyril D is offline
Ecwid Team
 
Join Date: Feb 2015
Location: Ecwid HQ
Posts: 530
Default

Jeff,
Quote:
Originally Posted by jefferis1 View Post
So if the code would work as above, would you write if (page.type === "PRODUCT" && page.categoryId != 18530265) I.E> NOT EQUALS?
Yes, you're absolutely right.

Please, try this one:

Code:
Ecwid.OnPageLoaded.add(function (page) {
    "use strict";
    if (page.type === "PRODUCT" && page.categoryId != 18530265) {
        $(".ecwid-productBrowser-details-outOfStockLabel").text("Price On Request");
    } else if (page.type === "CATEGORY" && page.categoryId != 18530265) {
        $(".ecwid-BuyNow-outOfStockLabel").text("Price On Request");
    }
});
This script should change the "Out of stock" wording to the "Price On Request" one on category and product pages except the category with 18530265 ID and product pages within that category.

Hope this helps!
__________________
Cyril D.
Ecwid Customer Care Team

More tips and hints on Ecwid use in our Help Center

⬇ Please click Thanks if my reply helped you.
  #6  
Old 04-29-2016, 01:04 AM
jefferis1's Avatar
jefferis1 jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default

THANK YOU THANK YOU THANK YOU!
  #7  
Old 04-29-2016, 08:09 AM
Cyril D's Avatar
Cyril D Cyril D is offline
Ecwid Team
 
Join Date: Feb 2015
Location: Ecwid HQ
Posts: 530
Default

Quote:
Originally Posted by jefferis1 View Post
THANK YOU THANK YOU THANK YOU!
You're very welcome, Jeff! I'm glad that has worked.
__________________
Cyril D.
Ecwid Customer Care Team

More tips and hints on Ecwid use in our Help Center

⬇ Please click Thanks if my reply helped you.
  #8  
Old 05-02-2016, 04:19 PM
jefferis1's Avatar
jefferis1 jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default

Hi... just ran into a problem we think... WordPress automatically adds <![CDATA[ to the functions and it seems that it is breaking some of the scripts...
You have any ideas? For example the script to replace out of stock with price on request was working friday, but monday morning it was not.. I replaced the script without the CDATA and it worked again...
  #9  
Old 05-04-2016, 01:36 PM
Skyler's Avatar
Skyler Skyler is offline
 
Join Date: Apr 2016
Posts: 25
Default

Quote:
Originally Posted by jefferis1 View Post
Hi... just ran into a problem we think... WordPress automatically adds <![CDATA[ to the functions and it seems that it is breaking some of the scripts...
You have any ideas? For example the script to replace out of stock with price on request was working friday, but monday morning it was not.. I replaced the script without the CDATA and it worked again...
Hello! This is Skyler from Ecwid Customer Care team.

In order to avoid a situation when Wordpress breaks your Javascript code, you should paste such kind of code into the following table on the WordPress Editor: Pages -> Store -> Text mode, then press Update and View Page. If you input any Javascript code into this table in Visual mode, your code will be broken again.

There’s even an easier way to solve the issue - to install WP-No-Format plugin, follow this link to do that https://wordpress.org/plugins/wp-no-format/. This plugin will help you prevent WordPress from modifying the code. After installing the plugin enter your code and update the store. You’ll see that the code will be changed by adding CDATA tag between some code elements, but, anyway, this time your code will work.
  #10  
Old 06-07-2016, 06:15 PM
jefferis1's Avatar
jefferis1 jefferis1 is offline
Junior Member
 
Join Date: May 2013
Posts: 16
Default Doesn't work on Search Results pages

Hi Cyril. This has worked great for us on Joden.com We just discovered though that it doesn't work if the item is found through search instead of through a category.
Is there a way we can apply the Price on Request to the search result pages?
Thanks again,
Jeff

Quote:
Originally Posted by Cyril D View Post
Jeff,

Yes, you're absolutely right.

Please, try this one:

Code:
Ecwid.OnPageLoaded.add(function (page) {
    "use strict";
    if (page.type === "PRODUCT" && page.categoryId != 18530265) {
        $(".ecwid-productBrowser-details-outOfStockLabel").text("Price On Request");
    } else if (page.type === "CATEGORY" && page.categoryId != 18530265) {
        $(".ecwid-BuyNow-outOfStockLabel").text("Price On Request");
    }
});
This script should change the "Out of stock" wording to the "Price On Request" one on category and product pages except the category with 18530265 ID and product pages within that category.

Hope this helps!
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Tags
category, category id, script issues, script tag

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 03:24 AM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.