Promise indicates fulfillment, while it's actually not!!

Hi there,

I’m building a Wishlist app for Wix Stores , and had an issue with the new icon buttons , promises handled with conditional statements don’t give you the expected results, even when the promise indicates that it was fulfilled.

I had this issue on icon buttons before when building a Refunds / Return app, and use the conditional statement to .collapse( ) / .expand( ) , and now I have the same issue in the Wishlist app and the .diable( ) and .enable( ) .

When checking the item’s stock availability, disable the " Add to Cart " button if the product is out of stock, and enable it if it’s not.

if (inStock === true) {
    if ($item('#addToCart').enabled === true) {
        console.log('Already Enabled');
    } else {
        await $item('#addToCart').enable().then( () => {console.info('Enabled')}, () => {console.warn('Button enabling failed')});
    }
} else {
    if ($item('#addToCart').enabled === true) {
        await $item('#addToCart').disable().then( () => {console.info('Disabled')}, () => {console.warn('Button disabling failed')})
    } else {
        console.log('Already Disabled')
    }
}

As you can see in the code above, I programmed it to work whether the button was enabled or disabled by default, and the console logged that the promise was fulfilled
and printed the (fulfillment) message.

The products in the Wishlist which are out of stock indicates in the console that their button is “Disabled” or “Already Disabled”, and the in stock products returned “Enabled” or “Already Enabled” depending on the initial status of the button.

Does anyone has this this issue?

I don’t understand the problem that you are describing? What isn’t working? What happens or doesn’t happen when the Promise is fulfilled?

Hi @yisrael-wix , when the promise is fulfilled, the button should be disabled when the product is out of stock, but it’s not, it remain enabled as visual, but looses it’s link.

@ahmadnasriya Is this on a Store or Product page? Or is this a page that you’ve built? Where does $item come from?

@yisrael-wix It’s a page that I’ve built as a Member Area Page , I knew someone will ask about the $item , it’s because this code is inside a repeater on that page.

@yisrael-wix


The button circled with the blue circle is disabled, I knew that because it has no link, but the button isn’t changing to “Disabled” state, I tried the regular button and it worked, the issue with promises is only with the new icon buttons.

I’d like to take a look at this. If I suspect it’s a bug, I’ll send it on the QA for evaluation.

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

@yisrael-wix

OK, click here to open the editor . [Link Removed]
the page is " My Wishlist " [Member Area Page].

I also had issues with the new icon buttons when I was trying to collapse and expand them on previous projects.

Thanks for your help :blush:

Hey @ahmadnasriya , some observations:

The dataset onReady() event handler does not need an await before it. This function gets triggered when the dataset is ready. See the onReady() API for details and sample code snippets.

Same thing with the repeater’s onItemReady() . See the onItemReady() API for details and sample code snippets.

And, you don’t need the await before the enable() and disable() since you are using .then() for both of those.

I’m not sure that any of these points will help, but it’s best to use the correct use of the API.

You can also move the onItemReady() function outside of the dataset’s onReady() function since it doesn’t get called till the Repeater renders.

If this stuff doesn’t help, at the top of the “My Wishlist” code, please add some test credentials that I can use to test. (and of course, don’t forget, no one else will be able to see these credentials)

If it is a wishlist for Wix Stores, then why not just use the Wishlist for Wix Stores that is already setup?
https://www.wix.com/corvid/example/wishlist

You’re no fun! :upside_down_face:

@givemeawhisky I know that there’s already a tutorial, I’m new to coding and I love to challenge myself :blush: If that make sense.

@yisrael-wix

Work done quicker means more time for longer leisurely drinking session :grin:

@ahmadnasriya

Challenging yourself is a great idea and a way of learning, just note that it is there as a fallback if you need to refer to it for any help or assistance.

@ahmadnasriya , @givemeawhisky has a good point. I like a challenge, and it’s good to learn the fundamentals, and you deserve kudos for that. I even looked at the Wishlist example to see what it did before I replied to your post. I was just assuming that you had a specific task you were focusing on.

However, laziness is a virtue. If you’ve got an easier way to do something, it’s worth looking at. However, realize that sometimes the easy way gets you started quickly but may not be flexible enough for your purposes.

@yisrael-wix , thanks a lot for the notes.

The repeater’s onItemReady() function was actually outside the on.Ready() function, but I needed a value that’s constantly changing based of different variables, and the original value is stored inside the .onReady() function, that’s why I put in inside it.

I didn’t understand what you mean of “testing credentials”, what are they? And how you could you use them to test?

@givemeawhisky Yup, of course, I’ll refer to it or ask this helpful community if I needed help.

@yisrael-wix If I want to learn how to code, copy and paste the code won’t get me anywhere, I love to understand the code and how it works, challenge myself and say, If they can do it, I can also do it, also, I’d like to compare my final result to the example that Wix offers, and see where I did something wrong, and how to do even better than the example.

Thanks for the compliment by the way, and for your help :wink:

@ahmadnasriya I would suggest you try out the Wishlist example as it uses Wix Stores so much of the functionality is already built in - and who knows, it might already do what you want.

As far as learning the basics, if you want to learn a bit more about Repeaters, there are a good number of examples available for you to play with. Especially, see the Todo List and Input Components in Repeaters examples.

@ahmadnasriya By credentials, I mean to make it easier for me to look at what you’ve got so far, I would like to be able to log in and play with the site myself. A test login would be nice to use. Since wix-users isn’t fully functional in Preview mode, I’ll just see if I can figure something out.