feat(arcteryx): add price (#12310)

This commit is contained in:
Evan 2023-04-15 12:36:37 -07:00 committed by GitHub
parent 642ac174e9
commit 24a15810c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 33 deletions

View File

@ -1,21 +1,8 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { generateRssData } = require('./utils');
const attributeSet = new Set(['name', 'image', 'short_description', 'slug']);
function generateRssData(item, index, arr) {
const attributes = item.attribute;
const data = {};
attributes.forEach((attribute) => {
const key = attribute.name;
const value = attribute.value[0].value;
if (attributeSet.has(key)) {
data[key] = value;
}
});
arr[index] = data;
}
module.exports = async (ctx) => {
const { country, gender } = ctx.params;
const host = `https://arcteryx.com/${country}/en/`;
@ -32,7 +19,9 @@ module.exports = async (ctx) => {
},
});
const items = response.data.universes.universe[1]['items-section'].items.item;
items.forEach(generateRssData);
items.forEach((item, index, arr) => {
generateRssData(item, index, arr, country);
});
ctx.state.data = {
title: `Arcteryx - New Arrivals(${country.toUpperCase()}) - ${gender.toUpperCase()}`,

View File

@ -1,21 +1,8 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { generateRssData } = require('./utils');
const attributeSet = new Set(['name', 'image', 'short_description', 'slug']);
function generateRssData(item, index, arr) {
const attributes = item.attribute;
const data = {};
attributes.forEach((attribute) => {
const key = attribute.name;
const value = attribute.value[0].value;
if (attributeSet.has(key)) {
data[key] = value;
}
});
arr[index] = data;
}
module.exports = async (ctx) => {
const { country, gender } = ctx.params;
const host = `https://outlet.arcteryx.com/${country}/en/`;
@ -34,7 +21,9 @@ module.exports = async (ctx) => {
},
});
const items = response.data.universes.universe[1]['items-section'].items.item;
items.forEach(generateRssData);
items.forEach((item, index, arr) => {
generateRssData(item, index, arr, country);
});
ctx.state.data = {
title: `Arcteryx - Outlet(${country.toUpperCase()}) - ${gender.toUpperCase()}`,

View File

@ -1,6 +1,12 @@
<div>
{{if item.short_description}}
{{item.short_description}}<br>
{{/if}}
{{if item.original_price}}
Original Price: {{item.original_price}}<br>
{{/if}}
{{if item.price}}
Current Price: {{item.price}}<br>
{{/if}}
<img src={{item.image}}>
<br><br>
{{item.short_description}}
<br><br>
</div>

23
lib/v2/arcteryx/utils.js Normal file
View File

@ -0,0 +1,23 @@
function generateRssData(item, index, arr, country) {
const attributeSet = new Set(['name', 'image', 'short_description', 'slug', `price_${country}`, `discount_price_${country}`]);
const attributes = item.attribute;
const data = {};
attributes.forEach((attribute) => {
const key = attribute.name;
const value = attribute.value[0].value;
if (attributeSet.has(key)) {
if (key === `price_${country}`) {
data.original_price = value;
} else if (key === `discount_price_${country}`) {
data.price = value;
} else {
data[key] = value;
}
}
});
arr[index] = data;
}
module.exports = {
generateRssData,
};