How to place woocommerce order with meta_data with axios - reactjs

i am creating a resturant delivery react native app using woocommerce api and trying to place an order with Woocommerce API using axios.
on the website, i can select a product, its optional dishes and place the order. and it creates successfully..
but in the app i do like this.
{
payment_method: "cod",
payment_method_title: "Cash On Delivery",
set_paid: true,
billing: {
first_name: "John",
last_name: "Doe",
address_1: "969 Market",
address_2: "",
city: "San Francisco",
state: "CA",
postcode: "94103",
country: "US",
email: "john.doe#example.com",
phone: "(555) 555-5555"
},
shipping: {
first_name: "John",
last_name: "Doe",
address_1: "969 Market",
address_2: "",
city: "San Francisco",
state: "CA",
postcode: "94103",
country: "US"
},
line_items: [
{
product_id: 1479,
quantity: 2
},
],
shipping_lines: [
{
method_id: "flat_rate",
method_title: "Flat Rate",
total: "10.00"
}
]
};
it creates the order successfully but only shows the side items without calculating the price. means only the basic price is shown on the order without adding the additional products.

Related

AWS Amplify - Graphql + Datastore: Variable 'input' has coerced Null value for NonNull type String

Running into a problem with the API generated with aws amplify.
Basically, I keep getting the following warning whenever I try to create one entity and it is not being persisted in DynamoDB.
Variable 'input' has coerced Null value for NonNull type 'String!
The following are the pertinent parts of the Graphql schema I used to create the backend.
enum EntityStatus {
ACTIVE
INACTIVE
ARCHIVED
}
type Address {
streetAddress1: String!
streetAddress2: String
city: String!
state: String!
zipCode: String!
country: String!
location: Location!
}
type Location {
lat: Float
lng: Float
}
type Tenant
#model
#auth(
rules: [
{ allow: groups, groups: ["Admin", "Coordinator", "Employees"], operations }
{ allow: groups, groups: ["Auditor"], operations: [read] }
]
) {
id: ID!
name: String!
address: Address!
phone: AWSPhone!
email: AWSEmail!
status: EntityStatus!
locale: String!
}
The code to create one of the Tenant entities is a simple call
try {
return await DataStore.save(new Tenant({ ...values }));
} catch (error) {
console.error(error);
}
The payload going sent by Datastore is as follows:
{
"name": "Tenant 1",
"phone": "1234567890",
"email": "tenant#tenant.com",
"status": "ACTIVE",
"address": {
"city": "Anytown",
"state": "TAB",
"zipCode": "12345",
"country": "US",
"location": { "lat": 123.12, "lng": 123.12 }
},
"locale": "en-US",
"id": "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a"
}
Here is the full Warning message
[WARN] 40:26.787 DataStore
Object { localModel: {…}, message: "Variable 'input' has coerced Null value for NonNull type 'String!'", operation: "Create", errorType: undefined, errorInfo: undefined, remoteModel: null }
errorInfo: undefined
errorType: undefined
localModel: Object { id: "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a", name: "Tenant 1", phone: "1234567890", … }
_deleted: undefined
_lastChangedAt: undefined
_version: undefined
address: Object { city: "Anytown", state: "TAB", zipCode: "12345", … }
createdAt: undefined
email: "tenant#tenant.com"
id: "f8be53bd-b1cb-4cbd-9b64-01fdf930da8a"
locale: "en-US"
name: "Tenant 1"
phone: "1234567890"
status: "ACTIVE"
updatedAt: undefined
<prototype>: Object { … }
message: "Variable 'input' has coerced Null value for NonNull type 'String!'"
operation: "Create"
remoteModel: null
<prototype>: Object { … }
react_devtools_backend.js:3973:25
Figured it out. My payload was missing 2 fields.
Wish that the error messages would be more helpful.

React JS Material UI DataGrid: how to join data between multiple table?

I have a dataGrid with React and Material UI. All data comes from table A which is structured as follows:
{Name: foo, Surname: Fry, Job Position: 3}
Then there is a table B which contains the correspondences of the various works eg:
{id: 3, Job: "comic"}
{id: 4, Job: "actor"}
etc...
how do i show "comic" in the grid instead of "3" as in the example?
A thousand thanks
You can process your data using the map() function. If your original data is in an array called people:
const people = [
{name: "Alice", surname: "Alman", job:3},
{name: "Bob", surname: "Briscoe", job:3},
{name: "Carol", surname: "Conway", job:1},
{name: "Dan", surname: "Dunne", job:2},
]
And you have the second table available
const jobs = [
{id: 1, job:"Programmer"},
{id: 2, job:"Actor"},
{id: 3, job:"Comic"},
{id: 4, job:"Manager"},
]
Then before passing the data to the grid you can do the following map to add the job title to each record:
const data = people.map(person => {
const job = jobs.find(job => job.id == person.job);
return {...person, title: job.job}
});
Which ends up with these values:
[{
"name": "Alice",
"surname": "Alman",
"job": 3,
"title": "Comic"
}, {
"name": "Bob",
"surname": "Briscoe",
"job": 3,
"title": "Comic"
}, {
"name": "Carol",
"surname": "Conway",
"job": 1,
"title": "Programmer"
}, {
"name": "Dan",
"surname": "Dunne",
"job": 2,
"title": "Actor"
}]

Mongo database call returning incorrect data after reload

