Shopify buy js sdk addLineItems null - shopify

Im using shopify buy sdk to create checkout
I tried bellow
const lineItemsToAdd = [
variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==',
quantity: 1
}
];
const shippingAddress = {
address1: self.selectedAddress.address1,
address2: self.selectedAddress.address2,
city: self.selectedAddress.city,
company: null,
country: self.selectedAddress.country.country_language.name,
firstName: 'Bob',
lastName: 'Norman',
phone: self.selectedAddress.phone,
province: self.selectedAddress.state.state_language.name,
zip: '11001'
};
await client.checkout.updateShippingAddress(checkoutData.id, shippingAddress);
let mainCheckoutId = await client.checkout.addLineItems(checkoutData.id, lineItemsToAdd);
Address works find but cannot add product to line items, it return null as bellow
mainCheckoutId.lineItems = null
Also erro msg
userErrors retuns message ="Variant is invalid";
I tried many products and all are published to online sale channel
And also im sure that variant id is correct

I don't know if you fixed your issue, but it looks like you are missing a brace in lineItemsToAdd :
const lineItemsToAdd = [{variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', quantity: 1}];

Related

Prestashop JS script tracking confirmation order page

I have a problem.
I need to deploy a tracking script for a partner to track orders. He sent me this:
<script>
var dcData = {
event: 'sel',
clear: 1,
price: '<price>',
cdata: {
orderNumber: '<ordernumber>',
email: '<email>',
},
}
digitalCircle('event', dcData);
</script>
It doesn't work after putting it in the confirm page.
Hello,
I have a problem.
I need to deploy a tracking script for a partner to track orders. He sent me this:
var dcData = {
event: 'sel',
clear: 1,
price: '',
cdata: {
orderNumber: '',
email: '',
},
}
digitalCircle('event', dcData);
It doesn't work after putting it in the confirm page.

Prisma how can I update only some of the models fields in update()

I have a Prisma model with lets say 10 fields.
Think User model with firstname, lastname, address, e-mail , phone, mobile, age etc.
I am trying to write a update method for this, where I most of the times only want to update some or only 1 of the fields. Not the whole User. If the field is not sent with the request, I want to keep the value from the db.
What would the best practice be for this. Should I check for all fields to be in the req object?
How could I write this for prisma?
Example on how I would like it to work:
req = {firstname: 'Bob', email: 'bob#bob.bob', etc}
const updateUser = await prisma.user.update({
where: {
email: 'viola#prisma.io',
},
data: {
req.firstname ? (email: req.firstname) : null,
req.email ? (email: req.email) : null,
req.address? (email: req.address) : null,
},
})
Or should I check for values to be present in req and build the data object in 10 versions:
let customDataObject = {}
if (req.firstname) {
customDataObject.firstname = req.firstname
}
if (req.email) {
customDataObject.email= req.email
}
const updateUser = await prisma.user.update({
where: {
email: 'viola#prisma.io',
},
data: customDataObject,
})
The undefined property is used in Prisma to do exactly what you're trying to achieve. Basically, when a field is assigned undefined it means ignore this and do nothing for this field. You can learn more about this in the article about null and undefined in the docs.
This is what your update query should look like.
// assuming email, firstname and address fields exist in your prisma schema.
const updateUser = await prisma.user.update({
where: {
email: 'viola#prisma.io',
},
data: {
firstname: req.firstname || undefined, // if req.firstname is falsy, then return undefined, otherwise return it's value.
email: req.email || undefined,
address: req.address || undefined
},
})

storing qr code in google pay(google wallet)

Is it possible to store information such as QR code in google pay just like apple wallet ? if not is there any alternative ,I have researched certain apps and haven't got any relevant resource yet
Yes, it is possible. Many different types of passes support a Barcode property where type is QR_CODE.
Here is an example on how to set it:
const loyaltyObject = {
id: getLoyaltyId(email),
classId: `${issuerId}.${loyaltyProgram}`,
accountId: email,
accountName: name,
state: 'active',
loyaltyPoints: {
balance: {
int: points,
},
label: 'Points',
},
barcode: {
type: 'qrCode',
value: email,
},
};

Using nested include on an array

I am trying to verify that an array has 2 elements with the following values:
expect([{
createdAt: 1545588925941,
updatedAt: 1545588925941,
id: '5c1fd0bdd38b1b2bb0875dd9',
readAt: null,
type: 'ResidentCreatedTask',
dataVersion: 0,
data: '{}',
user: '5c1fd0bdd38b1b2bb0875dd6',
home: '5c1fd0bdd38b1b2bb0875dd8'
},
{
createdAt: 1545588925941,
updatedAt: 1545588925941,
id: '5c1fd0bdd38b1b2bb0875dd9',
readAt: null,
type: 'ResidentCreatedTask',
dataVersion: 0,
data: '{}',
user: '5c1fd0bdd38b1b2bb0875dd6',
home: '5c1fd0bdd38b1b2bb0875dd8'
}
]).to.be.an('array').that.has.lengthOf(2).and.to.deep.nested.include({
0: {
type: 'ResidentCreatedTask'
},
1: {
type: 'ResidentCreatedTask'
},
});
But it's not working. I also tried changing the keys to strings with brackets like '[0]' and '[1]'.
I also tried removing the keys and making the val of includes an array like this:
.include([{ type: 'ResidentCreatedTask' }, { type: 'ResidentCreatedTask' }]);
But this also didn't work.
I don't like this solution, but you can wrap it an object.
So our payload is const payload = [{ id: 0 },{ id: 1 }]. Doing the following will not work, this is what I did in original post:
expect(payload).to.nested.include({ '[0].id': 0, '[1].id': 1 });
Work around is:
const wrappedPayload = { a: payload };
expect(wrappedPayload).to.nested.include({ 'a[0].id': 0, 'a[1].id': 1 });
This works, but I don't like having to wrap it. Very much still open to solutions. Is this a bug I should report to chai team?

Mongoose relation not working both ways

I can't get a relationship running between my Rides and Comments controller in my app (built using the yeoman angular-fullstack generator).
Comment model:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var CommentSchema = new Schema({
name: String,
comment: String,
active: Boolean,
ride: { type: mongoose.Schema.Types.ObjectId, ref: 'Ride' }
});
module.exports = mongoose.model('Comment', CommentSchema);
Ride model:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var RideSchema = new Schema({
name: String,
distance: String,
climb: String,
rating: String,
active: Boolean,
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }]
});
module.exports = mongoose.model('Ride', RideSchema);
Accessing /api/comments/ gives me a correct result, containing a related Ride:
{"_id":"54ce818f8c2889da58b01e19","name":"NAAM","comment":"COMMENT","ride":"54ce69647a78532057aa98e0","__v":0}]
Accessing /api/rides/ gives me the following result, without the corresponding Comments:
[{"_id":"54ce69647a78532057aa98e0","name":"Ride test ingevuld","distance":"4000","climb":"1200","rating":"1","__v":0,"comments":[]}]
Can anyone tell me what i am doing wrong?
Example from one of my projects:
exports.insertRoom = function(req, res) {
var id = req.body.id;
var r = req.body.room;
var room = new Room({name: r.name});
Floor.update(
{_id : id},
{
$push: { rooms: room}
},
{upsert:true},
function(floor, err)
{
res.sendStatus(200);
}
);
};
As far as I'am concerned it doesn't work like that. Your comments got it's ride, and your ride got it's comments. I think, you should remove
ride: { type: mongoose.Schema.Types.ObjectId, ref: 'Ride' }
and keep comments inside ride collection.
comments: ['Comment']
It is more objective solution as it supposed to be in MONGO DB which was designed for objective(hierarchial) data.