how to create extra field when capturing checkout in commerce js - javascript

i am using commerce js on my website and i want to create an extra field for getting phone number from user but commerce js does'nt have any documentation about extra_field. can any one tell me how to add it
i also created extra field in commerce js dashboard
here is my order data object
const orderData = {
line_items: checkoutToken.line_items,
customer: {
firstname: shippingData.firstName,
lastname: shippingData.lastName,
email: shippingData.email,
},
shipping: {
name: "International",
street: shippingData.address1,
town_city: shippingData.city,
county_state: shippingData.shippingSubdivision,
postal_zip_code: shippingData.zip,
country: shippingData.shippingCountry,
},
fulfillment: { shipping_method: shippingData.shippingOption },
payment: {
gateway: "stripe",
stripe: {
payment_method_id: paymentMethod.id,
},
},
extra_fields: {
contact: shippingData.contact,//its not working
}
};

When capturing the order, provide the extra_fields object with each extra field ID as the key and the value you want to use.
extra_fields: { [extraFieldId]: 'your custom field value' }
from https://commercejs.com/docs/api/?shell#capture-order

Related

Embedded Schema Inserting Blank in Meteor using Collection2

I am fairly new to meteor and attempting to insert to a collection using a model that uses embedded schemas. The content in the embedded schema is not being inserted into the db and is instead an empty entry.
The main model is being attached to the collection.
Guests = new Mongo.Collection('guests');
Schema = {}
Guests.attachSchema(new SimpleSchema({
BasicInformation : {
type: Schema.basicInfo,
optional: false,
},
})
The basicInfo schema is defined as follows.
Schema.basicInfo = new SimpleSchema({
firstName: {
type: String,
},
middleName: {
type: String,
},
lastName: {
type: String,
}
})
I am using this to insert in the collection on a common js file.
Guests.insert({
BasicInformation: {
firstName: 'First Name',
middleName: 'Middle Name',
lastName: 'Last Name'
},
})
If I remove the schema and add the fields in the main model instead of using an embedded schema, then it does get inserted. Not sure what’s up…help!
Welcome to Stack Overflow. And, as #Jankapunkt says, please put your code as formatted blocks in your question. Links to pictures hosted elsewhere may not work if the images get deleted. It's also easier for us to fix your code and show you what it should look like.
I think at the time you set up your schema, the Schema Object is empty. You add info to it later, but it's too late at that point. If you put the code in your question I can show you how, but I'm not willing to retype it for you.
UPDATE:
Good work. You need to populate the Schema object before you attach it to the table:
Guests = new Mongo.Collection('guests');
Schema = {} // Right now the object is empty
Schema.basicInfo = new SimpleSchema({ // So we add the sub-schema
firstName: {
type: String,
},
middleName: {
type: String,
},
lastName: {
type: String,
}
})
Guests.attachSchema(new SimpleSchema({
BasicInformation : {
type: Schema.basicInfo, // previously this was undef, now it is correct
optional: false,
},
})
That should work for you.

How to pass the data with dynamic key in semantic UI vue dropdown?

I am facing an issue with semantic-ui-vue dropdown.
Here is my sandbox link: https://codesandbox.io/s/3qknm52pm5.
In my sandbox, I have two dropdowns: From and To.
From shows the correct values and To doesn't due to key mismatch.
My App.vue contain this script
<script>
export default {
data() {
return {
from: [],
to: [],
fromCollection: [
{
value: "abc#gmail.com",
text: "abc#gmail.com"
},
{
value: "def#gmail.com",
text: "def#gmail.com"
},
{
value: "qwerty#gmail.com",
text: "qwerty#gmail.com"
},
{
value: "shubham#gmail.com",
text: "shubham#gmail.com"
}
],
toCollection: [
{
email: "abc#gmail.com"
},
{
email: "def#gmail.com"
},
{
email: "qwerty#gmail.com"
},
{
email: "shubham#gmail.com"
}
]
};
}
};
</script>
and the component I used for both of them are
<sui-dropdown
fluid
multiple
:options="fromCollection"
placeholder="from"
selection
v-model="from"
search
:allowAdditions="true"
text="email"
/>
<sui-dropdown
fluid
multiple
:options="toCollection"
placeholder="from"
selection
v-model="to"
search
:allowAdditions="true"
text="email"
/>
The 1st dropdown shows the correct values because I have passed the data from fromCollection whereas the 2nd dropdown doesn't show any text because I have passed the data from toCollection which has different key names.
Can someone help me to pass the data with dynamic keys like toCollection?
I couldn't find anything related in the documentation.
Can someone help?
there is no way to define field name for dropdown
only use computed to regenerate new array for it
demo

How to send mandrill emails to array of emails?

I'm building an app in Node and I'm using mandrill to send emails every time there is a new user to a predefined array of emails. I have an array of emails:
And I have this function where
newUserEmail(user_name, email) {
emailArray = [example1#ex.com, example2#ex.com, example3#ex.com]
const message = {
html: '<p>Name: *|NAME|* <br> Email: *|EMAIL|*</p>',
text: 'Name: *|NAME|*, Email: *|EMAIL|*',
subject: 'New person arrived',
from_email: 'newperson#example.com',
from_name: 'New',
to: [{
email: emailArray,
type: 'to'
}],
merge: true,
merge_vars: [{
rcpt: emailArray,
vars: [{
name: 'NAME',
content: user_name
}, {
email: 'EMAIL',
content: email
}]
}]
};
mandrill_client.messages.send({ message }, function(result) {
console.log(result);
}, function(e) {
console.log(`A mandrill error occurred: ${e.name} - ${e.message}`);
});
}
I get this on my console:
[ { email: 'Array',
status: 'invalid',
_id: '...',
reject_reason: null } ]
If I set only one email, it gets sent without problems.
Do I need to make a loop and run this function as many times as there are emails in the array? I hoped mandrill would recognise emails in the array :(
From what I gathered after a look at the documentation it looks like each object in the "to" array is an individual email address.
I would not run the function for each email address. Just map over the email array.
For example:
const formattedArray = emailArray.map(email => ({ email, type: 'to' }));
// if you're not a fan of arrow functions
const formattedArray = emailArray.map(function(email) {
return { email, type: 'to' };
});
Then in the mandrill message you can just set "to" equal to the formattedArray
to: formattedArray

Insert data in collection at Meteor's startup

I would like to insert data at Meteor's startup. (And after from a JSON file)
At startup, I create a new account and I would like to insert data and link it to this account once this one created.
This is the code that creates the new account at startup:
if(!Meteor.users.findOne({emails: { $elemMatch: { address: "test#test.com"}}})){
var id = Accounts.createUser({ email: "test#test.com", password: "1234", profile: { name: 'Test' } });
Meteor.users.update({_id: id }, { $set: { admin: false }});
}
And after that, I need to insert data and link it to this account with its ID. (In different collections).
So I tried to do something like that, but obviously It didn't work:
UserData = new Mongo.Collection('user_data');
if(!Meteor.users.findOne({emails: { $elemMatch: { address: "test#test.com"}}})){
var id = Accounts.createUser({ email: "test#test.com", password: "1234", profile: { name: 'Test' } });
Meteor.users.update({_id: id }, { $set: { admin: false }});
UserData.insert({
createdBy: id,
firstname: "test",
/* ... */
});
}
EDIT
Sorry for not have been clear.
The real issue is the :
UserData = new Mongo.Collection('user_data');
declaration is in another file, so I can't do like above.
As it's not in the same file, I tried to get the userId that got "test#test.com" as the email (the account's email created at startup). And once I got it, I want to use it in "createdBy: ID_HERE".
Ok, you'll want to check out Structuring your application. You'll have to make the file with the definition load earlier, or the one with the fixture later.
Normally you have your collections inside lib/ and your fixtures inside server/fixtures.js.
So if you put your insert code into server/fixtures.js it'll work.

How to get result with specific fields in StrongLoop?

I am currently using StrongLoop as my API backend server and Mongodb as data storage engine.
Let's say there is a collection called article. It has two fields title, and content. And there are two frontend pages to display a list of articles and view a single article.
Obviously the data list page only need title field and the view page need both. Currently the GET method of StrongLoop API return all fields including content. It cost extra traffic. Is there any way that can just return specific field?
Mongodb support projection in find() method for this. How can I do the same thing by StrongLoop?
Have you taken a look at the filters offered. http://docs.strongloop.com/display/LB/Querying+models
Query for NodeAPI:
server.models.Student.findOne({where: {RFID: id},fields: {id: true,schoolId: true,classId: true}}, function (err, data) {
if (err)
callback(err);
else {
callback();
}
})
Query for RestAPI :
$http.get('http://localhost:3000/api/services?filter[fields][id]=true&filter[fields][make]=true&filter[fields][model]=true')
.then(function (response) {
}, function (error) {
});
You can use fields projections,
Sample Record:
{ name: 'Something', title: 'mr', description: 'some desc', patient: { name: 'Asvf', age: 20, address: { street: 1 }}}
First Level Projection:
model.find({ fields: { name: 1, description: 1, title: 0 } })
and I think Strong loop is not yet supporting for second-level object filter, does anyone know how to filter second-level object properties or is yet to implement?.
Second Level Projection: (Need help here)
Ex: 2
model.find({ fields: { name: 1, 'patient.name': 1, 'patient.age': 1, 'patient.address': 0 } })
// Which results { name } only

Categories