I am trying to sort some database entries based on a boolean representing if a job is "completed" or not. The mutation functionality is working every time according to the graphQL playground but when the database call is utilized in the application the boolean data console logs as true first but then quickly logs again as false. The playground returns the data as true every time, once it has been changed, but something inside the application is not playing nice. Me and my project partners are freshly out of a coding bootcamp and have been learning successfully at a pretty steady pace but have not been able to figure this one out. Any feedback is appreciated. Thanks!!
const { loading: userLoading, data } = useQuery(QUERY_ME_BASIC);
const { loading: jobsLoading, data: jobsData } = useQuery(GET_JOBS);
var user = {};
var jobs = [];
var completedJobs = [];
var incompleteJobs = [];
if (!userLoading) {
console.log(jobsData)
user = data.me;
}
if(!jobsLoading){
jobs = jobsData.jobs
}
if(jobs){
console.log(jobs)
for (let i = 0; i < jobs.length; i++) {
if (jobs[i].completed === false) {
incompleteJobs.push(jobs[i]);
}
}
}
Query Response (GET_JOBS) from Graphql playground
{
"data": {
"jobs": [
{
"id": "47",
"_id": "6107fce77f7afc40e4e185a7",
"date": "2021-08-17",
"category": "Yard Waste",
"description": "addas",
"distance": "1.585",
"taken": true,
"completed": true,
"phone": "6153050246",
"email": "wfh2d88#gmail.com",
"driverEmail": "wfh2d88#gmail.com",
"createdAt": "Aug 2nd, 2021 at 9:10 am",
"pickup": {
"address": "207 Porter Village Circle",
"address2": "A",
"city": "Nashville",
"state": "Tennessee",
"zip": "37206",
"lat": "36.182571",
"lng": "-86.733267"
},
"dropoff": {
"address": "1800 Stratford Ave",
"address2": "A",
"city": "Nashville",
"state": "Alabama",
"zip": "37206",
"lat": "36.198164",
"lng": "-86.717083"
}
}
]
}
}
console.log(job) after Job Completion (3 appear one quickly after the other). First Two:
0:
category: "Yard Waste"
completed: true
createdAt: "Aug 2nd, 2021 at 9:10 am"
date: "2021-08-17"
description: "addas"
distance: "1.585"
driverEmail: "wfh2d88#gmail.com"
dropoff: {address: "1800 Stratford Ave", address2: "A", city: "Nashville", state: "Alabama", zip: "37206", …}
email: "wfh2d88#gmail.com"
id: "47"
phone: "6153050246"
pickup: {address: "207 Porter Village Circle", address2: "A", city: "Nashville", state: "Tennessee", zip: "37206", …}
taken: true
__typename: "Job"
_id: "6107fce77f7afc40e4e185a7"
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)
Profile.js:32
Object
Profile.js:41
Last log from same line:
0:
category: "Yard Waste"
completed: false
createdAt: "Aug 2nd, 2021 at 9:10 am"
date: "2021-08-17"
description: "addas"
distance: "1.585"
driverEmail: "wfh2d88#gmail.com"
dropoff: {address: "1800 Stratford Ave", address2: "A", city: "Nashville", state: "Alabama", zip: "37206", …}
email: "wfh2d88#gmail.com"
id: "47"
phone: "6153050246"
pickup: {address: "207 Porter Village Circle", address2: "A", city: "Nashville", state: "Tennessee", zip: "37206", …}
taken: true
__typename: "Job"
_id: "6107fce77f7afc40e4e185a7"

Order of data returning from Monongodb

I am making a mongodb model>>
const mongoose = require('mongoose');
const {Schema} = mongoose;
const locationSchema = new Schema({
name: String,
Address: String,
ContactInfo: {
phone: Number,
email: String,
},
Website: String,
Hours: {
DaysOpen: String,
OpeningTime:[Number],
ClosingTime:[Number],
},
Services: String,
Languages: String,
Documentation: Boolean,
OtherNotes: String,
})
mongoose.model('Locations', locationSchema);
When I try and run a get request to see what is in my database I am returned
{
"error": false,
"location": {
"Hours": {
"OpeningTime": [
1215,
898
],
"ClosingTime": [
1400
],
"DaysOpen": "Sunday"
},
"_id": "5ee8fd2e57aa5126d4c1c854",
"name": "Evergreen Christian Center Food Pantry",
"Address": "4400 NW Glencoe Rd, Hillsboro, OR 97124",
"ContactInfo": {
"phone": 5033196590,
"email": "gonzocyn2#msn.com"
},
"Website": "https://www.ecc4.org/home",
"Services": "All foods available including meat and frozen foods",
"Languages": "English, Spanish",
"Documentation": false,
"OtherNotes": "Bring own bag or box. Sign up starts at 9:00am",
"__v": 0
}
The problem is that "Hours" is being displayed before the name, address, and contact info. This only occurs when I have the fields "OpeningTime" and "ClosingTime" as arrays. Any idea on how to fix this?

Solr Querying Child document

I normally use elasticsearch and I'm new to solr. How can I search zip codes in child documents in some code like below? Is it even possible?
{
name: "my Name",
phone: {
mobile: "(123) 456 7800",
mobile2: "(123) 456 7800"
},
Address:{
Home: {
address: "123 something way",
cs: "El Cerrito, CA",
zip: 99999
},
Work: {
address: "444 Goldriver drive",
cs: "Cool, CA",
zip: 88888
}
}
}

Resources