Skip to content

Commit

Permalink
Merge pull request #395 from evershopcommerce/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
treoden authored Nov 6, 2023
2 parents 2202b9d + 4f90d01 commit 9f3e40a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ const { get } = require('@evershop/evershop/src/lib/util/get');

module.exports = async (request, response, delegate) => {
const gallery = get(request, 'body.images', undefined);
if (gallery !== undefined) {
const productId = await delegate.updateProduct;
const connection = await delegate.getConnection;
const productId = await delegate.updateProduct;
const connection = await delegate.getConnection;
if (Array.isArray(gallery) && gallery.length === 0) {
// Delete all images
await del('product_image')
.where('product_image_product_id', '=', productId)
.execute(connection);
}
if (Array.isArray(gallery) && gallery.length > 0) {
// eslint-disable-next-line no-useless-catch
try {
// Delete all images that not in the gallery anymore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ module.exports = {
.and('is_main', '=', false)
.execute(pool);
return gallery.map((image) => ({
id: image.product_image_id,
alt: product.name,
url: image.origin_image,
uuid: uuidv4(),
origin: image.origin_image,
thumb: image.thumb_image,
single: image.single_image,
listing: image.listing_image
}));
id: image.product_image_id,
alt: product.name,
url: image.origin_image,
uuid: uuidv4(),
origin: image.origin_image,
thumb: image.thumb_image,
single: image.single_image,
listing: image.listing_image
}));
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default function ProductEditForm({ action }) {
// eslint-disable-next-line no-param-reassign
formData.tax_class = null;
}
if (formData.images === undefined) {
// eslint-disable-next-line no-param-reassign
formData.images = [];
}
return formData;
}}
onError={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ Current.propTypes = {

export default function Images({ product: { uuid, image, gallery = [] } }) {
const [current, setCurrent] = React.useState(image);
const [thumbs, setThumbs] = React.useState(() => {
if (image) {
// Add image to beginning of gallery
gallery.unshift(image);
}
return gallery;
});
const [thumbs, setThumbs] = React.useState(gallery);

React.useEffect(() => {
setCurrent(image);
Expand Down

0 comments on commit 9f3e40a

Please sign in to comment.