Unable to get order id on bigcommerce store confirmation page - handlebars.js

I am trying to get order id on confirmation page of big-commerce store after placing an order according to the following code:
fetch('/api/storefront/order/{{checkout.order.id}}', {credentials: 'include'})
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(myJson);
});
But I am getting the following error:
{title: 'Not Found', type: 'about:blank', status: 404, detail: "Provided order Id doesn't represent a valid order"}

That code looks correct to me. In what file have you placed the code? It should be in order-confirmation.html

Related

Handle 422 with $fetch

I'm upgrading a project to Nuxt3 and I'm using the new $fetch to hit my API, all it's OK but I can't manage the handle the 422 error from the API.
The API I've created would return something like this for the 422 code
{ message: "The email has already been taken.", errors: { email: ["The email has already been taken."]}}
Then in Nuxt I'm using this:
$fetch(`${runtimeConfig.public.BASE_API_BROWSER_URL}/XXX/`, {
method: 'POST',
body: {
...data
}
})
.then((resp) => {
message.value.push(resp.message)
isSubmitting.value = false
})
.catch((error) => {
errors.value.push(error.message)
isSubmitting.value = false
})
But what I have back is just FetchError: 422 Unprocessable Content instead of the error inside the API response, any idea on how to able to use error.message again?
Should be typically accessible via error.response.message.
For better visibility of the error object structure, use console.dir to explore its contents in the browser console: console.dir(error)
Unlike console.log(var1, var2, var3), console.dir only handles one attribute.
Important to remember this else you will be misled to thinking variables are empty.

Set or Add in Firebase which I need to use for creating a new Database entry?

I want to save User's name in a Database of Firebase called profiles
While I am using the below code it is not creating any entry in my database:
register() {
fb.auth().createUserWithEmailAndPassword(this.email, this.password)
.then((user)=>{
db.collection('profiles').doc(user.user.uid).set({
name: this.profile.name
})
}
I have a profile object. So, it is not a problem.
If I use add like the below, it is creating entry.
db.collection('profiles').add({
name: this.profile.name
})
But Problem is while I am trying to retrieve it's ID, it is not giving me the correct result.
db.collection("profiles").doc(user.uid).update({
name: this.profile.name,
mobile: this.profile.mobile,
postcode: this.profile.postcode
});
uid is not matching.
ERROR:
[Vue warn]: Error in v-on handler: "FirebaseError: [code=invalid-argument]: Function DocumentReference.update() called with invalid data. Unsupported field value: undefined (found in field name)"

Can I merge data when sending put request to firebase realtime database using axios?

I am able to update my data in Firebase Realtime Database using axios like this:
axios.put('/blogposts/' + postId + '.json', post, {headers: {'Content-Type': 'application/json'}}).then(response => {
res.status(200).send(json.stringify(response.data));
}).catch(err => {
res.status(500).send('error putting blog post.');
});
But the post being put looks like this:
{
title: '...',
body: '...'
}
and the posts in the database look like this:
{
title: '...',
body: '...',
createdAt: 123,
updatedAt: 123
}
Before putting the post, I give it an updatedAt stamp:
post.updatedAt = Date.now();
Then I put the post using the axios call above.
In the database, the post ends up looking like this:
{
title: '...',
body: '...',
updatedAt: 123
}
createdAt has disappeared.
I'm wondering if there's a config setting that tells Firebase not to overwrite the whole post, but each field one by one, so that title gets overwritten, body gets overwritten, updatedAt gets overwritten, but createdAt is left alone. I believe this is called a merge, but adding merge:true to the config object doesn't do what I want.
Is there a way to do what I want, or does the updated object always have to include each and every field of the old object even if the field isn't being updated?
Thanks.
To merge the data you write with the existing data at the location in a REST request, use the PATCH verb. From there comes this example:
curl -X PATCH -d '{
"nickname": "Alan The Machine"
}' 'https://docs-examples.firebaseio.com/rest/saving-data/users/alanisawesome.json'
In Axios that seems to translate to axios.patch(...).

Meteor audit-argument-checks

I have a Meteor project where I'm using audit-argument-check. I'm getting an error message
Error: Did not check() all arguments during publisher 'document
I'm know this is related the audit-argument-check not being able to check all arguments. But as far as I'm concerned, I checked all of them. Concrete, I have defined a collection 'documents' and attached a SimpleSchema. As part of iron-router, I have the following:
Router.route('customerDocumentShow', {
template: 'customerDocumentShow',
path: 'customer/documents/:_id',
waitOn: function () {
return Meteor.subscribe('document', this.params._id);
},
data: function () {
return Documents.findOne(this.params._id);
}
});
So I'm passing only the documentId (this.params._id). On the server, I have defined a method:
Meteor.methods({
documentsReadMethod: function(documentId){
check(documentId, String);
var documentItem = Document.findOne(argument);
if (!documentItem) {
throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.');
}
return documentItem;
}
});
So I'm checking to documentId in the server method. So not sure why I'm getting this error message.
Note: One thing I'm not entirely sure about though is how I need to call this method (right now, it's documentsReadMethod_. I'm not explicitly calling (on the client):
Meteor.call(documentsReadMethod, this.params_id);
as I'm using autoform, collection2 and simpleschema. I've been spending the entire weekend, but have no clue. Any idea's ?
Note: the code is on github: https://github.com/wymedia/meteor-starter-base
The problem is in the publish. You didn't check the id here:
https://github.com/wymedia/meteor-starter-base/blob/master/server/publications/documents.js#L16
Just add check(id, String); line 16 and it should work.
I have the same problem with another tuto !
Answer found at check is not defined in meteor.js : since Meteor v1.2, you have to add this package:
$ meteor add check

Meteor getting this.params._id undefined

UPDATE: I got the issue fixed, it was due to my Meteor Publish setting I had to change it to return Links.find(); and then filter the correct data in my links list return Links.find({topicId: this._id}, {sort:{submitted: -1}});
So I'm getting some very weird issue and I'm really stuck.
I have the following route setup
this.route('linkEdit', {
path: '/link/:_id/edit',
data: function() {
console.log(this.params);
console.log(this.params._id);
console.log(Links.findOne(this.params._id));
return Links.findOne(this.params._id)
}
});
So this.params is fine I'm getting - [_id: "LiAiifzPHmMR23tg3", hash: undefined]
For this.params._id - I'm getting the correct ID, LiAiifzPHmMR23tg3
But for Links.findOne(this.params._id) - I'm getting undefined
However when I check mongodb I have a link with that ID.
Also if I add an alert, while the alert is popping up the template renders the data but then re-renders and I'm getting blank data as it can't find the correct link ID.
That's because your collection query is a bit off, you'll want to change that to the following:
Links.findOne({_id: this.params._id});

Resources