top of page

Forum Posts

Enes
Velo Certified
Velo Certified
Dec 12, 2022
In Coding with Velo
I can't manually approve waiting members I get an error with "FORBIDDEN" code here is the error: Here is the page code: import { approveMember } from 'backend/Members/member-helpers.jsw'; import wixLocation from 'wix-location'; $w.onReady(async function () { const token = wixLocation.query.token; const resourceId = wixLocation.query.resourceId; if (!token) { $w('#tite').text = 'E-Posta Doğrulanamadı!'; } else { console.log('Token', token); const result = await approveMember(token, resourceId); if (result.approved === true) { $w('#tite').text = 'E-Posta Doğrulandı!'; $w('#desc').expand(); } else { $w('#tite').text = 'E-Posta Doğrulanamadı!'; } } }); Here is the backend code: export async function approveMember(token, resourceId) { const verifyEmailChannel = { name: 'verify-email', resourceId }; try { const sessionToken = await authentication.approveByToken(token); console.log('Session Token', sessionToken) const approvedData = { approved: true, sessionToken } await publish(verifyEmailChannel, approvedData); return approvedData; } catch (err) { const approvedData = { approved: false, reason: err } await publish(verifyEmailChannel, approvedData); console.error('Approve Error: ', err); return approvedData; } } So what happens is, I send an email to member and I added a button inside this email with a dynamic URL inside this URL I have approve token. www.domain.com/verify?token=<token> But I can't approve member manually by using approveByToken API I get an error that I shared above. I have tried few basic changes but no effects at all. Why I can't approve member using this API?? -I use the token returned by register API. (and yes it's string)
ApproveByToken Permission Error content media
2
33
236
Enes
Velo Certified
Velo Certified
May 22, 2022
In Velo Pro Discussion
I'm trying to create a custom input system for Editor X because we can't use inputs like slider, rich text box, address input, ratings and pagination and some others also not available on classic editor like data list. I want to create a dynamic custom element which will generate a input with fully customizable options. And functionality will be like wix. Example from Velo: $w('#myDropdown').options = options; Example from my system: myInput.options = options; So I have created a test version to test it with dropdown input which is <select> in html anyway that's not important. I also created a object oriented system in JS to use all these things like in Velo BUT BUT BUT to use this object functions I need to use the HTML Element inside of my custom element. There is no problem with Native JS (I mean when u code it outside of Wix) but in Wix I can't pass the HTML Element to the class as a parameter in any way. What I have tried already? 1. I have tried to pass the needed element (dropdown element) inside custom event: let element = this.shadowRoot.getElementById(inputId); this.dispatchEvent(new CustomEvent('load', { detail: element })) But I'm getting this error: (I have searched for this error and it's probably not doable with Wix) 2. I have tried to get the element from iFrame using document.getElementById and pass the element to the postMessage parameter when I send message to the iFrame. <script type="text/javascript"> window.onmessage = (event) => { let element = document.getElementById('customElement'); window.parent.postMessage("Returned", element); }; </script> In this try no errors but I don't get any response also. So not worked. When I console log the element inside iFrame script what I see is it can't find the element it returns null (in this example I'm not trying to get dropdown element I was trying to get custom element itself because elements inside shadowRoot is not accessible) 3. I have tried to copy paste my object (at least I have tried :D) let element = this.shadowRoot.getElementById(inputId); const dropdown = new Input(element); this.dispatchEvent(new CustomEvent('load', { detail: dropdown })) Same logic with different element this time I tried to get object. But not worked same error: What else I can try or do? How can I achieve this with Wix is there any way to do this? All I want to do is use the element for my object here is the object code: I need the html input element to get this work. export function Input(element) { this.element = element; Object.defineProperty(this, 'value', { get: function () { return this.element.value; }, set: function (value) { if (value === 0) { new Error('You cant set placeholder as a value! index 0 is placeholder') } this.element.value = value; } }); Object.defineProperty(this, 'selectedIndex', { get: function () { return this.element.selectedIndex; }, set: function (value) { if (value === 0) { throw new Error('You can set placeholder as a value! index 0 is placeholder') } else { this.element.options.selectedIndex = value; } } }); Object.defineProperty(this, 'required', { get: function () { if (this.element.required) { return this.element.required; } else { return false; } }, set: function (value) { if (typeof value != 'boolean') { throw new Error(`Value must be boolean!`) } return this.element.required = value; } }); Object.defineProperty(this, 'enabled', { get: function () { if (this.element.disabled) { return false; } else { return true; } } }); Object.defineProperty(this, 'placeholder', { get: function () { return this.element.options[0].label; }, set: function (value) { this.element.options[0].label = value; } }); Object.defineProperty(this, 'options', { get: function () { return Array.apply(null, this.element.options).map((option, index) => { if (index != 0) { return { label: option.label, value: option.value } } }).filter((element) => { return element !== undefined; }) }, set: async function (value) { if (typeof value != 'object' || value.length <= 0) { throw new Error(`It's not an array!`); } else { let errorCollector = 0; value.forEach((item) => { if (item.label) { // } else { errorCollector++ } if (item.value) { // } else { errorCollector++ } }) if (errorCollector > 0) { throw new Error(`You must include label and value in every object! You had problems in ${parseInt(errorCollector / 2 + 0.5)} of your objects!`) } else { //remove all options const optionsNode = element.shadowRoot.querySelectorAll('#testInput option'); optionsNode.forEach((option, index) => { if (option.value) { option.remove() } }); //add new options value.forEach((option) => { //@ts-ignore this.element.add(new Option(option.label, option.value)); }) } } } }); this.disable = function () { this.element.setAttribute("disabled", "disabled") } this.enable = function () { this.element.removeAttribute("disabled") } } Thanks!
I need to access HTML Element but how? content media
0
0
250
Enes
Velo Certified
Velo Certified
May 07, 2022
In Coding with Velo
In fact there are no errors but there is a big UX error for my users. What's happening: I have a router page which I use with a HTTP Function but error is all about it self (%99) and like I said it's not an error maybe it's a bug of Wix (maybe). When user went into router page first router shows to user forbidden message after few seconds router remove the forbidden message and redirect user to page and everything works. So why if everything already works why router shows a forbidden page?? router.js export async function download_product_Router(request) { //Getting all queries coming from HTTP response (301) const incomingMemberIp = request.query.memberIp; const incomingMemberId = request.query.memberId; const token = request.query.token; const productId = request.query.productId; if (incomingMemberIp === request.ip && incomingMemberId === request.user.id) { //Checking if the token is valid and for this user or not const isTokenValid = await checkToken(token, incomingMemberId, productId); //Gets product image const productImage = await findProductImage(isTokenValid.productId); if (isTokenValid.valid === true) { //Creating the data that we will send to frontend via router const routerData = { 'token': isTokenValid.token.encryptedToken, 'tokenId': isTokenValid.token._id, 'productImage': productImage, 'memberIp': incomingMemberIp, 'memberId': incomingMemberId, 'downloadUrl': request.url, 'env': request.env } //Redirect to the Download Product page with ok reponse return ok("Ürün İndirme", routerData); } else { return forbidden(); } } else { return forbidden(); } } Here is the video of what actually happening: As you can see in the router.js there are only two forbidden and after these forbidden response there is nothing. But somehow router changes it into 200 after forbidden and everything works like I said. But I don't want to see this 403 page. I don't think you need (because this should be a bug of Wix or any error should be related to router.js) but if you need my HTTP Function code let me know. (You can't try this live, this is a live system I can't do any changes on it) I'll be trying to fix this if I understand what was the reason and if I can fix it I'll post here.
Router Shows Forbidden Page and then Change it to OK 200 Response (maybe a BUG) content media
0
1
50
Enes
Velo Certified
Velo Certified
Apr 29, 2022
In Coding with Velo
Are there any API for this functionality: Making any data private or public for users with wix-members I couldn't find any API to achieve this functionality. If it's not available will it be in the future? -Btw bad translate for Turkish it says First Name Privacy Settings but First Name is still English lol
Wix Members Private and Public Data content media
0
0
17
Enes
Velo Certified
Velo Certified
Apr 24, 2022
In Tips, Tutorials, Examples
While I'm building something with HTTP-Endpoint I solved a problem that someone can spent their hours to solve it if they are not familiar with it (like me). If you are having a problem with your API (HTTP-Endpoint): Your code changes not taking any affect. You are getting same response even if you change the code. Or similar responses. Your problem may cause because of one missing header option: "Cache-Control": "no-cache" I was trying to build a file download system using AWS with my Wix site but my changes were not affecting to my API so I remembered that maybe it's caching the request and I was right it was caching the request. There are some request types that will be cached: 200 (OK) 301 (Moved Permanently) 404 (Not Found) 206 (Partial Content) What you should do to let browser not cache your request? You need to add a header option to your response and you need to clear your browser caches (cookies) to see changes. Example response: (using response HTTP API) return response({ status: 301, headers: { location: 'https://www.example.com/' 'Cache-Control': 'no-cache' } }) If you add this 'Cache-Control': 'no-cache' to your headers in your response browser will not cache your request again. Tip: Use Postman to check your API responses. (It's free) More about caching requests. More about Cache-Control If I wrote something wrong let me know :)
0
0
79
Enes
Velo Certified
Velo Certified
Apr 09, 2022
In Velo Pro Discussion
Can I create a router for homepage or can I create a general router to process all requests to my site.
0
1
59
Enes
Velo Certified
Velo Certified
Mar 17, 2022
In Coding with Velo
As you know we have events in some of APIs like "Wix-Stores" these events help us to handle something when something happened. Example: When someone buys a product from your store check if there is coupon code and if coupon code is equal to one of (X,Y,Z) these coupon codes give add some money to X affiliater "product price %5" in this way you can create an affiliate in Wix with Wix Stores. (I have done this like months ago it's working well :)) Using: onOrderPaid() event What I Want to do? I want to create my own custom events and I have found my answer for this already but I'm still searching if there is another way to do this. My answer to this is using data hooks. In most of the events (maybe all of them) there is a relation with a database (collection) and you can handle these events using data hooks. Data Hooks 101 We can use data hooks and we can use if else inside hooks so we can check for specific things. Example: To create a onNewOrder() event you could just use afterInsert data hook. So when a new item added to collection it will fire the event. You can add an if else and check for paid status so if new item paid status is "paid" you can just fire onOrderPaid() event. This is what I understand and found so far. I want to learn this is the best and only way to do this (in Wix with Velo) or is there other better or just other ways to do the same thing. And there is another question that I'm looking for an answer. Using Events with Frontend (Important part) Okay let say we have built an event and it's checking for changes of stock data of the products. What I want to do is I want to reload the data "change stock text" in live mode (shortly without reloading the page) so user can see how many product left in stock. And I'm still searching for an answer to this question. How can I fire a function in frontend using backend events? Shortly how can I update the text in the product page using this event???
0
9
349
Enes
Velo Certified
Velo Certified
Feb 27, 2022
In Coding with Velo
What is the difference between 'Stores/Orders' collection and 'Ecom/Orders' collection I didn't get it? What type of data this collection stores?
0
1
27
Enes
Velo Certified
Velo Certified
Feb 04, 2022
In Tips, Tutorials, Examples
In this tutorial I will try to explain how you can create a custom HTTP Endpoint (API) to receive your Wix site logs (both frontend and backend) and how you can create alerts to let you know when something is not working. So let's start creating our custom API using Google Cloud! What you will need to build this? Google Identity Account Google Cloud Account Any Wix Site You Have Jump to headings: Sign Up for Google Identity Cloud Setup Google Cloud Identity & Organization Creating App Engine Creating API And Deploy to App Engine Connecting Wix to Google Cloud Creating Alerts for Logs (Optional) Step 1 - Sign Up for Google Identity Cloud In the first step we need to create a Google Identity account and use one of the account that we will create inside our Google Identity account. *Note: You need a domain to create a Google Identity Account if you don't have a domain you can just use a regular Google account to use Google Cloud just skip to 3rd step. You can directly go to this URL to just create a Google Identity Account. We will start from here for who will create a Google Identity account. When you achieve "How you'll sign in step" at Google Identity sign up. Create a email with your domain and set a password for it. After completing other steps. Google will take to the sign in page: Sign in your account. After signing in your account Google will take you to Google Admin page. We will verify the domain that we have added while we are signing up. Go to your domain provider and manage your DNS settings in your DNS settings you will add a TXT record. This is how you can do it inside Wix if your domain is managed by Wix: Host Name will be empty if your domain provider not allow to leave it empty use @. Value will be the text we have copied from Google Identity account. And TTL will be 1 Hour which is default already. After completing DNS setup we can go back to Google Admin console. And click "Verify My Domain" button at the bottom. It can take sometime to verify your domain (avg 4-5min) just get a coffee while waiting this :) When Google verified your domain just go to Google Cloud: Now we can move to step 2. Step 2 - Setup Google Cloud Identity & Organization Now we have a different Google Account to use Google Cloud with Google Identity. And when you move to Google Cloud from Google Admin console you will see this screen: Just agree the terms and click AGGREE AND CONTINUE. You will see a pop-up at the bottom of the page: (It's mean now admin@exweiv.store is the admin of organization that we have created) Now time to setup Identity & Organization settings: First will be marked as completed we will continue from second step. In here you can read what Google tells you and understand all the steps (if you really need to understand these steps). In every step there will be tasks and you can complete these tasks by clicking fast complete buttons: In this step Google tells me to create groups inside my Google Admin console if you don't want to do it manually you can just click "Create and Customize Groups" button. When you have done all the steps you will see this result page: Now time to setup our App Engine so we can move to step 3. Step 3 - Creating App Engine So this is the step that who just wants to use a regular Google account and not to create a Google Identity account. Or if you already have completed these steps (creating Google Cloud account etc.) you can start from here. So let's start building our API but before that we need to understand how it will work. Here is a support article by Wix about what we will do in this step. We will use a GitHub repo to create our API (this GitHub repo is created by Wix). Here is the GitHub repo And here is the image that shows what we will be building *image from support article: In Google Cloud we will use App Engine to create a custom HTTP Endpoint and we will send logs of our Wix site to this HTTP Endpoint as a request (POST method). So let's start building it! Go to App Engine and create a new App in Google Cloud: You will have to fill some details about your app: I will select europe-west-6 because my website users is closer to this location. (It's better to choose nearest location to your users) Then we need to create a service: (Click to the dropdown and select "create new service") Choose a name and ID for your service: (You don't have to take action for other 2 optional step 2nd and 3rd step) Then select your service and create a new key: (In JSON format) After you have created a key in JSON format you will get a JSON file (auto download) into your local device. (We will use this JSON file so keep it) And don't forget to give Editor access to your service account to do this you need the email of service account. When you create your service account you will see an email at the details section: Copy this email and go to IAM page and add new user: Then save it. So we can go back to App Engine setup and just refresh the list and select your Service Account: It will take sometime to create your App Engine so be patient. After you have created your App Engine you will see a screen like this: What we have done so far? We have created an App Engine We have created a Service Account We have added Editor permission to our Service Account Now time to use this App Engine and create the API using GitHub repo provided by Wix. Open Cloud Shell by clicking the icon at the top of the menu: To be more comfortable I will open the Shell and Editor in new window: Select your project by typing: gcloud config set project `PROJECT ID` To find your project ID follow these steps: Click your project name at the top left corner just next to logo of Google Cloud You will see your project ID and Name: Time to move into step 4. Step 4 - Creating API And Deploy to App Engine In Cloud shell type these commands in order: git clone https://github.com/wix/corvid-stackdriver-telemetry-adapter.git Result: cd corvid-stackdriver-telemetry-adapter Result: Now we need to upload JSON file we have downloaded previously when we created the Service Account. After uploading the JSON file name it as 'service-account-key' First open the folder: Then drag and drop your JSON file: Rename your JSON file: Rename it as: 'serice-account-key' (without ''). We will also have edit app.yaml file. We will add service_account and service element to our app.yaml file and we will change runtime element to nodejs16: runtime: nodejs16 service_account: 'YOUR SERVICE ACCOUNT EMAIL' service: 'SERVICE NAME' How you can find your service name? Your service name is text before @ of your service email. Example: store-of-exweiv@deft-return-340304.iam.gserviceaccount.com Now we can continue from shell. npm i Result: npm run test Result: npm run deploy Result: type Y and press enter It will take 5-10 min to deploy your app to App Engine so just wait. Note: You can get an error about Cloud Build API if you get this error just Enable the API from this page: https://console.developers.google.com/apis/api/cloudbuild.googleapis.com/overview?project=deft-return-340304 (if you have more than one Google Account in your browser may you have to change account from top right) (To be able to use most of the features of Google Cloud you will need to create a Billing account also don't forget that) Shell Result (similar to this): Now we can go back to Google Cloud window and just move to the App Engine page of Google Cloud you will see a page something like this: If you see this page it's mean probably you have done it and just one thing left to do and it's connecting Wix to Google Cloud. We have a URL at the top right of our App Engine dashboard page my URL is: (you will have your own URL) https://deft-return-340304.oa.r.appspot.com To connect it to Wix we will add /log to end of the URL: https://deft-return-340304.oa.r.appspot.com/log Now we can move to last step (step 5) Step 5 - Connecting Wix to Google Cloud So time to connect our Wix site to this HTTP Endpoint to do this first we need to open our site dashboard and go to Developer Tools > Logs We will connect our HTTP Endpoint (API) using 'Advanced Connection' option in Logs page. Just paste your /log URL to here and you are ready to go! Congratulations you have created a custom API and you have connected it to your Wix site. So what's next? Let's check if everything is working correctly. To check if everything is working or not we need to use Logging Explorer inside Google Cloud: Now we need to send some logs (send requests) to our API to do this just open your website and log something to console I already have some errors :) so I can check it by just going into my homepage. IMPORTANT NOTE FOR LOGS: When you are writing your codes don't use console.log for every log. Use console.error() for error logs Use console.info() for info logs Use console.log() for regular logs Use console.warn() for warning logs Use console.error() for your promise errors (after .catch()) If you log an error with console.log you will not gonna see it as an error in logs. As you can see I can see my site logs by filtering resource type as global. Step 6 - Creating Alerts for Logs (Optional) If you want to be get alerted you can use log alerts. I will create a basic alert for all of my error logs to do this first go to Logging Explorer. First filter your logs. I want to create alert for all of my errors so I have filtered logs to see all errors. After that click 'Create Alert' button. First add name and doc for your error. Don't do any changes at step 2 and move to the step 3: Time between notifications: 1hr = you will get notified at every 1hr for this alert. Incident autoclose duration: Select a duration, after which the incident will close automatically when matching log entries are absent. I will select 5 min for time between notifications to get faster notifications. Now time to create notification channels: Go to manage notifications channels page and add details: (I will add an email) *Google has a mobile app so you can also get notified from your mobile device. After adding email: Now select notification channels you want for this alert: (then we can save alert) So we have created an alert. I will just create an error and I will get an email in 5 min here is the email that I got: We have just completed everything. ✅ If you see any error or missing details or any wrong thing in this tutorial just let me know so I can fix it :) I hope I was able to explain everything correctly.
Creating HTTP Endpoint For Logging (With Google Cloud) content media
2
1
231
Enes
Velo Certified
Velo Certified
Feb 02, 2022
In Velo Pro Discussion
It's first time I'm using Google Cloud and Google Cloud Operations but I can't understand why I can't create alerts. It's asking for permission but I can't set permission. I wanted to get alerted for errors but I could not understand how can I done it when I press `create alert` button at the Log Explorer page I see this permission errors. Any docs or something that can tell me how can I fix this?
Google Cloud Operations with Wix content media
0
25
91
Enes
Velo Certified
Velo Certified
Jan 23, 2022
In Coding with Velo
I don't know if this is a bug because it's shouldn't be like that at least this is what I think! Here is the code! export async function checkIfProductDownloadable(orderId) { const options = { suppressAuth: true }; return wixData.query("Stores/Orders") .eq("_id", orderId) .find(options) .then((requiredOrderData) => { const requiredOrder = requiredOrderData.items; if (requiredOrder.length > 0) { const now = new Date().getTime(); const orderDate = requiredOrder[0]._dateCreated.getTime(); const difference = now - orderDate; const oneYear = 31556952000; if (difference > oneYear) { return 403; } else { return 200; } } }) .catch((err) => { console.error(err); }) } In here I'm checking if users order in the last one year or not. And I'm returning 200 (OK) or 403 (Forbidden) as a result for my Router page. I'm using this backend function in a router.js to check orderId. What I found is if orderId is undefined it returns 200 (I tested in live mode and also in backend preview test) and .eq should not work like that I don't know if it's useful in different cases but this is what I think. Is this a BUG or .eq just works like that?
0
4
35
Enes
Velo Certified
Velo Certified
Jan 22, 2022
In Velo Pro Discussion
I haven't work with Wix Router yet. I was checking Wix Router APIs to understand what does do Wix Router and can I use it for my use case? What I want to do: I wan to create a advanced digital product download system to keep files secure and create custom tokens to download products. What I have planned generally: After clicking download button on the 'my downloads' page. (Member Page) A new tab will open and this will be the router page. I will handle the request to check if this user can download this products (security checks...) Then I will redirect user to download page which will be using limited time tokens. I hope I was able to explain what I want to do. My questions about this is very simple if you guys have used Router or if you know what is it. My Questions: Is Router right thing to do this or is there any better way to do it? I don't want to hurt my website SEO generally so how can I done it while using router. How can I tell Google to ignore these all router pages? When I was checking APIs I saw ok() to send 200 response with some data. In here I created something like that is that correct way to let Google or other search engines ignore my router pages? My Router Code To NOT Index Page: export function product_download_Router(request, response) { let data = { "data1": "test" } let header = { "noIndex": true } return ok("productDownload-page", data, header) } API that I checked
0
1
49
Enes
Velo Certified
Velo Certified
Jan 22, 2022
In Coding with Velo
I don't know if this is a specific but I have an underlined text which Wix says error for it but it's actually working and I knew there shouldn't be any error. If Wix can fix this (fix: don't show this as an error) Tested, this function works without any problem (in preview, or live site)
Wix says error but I say not xd content media
0
0
17
Enes
Velo Certified
Velo Certified
Jan 21, 2022
In Coding with Velo
We can't use Stripe tests cards to test our orders I created something for my store and I need to pay real money to test it every single time. I just paid 10€ to test my code until it works without problem. Please we need to be able to use test cards. (I'm using Stripe but I'm talking for every single payment provider)!!!
2
2
37
Enes
Velo Certified
Velo Certified
Jan 15, 2022
In Coding with Velo
I want to create a dynamic reviews repeater showing latest member data on the repeater. Because of that I'm not collection user info when they insert review I'm using _owner and trying to get member data with getMember in the backend using _owner. But when I try this with a logged in account or a visitor user. I'm seeing an error with a permission error and I don't know how can I bypass it? Or how can I fix this issue to create dynamic reviews repeater. I also tried to login with a admin account and there was no problem. I can get the member data for each review. Shortly: This is my backend getMember function: export function getMember(memberId) { return wixMembersBackend.members.getMember(memberId, { fieldsets: ['FULL'] }) .then((memberData) => { return memberData; }) .catch((err) => { console.error(err) }) } This is my backend code to create dynamic repeater data: export function getProductReview(productId, skip) { return wixData.query("ProductReviews") .limit(10) .skip(skip) .eq("productId", productId) .find() .then((productReviewsData) => { let productReviews = productReviewsData.items; if (productReviews.length > 0) { productReviews = productReviews.map(async (review) => { let memberData = await getMember("c9e73b46-85a9-48ba-8a66-5595b82f5893") .then((memberData) => { let profilePhoto = memberData.profile.profilePhoto; let memberName = `${memberData.contactDetails.firstName} ${memberData.contactDetails.lastName}` if (profilePhoto) { return { "profilePhoto": profilePhoto.url, "memberName": memberName } } else { return { "profilePhoto": undefined, "memberName": memberName } } }) return { "_id": review._id, "reviewTitle": review.reviewTitle, "review": review.review, "rating": review.rating, "memberName": memberData.memberName, "memberProfilePhoto": memberData.profilePhoto } }) const result = Promise.all(productReviews); return result; } }) .catch((err) => { console.error(err); }) } When I use admin account I'm getting every single data without any problem. But when I try with an non-admin account I can't get first and last name of user but I can get profile photo. How can I fix this permission issue?
0
2
76
Enes
Velo Certified
Velo Certified
Jan 12, 2022
In Tips, Tutorials, Examples
I'm recommending Tabnine plugin to all of you a AI auto complete for your codes. After I wrote more than 5000 lines with Tabnine it's auto completing almost half of my codes. What about Velo? If you are coding Velo in VSCode like me this is very useful because for now we don't have any integration or any plugin directly for Velo in VSCode or other IDEs (there is one but it's a bit old and just autocomplete something) so this plugin would help to autocomplete a lot of thing for you codes. Examples: I was able to create all onReady with one `tab` click. Another one for repeater callback (onItemReady) again just one `tab` click. As you write it will be much better. (This plugin is not for Velo it's general but because of we don't have any autocomplete thing for Velo inside VSCode it's beign very useful for Velo syntaxes) Some stats: For who need help about installing this: To install it in VSCode you can search for Tabnine in plugins tab (left side). And yes it's free. (I'm also using free version) And one more plugin for directly Velo is here: (Auto complete imports and $w('') I'm also using this)
Autocomplete for Velo in VSCode content media
3
1
214
Enes
Velo Certified
Velo Certified
Jan 07, 2022
In Coding with Velo
I have created a backend function which returns an array. In the front-end I call this function and pass array (with JSON stringify) to the custom element using setAttribute API. In the custom element I parse incoming array and create custom components with it. Problem is how could I await incoming attribute because custom element is not waiting it just checking attribute and gets null. And it's not working just because of this I added timeout and tested what would happen it would wait and it's working when it's able to get data from front-end. How can I make async await system between frontend and custom element? Here is the codes: Front-end: import { stateChanger } from 'public/Utilities/Utilities.js' import { getAvailableProducts } from 'backend/Support/Custom-Setup-System/data.jsw' $w.onReady(function () { getAvailableProducts() .then((results) => { console.log(results) $w("#productSelectorElement").setAttribute("data", JSON.stringify(results)) $w("#productSelectorElement").on('onClick', event => { console.log(event.detail) }); }) }); Custom Element: const createStyle = () => { let style = document.createElement('style'); style.innerHTML = ` p { color: white; font-family: Poppins; font-size: 16px; padding: 0; margin: 0; cursor: pointer; } h4 { color: white; font-family: Poppins; font-weight: 500; font-size: 20px; margin: 0; padding: 0; } .grid { width: var(--customElementWidth); display: grid; grid-template-columns: repeat(5, minmax(150px, auto)); grid-auto-rows: minmax(170px, auto); justify-content: center; align-items: center; grid-gap: 20px; } .container { --state: none; --opacity: 0; width: 150px; height: 170px; display: grid; justify-content: center; align-items: center; grid-template-columns: repeat(2, 1fr); border: none; border-radius: 15px; background-color: white; transition: 0.3s ease-in-out; cursor: pointer; } .content { height: 130px; display: var(--state); grid-template-rows: 1fr 1fr; grid-gap: 5px; margin-left: -50px; margin-right: 20px; justify-content: start; align-items: center; animation: opacity 0.4s ease-in; } .image { display: grid; justify-content: start; align-items: center; } .image img { object-fit: cover; height: 130px; width: 110px; border-radius: 15px; margin-left: 20px; } .container:hover { background-color: green; width: 400px; --state: grid; cursor: pointer; } .title { align-self: end; } .text { margin-top: 4px; align-self: start; } @keyframes opacity { from { opacity: 0; display: none; } to { opacity: 1; display: grid; } } ` return style; } let innerHtml = (idIdentity) => { let html = ` <div class="image"> <img id="image${idIdentity}" src="./normal-gölgesiz.png" alt=""> </div> <div class="content"> <h4 class="title" id="title${idIdentity}">Yayıncı Paketi</h4> <p class="text" id="text${idIdentity}">Seçmek İçin Tıklayın</p> </div> ` return html; } const createGrid = () => { const grid = document.createElement('div') grid.className = "grid"; return grid; } const createProductTab = (item, idIdentity) => { const productTab = document.createElement('div'); productTab.className = "container"; productTab.id = `container${idIdentity}`; productTab.innerHTML = innerHtml(idIdentity); let hoverColor; if (item.isSelectable === true) { hoverColor = "#008765" } else { hoverColor = "#E03131" } productTab.addEventListener('mouseover', () => { productTab.style = `background-color: ${hoverColor}` }) productTab.addEventListener('mouseout', () => { productTab.style = "background-color: white" }) productTab.querySelector(`#image${idIdentity}`).src = item.productImage; productTab.querySelector(`#title${idIdentity}`).innerText = item.productTitle; productTab.querySelector(`#text${idIdentity}`).innerText = item.reasonText; return productTab; } class ProductTab extends HTMLElement { constructor() { super(); this.showInfo = true; this.attachShadow({ mode: 'open' }); this.shadowRoot.appendChild(createStyle()); this.shadowRoot.appendChild(createGrid()) } async getData() { return await JSON.parse(this.getAttribute("data")) } async setupProductTab() { let main = this; let data = await this.getData() data.forEach((item, index) => { this.shadowRoot.querySelector('.grid').appendChild(createProductTab(item, index)) this.shadowRoot.querySelector(`#container${index}`).addEventListener('click', event => { main.dispatchEvent(new CustomEvent('onClick', { detail: item })); }) }) } async connectedCallback() { console.info("Connected") this.setupProductTab() } disconnectedCallback() { console.error("Disconnected!") } } window.customElements.define('product-tab', ProductTab); I even tried to use while and for loop even like a noob I tried setInterval non of them worked xd. Any answer?
0
1
212
Enes
Velo Certified
Velo Certified
Jan 04, 2022
In Coding with Velo
In Wix I think we can't update or overwrite our eventlisteners like onClick what can I do about this issue? Example: $w("#Button123").onClick((event) => { runFunction() }) $w("#Button123").onClick((event) => { runFunction() }) If I write this code runFunction will be fired 2x times. This is the issue that I'm having. Also even if I have different functions like: $w("#Button123").onClick((event) => { runFunction() }) $w("#Button123").onClick((event) => { runFunctionTwo() }) Again both will fired. Another example: function setup() { $w("#Button123").onClick((event) => { console.log(123) }) } setup() function updateItems() { setup() } updateItems() In this exmaple I would see 2x console.log(123) even if I click once. Because updateItems function created the same eventlistener once again! This is the issue I hope I was able to let you understand what I meant. So? How can I overwrite or basically update my eventlistener and not create new one each time? Wix must make an update about this and let eventlisteners overwrite automatically. How it should be example: $w("#Button123").onClick((event) => { runFunction() }) $w("#Button123").onClick((event) => { runFunctionTwo() }) Only runFunctionTwo will be executed. Each time we create new eventListener it should overwrite old one. -Maybe Wix can create a new selector like $o and we can use it when we want to overwrite. (I'm not a master so maybe I'm thinking false but this is my idea because I'm having problem with this)
1
2
55
Enes
Velo Certified
Velo Certified
Dec 23, 2021
In Coding with Velo
Is this error happening because of my code or because of anything else because I can't understand why I see this error?
Wix-Pay Console Error content media
0
6
43
Enes
Velo Certified
Velo Certified
Dec 19, 2021
In Coding with Velo
I'm just trying to pull a very simple url with Wix Media Backend API (getFileUrl) but it doesn't work like I want. I can't pass incoming URL into object it just pass undefined. I also console.log incoming URL and I can see there is URL it's working but it doesn't pass this URL into object here is the backend code. Just spent 6 hours for this very stupid thing and still can't understand why it's not working. All I want to do is create my own Orders page but it's being impossible to create because nothing is working like I want. getFileUrl - Velo API Reference - Wix.com Here is the backend code: (I made the problem code black and bold) import wixData from 'wix-data' import { mediaManager } from 'wix-media-backend'; export async function getOrders(memberId) { let options = { "suppressAuth": true, }; return wixData.query("Stores/Orders") .eq("buyerInfo.id", memberId) .find(options) .then((orders) => { if (orders.items.length > 0) { let orderData = orders.items; return wixData.query("Products") .include("productId") .find(options) .then((products) => { if (products.items.length > 0) { let productsData = products.items; return orderData.map((order, index) => { let orderData = { "_id": order._id, "formattedAddress": order.billingInfo.address.formatted, "paymentMethod": order.billingInfo.paymentMethod, "memberEmail": order.buyerInfo.email, "memberLastName": order.buyerInfo.lastName, "memberFirstName": order.buyerInfo.firstName, "memberId": order.buyerInfo.id, "memberPhone": order.buyerInfo.phone, "orderDate": order._dateCreated, "orderNo": order.number, "lineItems": [], "paymentStatus": order.paymentStatus, "totals": order.totals } orderData.lineItems = order.lineItems.map((lineItemData) => { let lineItem = { "productDownload": undefined, "productName": lineItemData.name, "productQuantity": lineItemData.quantity, "productSku": lineItemData.sku, "tax": lineItemData.tax, "productPrice": lineItemData.priceData.price, "totalPrice": lineItemData.priceData.totalPrice, "options": lineItemData.options, "customTextFields": lineItemData.customTextFields, "productImage": lineItemData.mediaItem.id, "discount": lineItemData.discount } productsData.forEach((product) => { if (product.productId._id === lineItemData.productId) { let now = new Date(); let gap = now.getTime() - order._dateCreated.getTime(); if (product.productId._id === lineItemData.productId && gap < 31556952000) { if (product.productDownload) { let start = product.productDownload.search("archives/") + 9; let end = product.productDownload.search(".zip") + 4; let fileName = product.productDownload.slice(start, end) lineItem.productDownload = mediaManager.getFileUrl(fileName); } } } }) return lineItem }) return orderData; }) } }) } }) .catch((err) => { console.error(err) }) } As you can see there is no problem when I test it I'm getting all data except downloadUrl (I tried passing data after .then also not working I tried everything) please someone tell me why this API not working like I want it's not passing the data here is test results: result is Empty object for URL BUT BUT BUT Here is the console log for url and it's actually exist but didn't pass the url inside. Result is coming first console log
Problem With Backend content media
0
2
36

Enes

Velo Certified
+4
More actions
bottom of page