Просмотр исходного кода

feat module 6, 7 : pull Size Chart data from shopify, include Size Chart identifiers in product service

master
nadia 2 дней назад
Родитель
Сommit
e3c47d511d
2 измененных файлов: 75 добавлений и 3 удалений
  1. 62
    2
      src/components/ProductDetails/ProductDetails.jsx
  2. 13
    1
      src/services/ProductService.js

+ 62
- 2
src/components/ProductDetails/ProductDetails.jsx Просмотреть файл

132
   const [variants, setVariants] = useState([])
132
   const [variants, setVariants] = useState([])
133
   const [showLoader, setShowLoader] = useState(false)
133
   const [showLoader, setShowLoader] = useState(false)
134
   const [atomeOpen, setAtomeOpen] = useState(false)
134
   const [atomeOpen, setAtomeOpen] = useState(false)
135
+  const [sizeChartOpen, setSizeChartOpen] = useState(false)
135
   const [storeAvailabilityOpen, setStoreAvailabilityOpen] = useState(false)
136
   const [storeAvailabilityOpen, setStoreAvailabilityOpen] = useState(false)
136
   const [storeSearch, setStoreSearch] = useState("")
137
   const [storeSearch, setStoreSearch] = useState("")
137
   const [expandedStoreRows, setExpandedStoreRows] = useState({})
138
   const [expandedStoreRows, setExpandedStoreRows] = useState({})
391
   const shippingInformationMetafield = product?.metafields?.shipping_information
392
   const shippingInformationMetafield = product?.metafields?.shipping_information
392
   const returnExchangeMetafield = product?.metafields?.return_exchange
393
   const returnExchangeMetafield = product?.metafields?.return_exchange
393
   const productDetailsMetafield = product?.metafields?.product_details
394
   const productDetailsMetafield = product?.metafields?.product_details
395
+  const sizeChartMetafield = product?.metafields?.size_chart
396
+  const sizeChartImageUrl = sizeChartMetafield?.reference?.image?.url || sizeChartMetafield?.reference?.url || ""
397
+  const sizeChartImageAlt = sizeChartMetafield?.reference?.image?.altText || `${product?.title || "Product"} size chart`
394
 
398
 
395
   // Renders Shopify product metafield custom.material inside the Material row.
399
   // Renders Shopify product metafield custom.material inside the Material row.
396
   const materialPanel = (
400
   const materialPanel = (
713
 
717
 
714
           <Box
718
           <Box
715
             component="a"
719
             component="a"
716
-            href="#"
720
+            href={sizeChartImageUrl || "#"}
721
+            onClick={(event) => {
722
+              event.preventDefault()
723
+              if (sizeChartImageUrl) setSizeChartOpen(true)
724
+            }}
717
             sx={{
725
             sx={{
718
               display: "inline-flex",
726
               display: "inline-flex",
719
               alignItems: "center",
727
               alignItems: "center",
721
               textDecoration: "underline",
729
               textDecoration: "underline",
722
               textTransform: "uppercase",
730
               textTransform: "uppercase",
723
               fontSize: "0.875rem",
731
               fontSize: "0.875rem",
724
-              mb: 1
732
+              mb: 1,
733
+              cursor: sizeChartImageUrl ? "pointer" : "default"
725
             }}
734
             }}
726
           >
735
           >
727
             <StraightenIcon sx={{ mr: 0.75, fontSize: 20 }} />
736
             <StraightenIcon sx={{ mr: 0.75, fontSize: 20 }} />
1139
         </Box>
1148
         </Box>
1140
       </Dialog>
1149
       </Dialog>
1141
 
1150
 
1151
+      {/* Size Chart Popup */}
1152
+      <Dialog
1153
+        open={sizeChartOpen}
1154
+        onClose={() => setSizeChartOpen(false)}
1155
+        maxWidth={false}
1156
+        PaperProps={{
1157
+          sx: {
1158
+            borderRadius: 1,
1159
+            backgroundColor: "#FFF",
1160
+            width: { xs: "calc(100% - 32px)", md: "auto" },
1161
+            maxWidth: { xs: "calc(100% - 32px)", md: "90vw" },
1162
+            maxHeight: "90vh",
1163
+            p: { xs: 1.5, md: 2 },
1164
+            position: "relative",
1165
+            overflow: "visible"
1166
+          }
1167
+        }}
1168
+      >
1169
+        <IconButton
1170
+          aria-label="Close size chart"
1171
+          onClick={() => setSizeChartOpen(false)}
1172
+          sx={{
1173
+            position: "absolute",
1174
+            right: { xs: -12, md: -16 },
1175
+            top: { xs: -12, md: -16 },
1176
+            backgroundColor: "#FFF",
1177
+            color: "#000",
1178
+            zIndex: 1,
1179
+            boxShadow: "0 1px 4px rgba(0,0,0,0.2)",
1180
+            "&:hover": {
1181
+              backgroundColor: "#FFF"
1182
+            }
1183
+          }}
1184
+        >
1185
+          <CloseIcon sx={{ fontSize: { xs: 24, md: 30 } }} />
1186
+        </IconButton>
1187
+
1188
+        <Box
1189
+          component="img"
1190
+          src={sizeChartImageUrl}
1191
+          alt={sizeChartImageAlt}
1192
+          sx={{
1193
+            display: "block",
1194
+            width: "100%",
1195
+            maxWidth: { xs: "100%", md: "80vw" },
1196
+            maxHeight: "80vh",
1197
+            objectFit: "contain"
1198
+          }}
1199
+        />
1200
+      </Dialog>
1201
+
1142
       {/* Store Availability Sidebar */}
1202
       {/* Store Availability Sidebar */}
1143
       <Drawer
1203
       <Drawer
1144
         anchor="right"
1204
         anchor="right"

+ 13
- 1
src/services/ProductService.js Просмотреть файл

171
           {key: "care_instruction", namespace: "custom"},
171
           {key: "care_instruction", namespace: "custom"},
172
           {key: "shipping_information", namespace: "custom"},
172
           {key: "shipping_information", namespace: "custom"},
173
           {key: "return_exchange", namespace: "custom"},
173
           {key: "return_exchange", namespace: "custom"},
174
-          {key: "product_details", namespace: "custom"}
174
+          {key: "product_details", namespace: "custom"},
175
+          {key: "size_chart", namespace: "custom"}
175
         ]
176
         ]
176
       ) {
177
       ) {
177
         namespace
178
         namespace
178
         key
179
         key
179
         type
180
         type
180
         value
181
         value
182
+        reference {
183
+          ... on MediaImage {
184
+            image {
185
+              url
186
+              altText
187
+            }
188
+          }
189
+          ... on GenericFile {
190
+            url
191
+          }
192
+        }
181
       }
193
       }
182
     }
194
     }
183
   }`
195
   }`

Загрузка…
Отмена
Сохранить