I didn’t have this issue before… So it seams i broke something some how, but the console log when catching error is giving me this :
Back End :
import wixStoresBackend from 'wix-stores-backend';
export function createProduct(product) {
return wixStoresBackend.createProduct(product);
}
export function addProductsToCollection(product, collection) {
return wixStoresBackend.addProductsToCollection(product, collection);
}
export function addProductMedia(product, mediaData) {
return wixStoresBackend.addProductMedia(product, mediaData);
}
Front End :
import {
createProduct,
addProductsToCollection,
addProductMedia
} from 'backend/products';
import wixData from 'wix-data';
import wixUsers from 'wix-users';
let lenght = 0;
//const NUMBER_OF_CHOICES = $w("#innGallery").items.length;
$w.onReady(function () {
/* $w("#addProductButton").onClick(async () => {
*/
})
let galleryPictures = [];
let innGallery = {}
export async function galleryUploadBtn_change(event) {
let imageToGallery = {};
let file = $w('#galleryUploadBtn').value;
if (file.length > 0) {
const response = await $w('#galleryUploadBtn').startUpload($w('#galleryUploadBtn').buttonLabel = 'Chargement ...');
if (response) {
$w('#galleryUploadBtn').buttonLabel = 'Images';
imageToGallery.src = response.url;
imageToGallery.type = 'image';
console.log('gallery', galleryPictures);
galleryPictures.push(imageToGallery);
imageToGallery = {};
}
}
galleryDisplayer();
}
function galleryDisplayer() {
$w('#innGallery').items = galleryPictures;
$w('#Gallery').expand();
}
export async function videoUploadBtn_change(event) {
let videoToGallery = {};
let file = $w('#videoUploadBtn').value;
if (file.length > 0) {
const response = await $w('#videoUploadBtn').startUpload($w('#videoUploadBtn').buttonLabel = 'Chargement ...');
if (response) {
$w('#videoUploadBtn').buttonLabel = 'Videos';
videoToGallery.src = response.url;
videoToGallery.type = 'video';
console.log('gallery', galleryPictures);
galleryPictures.push(videoToGallery);
videoToGallery = {};
}
}
galleryDisplayer();
}
export function clear_click(event) {
galleryPictures = [];
galleryDisplayer();
}
/**
* Adds an event handler that runs when an input element's value
is changed.
* @param {$w.Event} event
*/
/**
* Adds an event handler that runs when an input element's value
is changed.
* @param {$w.Event} event
*/
/**
* Adds an event handler that runs when the element is clicked.
* @param {$w.MouseEvent} event
*/
//import { createProduct } from 'backend/products';
// ...
/**
* Adds an event handler that runs when the element is clicked.
* @param {$w.MouseEvent} event
*/
export async function addProductButton_click(event) {
wixData.query('Stores/Products').find().then((results) => {
lenght = results.items.length
})
var product = {
"name": $w("#input1").value,
"description": $w("#textBox1").value,
"price": $w("#input2").value,
"sku": wixUsers.currentUser.id + "-" + Number(lenght + 1),
"productType": "physical"
}
if ($w("#checkbox1").checked === true) {
product = { "name": $w("#input1").value,
"description": $w("#textBox1").value,
"price": $w("#input2").value,
"sku": wixUsers.currentUser.id + "-" + Number(lenght + 1),
"productOptions": {
"Variante": {
"choices": [{
"description": $w("#input3").value,
"value": $w("#input3").value
}]
}
},
"manageVariants": true,
"productType": "physical"}
}
console.log(product)
try {
let newProduct = await createProduct(product);
console.log(product)
// The product was created. Now assign it
// to a collection. Convert the product ID
// to an array.
const newProducts = [newProduct._id];
const collectionId = [$w("#dropdown1").value, $w("#dropdown3").value]
await addProductsToCollection(collectionId, newProducts)
// The product was assigned to a collection.
// Now let's add media.
const option = $w("#dropdown2").value
const choice = $w("#input3").value
innGallery = galleryPictures.map(a => ({ src: a.src }))
const medias = innGallery
const mediaData = medias
// If a choice and option are defined,const NUMBER_OF_CHOICES = 4;
// addProductMedia() adds media to choice
/* if (choice !== "" && option !== "") {
mediaData[0].choice = {
choice,
option
}
}
*/
await addProductMedia(newProducts, mediaData);
} catch (err) {
console.log(err)
}
}
/**
* Adds an event handler that runs when an input element's value
is changed.
* @param {$w.Event} event
*/
export function checkbox1_change(event) {
if ($w('#checkbox1').checked === true) {
$w("#input3").expand()
$w("#dropdown2").expand()
$w("#uploadButton1").expand()
} else {
$w("#input3").expand()
$w("#dropdown2").collapse()
$w("#uploadButton1").collapse()
}
}
Any idea ?