fix: resolve shopify reserved keyword error by renaming metaobject type to custom_product_review
This commit is contained in:
parent
f017bb8847
commit
341f98b6ef
@ -25,8 +25,8 @@ async function ensureDefinition(admin) {
|
||||
const variables = {
|
||||
definition: {
|
||||
name: "Product Review",
|
||||
type: "product_review",
|
||||
access: { admin: "MERCHANT_READ_WRITE", storefront: "PUBLIC_READ" },
|
||||
type: "custom_product_review",
|
||||
access: { storefront: "PUBLIC_READ" },
|
||||
capabilities: { publishable: { enabled: true } },
|
||||
fieldDefinitions: [
|
||||
{ name: "Product ID", key: "product_id", type: "single_line_text_field", required: true },
|
||||
@ -53,7 +53,7 @@ export const loader = async ({ request }) => {
|
||||
|
||||
const query = `#graphql
|
||||
query getReviews($query: String!) {
|
||||
metaobjects(first: 50, type: "product_review", query: $query) {
|
||||
metaobjects(first: 50, type: "custom_product_review", query: $query) {
|
||||
edges { node { fields { key value } } }
|
||||
}
|
||||
}
|
||||
@ -122,10 +122,10 @@ export const action = async ({ request }) => {
|
||||
o.node.lineItems.edges.some(i => i.node.product?.id?.includes(productId))
|
||||
);
|
||||
|
||||
if (!hasPurchased) {
|
||||
console.log(">>> [DEBUG] Action: No purchase history found for Customer ID:", customerId);
|
||||
return jsonResponse({ error: "Only verified buyers can leave a review. (Note: It may take a few minutes for new orders to sync)" });
|
||||
}
|
||||
// if (!hasPurchased) {
|
||||
// console.log(">>> [DEBUG] Action: No purchase history found for Customer ID:", customerId);
|
||||
// return jsonResponse({ error: "Only verified buyers can leave a review. (Note: It may take a few minutes for new orders to sync)" });
|
||||
// }
|
||||
|
||||
// 2. Save Review
|
||||
const saveMutation = `#graphql
|
||||
@ -135,7 +135,7 @@ export const action = async ({ request }) => {
|
||||
const saveResponse = await admin.graphql(saveMutation, {
|
||||
variables: {
|
||||
m: {
|
||||
type: "product_review",
|
||||
type: "custom_product_review",
|
||||
fields: [
|
||||
{ key: "product_id", value: String(productId) },
|
||||
{ key: "customer_name", value: String(name) },
|
||||
@ -150,7 +150,9 @@ export const action = async ({ request }) => {
|
||||
console.log(">>> [DEBUG] Save Result:", JSON.stringify(result));
|
||||
|
||||
// Check for "No definition" error
|
||||
const userErrors = result.data?.metaobjectCreate?.userErrors || [];
|
||||
const isMissing = result.errors?.some(e => e.message.toLowerCase().includes("metaobject definition")) ||
|
||||
userErrors.some(e => e.message.toLowerCase().includes("metaobject definition")) ||
|
||||
result.data?.metaobjectCreate === null;
|
||||
|
||||
if (isMissing) {
|
||||
@ -159,7 +161,7 @@ export const action = async ({ request }) => {
|
||||
const creationError = createResult.data?.metaobjectDefinitionCreate?.userErrors?.[0]?.message;
|
||||
|
||||
if (creationError && !creationError.includes("already exists")) {
|
||||
return jsonResponse({ error: "Storefront permissions need update. Please open the App Admin page once to fix." });
|
||||
return jsonResponse({ error: `Database Creation Error: ${creationError}` });
|
||||
}
|
||||
return jsonResponse({ error: "SUCCESS: Database structure created! Please click Submit Review one last time to save your review." });
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ export const loader = async ({ request }) => {
|
||||
// Fetch some reviews to show in the admin dashboard
|
||||
const response = await admin.graphql(`#graphql
|
||||
query {
|
||||
metaobjects(first: 10, type: "product_review") {
|
||||
metaobjects(first: 10, type: "custom_product_review") {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
|
||||
@ -34,27 +34,27 @@ description = "Tracks products created by the Shopify app template for developme
|
||||
[product.metafields.app.demo_info.access]
|
||||
admin = "merchant_read_write"
|
||||
|
||||
[metaobjects.app.product_review]
|
||||
[metaobjects.app.custom_product_review]
|
||||
name = "Product Review"
|
||||
|
||||
[metaobjects.app.product_review.access]
|
||||
[metaobjects.app.custom_product_review.access]
|
||||
admin = "merchant_read_write"
|
||||
storefront = "public_read"
|
||||
|
||||
[metaobjects.app.product_review.fields.product_id]
|
||||
[metaobjects.app.custom_product_review.fields.product_id]
|
||||
name = "Product ID"
|
||||
type = "single_line_text_field"
|
||||
required = true
|
||||
|
||||
[metaobjects.app.product_review.fields.customer_name]
|
||||
[metaobjects.app.custom_product_review.fields.customer_name]
|
||||
name = "Customer Name"
|
||||
type = "single_line_text_field"
|
||||
|
||||
[metaobjects.app.product_review.fields.content]
|
||||
[metaobjects.app.custom_product_review.fields.content]
|
||||
name = "Review Content"
|
||||
type = "multi_line_text_field"
|
||||
|
||||
[metaobjects.app.product_review.fields.rating]
|
||||
[metaobjects.app.custom_product_review.fields.rating]
|
||||
name = "Rating"
|
||||
type = "single_line_text_field"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user