AFTER I MAKE WIX DATABASES GALLERY IN PREVIEW EVERYTHING IS WORK AFTER PUBLISH NOT WORK

PLEASE HELP

AFTER I MAKE WIX DATABASES GALLERY IN PREVIEW EVERYTHING IS WORK AFTER PUBLISH NOT WORK

Have you synchronised the sandbox data collection with the live one? Go to your data collection and click the synch option at the top of the screen and choose the option you need to copy your sandbox to your published pages.

Steve

1 Like

Thanks Thanks Thanks

@vladimirkstanchev You are welcome! Can you mark my comment as Top comment when you get a chance? Cheers Steve

@stcroppe
Hi, i have only one problem can you help me.
Dropdown menu is a category and sub categoria and after preview everything is work but after publish is not work.

up example is based on this code write with on friends

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;

// Helper method for extracting column records and making them unique
// All list methods use this to generate list containing objects with
// key value pairs for the keys ‘label’ and ‘value’ which is expected
//by the $w.DropDown.options property
function uniqueColumnListForField(list, field){
let result = ;
let uniqueValues = ; // Used to ensure values in the list are unique
list.forEach(item => {
let fieldValue = item[field];
// Only store field values that we haven’t yet seen. Skip null values
if (fieldValue && !uniqueValues.includes(fieldValue)) {
uniqueValues.push(fieldValue); // Remember this value to maintain uniqueness
// Save the resulting information in the format required by the DropDown options list.
result.push({ ‘label’: fieldValue, ‘value’: fieldValue });
}
});
return result;
}

function updateMainDropDown() {
wixData.query(“AllProductsMainCategories”)
.find()
.then( (results) => {
let options = [{
“value”: “ВСИЧКИ КАТЕГОРИИ”,
“label”: “ВСИЧКИ КАТЕГОРИИ”
}];

    options = options.concat(results.items.map(mainCategory => { 

return {
‘value’: mainCategory.mainCategory,
‘label’: mainCategory.mainCategory
};
}));

//console.log(options);
$w(‘#dropdownMainCategory’).options = options;
})
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
}

export function dropdownMainCategory_change(event) {

let mainCategoryFilter = wixData.filter();

if ($w(‘#dropdownMainCategory’).value) {
if ($w(‘#dropdownMainCategory’).value === “ВСИЧКИ КАТЕГОРИИ”){
$w(‘#allProductsDataset’).setFilter(mainCategoryFilter)
.then(() => {
//
});
} else {
mainCategoryFilter = mainCategoryFilter.eq(‘mainCategory’, $w(‘#dropdownMainCategory’).value);
$w(‘#allProductsDataset’).setFilter(mainCategoryFilter)
.then(() => {
wixData.query(“AllProducts”)
.eq(‘mainCategory’, $w(‘#dropdownMainCategory’).value)
.find()
.then( (results) => {
let subCategoryList = [{
“value”: “ВСИЧКИ ПОД КАТЕГОРИИ”,
“label”: “ВСИЧКИ ПОД КАТЕГОРИИ”
}];
subCategoryList = subCategoryList.concat(uniqueColumnListForField(results.items,“subCategory”));
//console.log(subCategoryList);
$w(‘#dropdownSubCategory’).options = subCategoryList;
$w(‘#dropdownSubCategory’).enable();
})
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

        }); 
    } 
} 

}

export function dropdownSubCategory_change(event) {

let subCategoryFilter = wixData.filter();

if ($w(‘#dropdownMainCategory’).value) {
if ($w(‘#dropdownSubCategory’).value === “ВСИЧКИ ПОД КАТЕГОРИИ”){

        subCategoryFilter = subCategoryFilter.eq('mainCategory', $w('#dropdownMainCategory').value);                         
        $w('#allProductsDataset').setFilter(subCategoryFilter) 
            .then(() => { 
                    wixData.query("AllProducts") 
                    .eq('mainCategory', $w('#dropdownMainCategory').value)   
                    .find() 
                    .then( (results) => {    

let subCategoryList = [{
“value”: “ВСИЧКИ ПОД КАТЕГОРИИ”,
“label”: “ВСИЧКИ ПОД КАТЕГОРИИ”
}];
subCategoryList = subCategoryList.concat(uniqueColumnListForField(results.items,“subCategory”));
//console.log(subCategoryList);
$w(‘#dropdownSubCategory’).options = subCategoryList;
$w(‘#dropdownSubCategory’).enable();
})
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

        }); 
    } **else** { 
        subCategoryFilter = subCategoryFilter.eq('subCategory', $w('#dropdownSubCategory').value);               
        $w('#allProductsDataset').setFilter(subCategoryFilter) 
            .then(() => { 

//
});
}
}
}

$w.onReady( function () {
//We initialise the drop downs here once the data we need is available.
$w(‘#allProductsDataset’).onReady(() => {
updateMainDropDown();
});
});

I want to make CATEGOTI AND SUBCATEGORI dropdawn menu what is the best way to do that

Hi Vladimir:

Can you show the URL for the site so that I can have a look?

Steve

Hi Vladimir:
If you have that URL I can still try to answer your question.

Cheers
Steve

Hi Vladimir:

OK I think what you need to do is build a single or combined query depending on the settings of the drop down.

So the logic will be:

export function dropdownMainCategory_change(event) {
    let mainCategoryFilter = wixData.filter();
    if ($w('#dropdownMainCategory').value) {
        if ($w('#dropdownMainCategory').value !== "ВСИЧКИ КАТЕГОРИИ"){
            mainCategoryFilter = mainCategoryFilter.eq('mainCategory', $w('#dropdownMainCategory').value);
        }
    }
    $w('#allProductsDataset').setFilter(mainCategoryFilter)                 
    .then(() => {
        // Load all items held by dataset after filter is applied                        
        $w('#allProductsDataset').getItems(0, $w('#allProductsDataset').getTotalCount())
        .then( (results) => {
             let subCategoryList = [
                 {  "value": "ВСИЧКИ ПОД КАТЕГОРИИ",
                    "label": "ВСИЧКИ ПОД КАТЕГОРИИ"                                                   
                 }];                                                                                          
             subCategoryList = subCategoryList.concat(uniqueColumnListForField(results.items,"subCategory"));
             $w('#dropdownSubCategory').options = subCategoryList;
             $w('#dropdownSubCategory').enable();
         })
        .catch( (error) => {
            let errorMsg = error.message;
            let code = error.code;
        } );
    });
} 

export function dropdownSubCategory_change(event) {
    let subCategoryFilter = wixData.filter();
    if ($w('#dropdownSubCategory').value) {
        // The sub category has changed
        // If we have a value that is NOT 
        // "ВСИЧКИ ПОД КАТЕГОРИИ" then there must have been
        // a main drop down selection
        if ($w('#dropdownSubCategory').value !== "ВСИЧКИ ПОД КАТЕГОРИИ"){
            // We need to filter on both the main and the sub categories
            let 
            subCategoryFilter = subCategoryFilter
                .eq('mainCategory', $w('#dropdownMainCategory').value)
                .eq('subCategory', $w('#dropdownSubCategory').value);                                         
           $w('#allProductsDataset')
               .setFilter(subCategoryFilter)
               .catch( (error) => {
                   let errorMsg = error.message;
                   let code = error.code;                         
               } );
       }
    }
}

When the main category changes (and its new value is NOT “ВСИЧКИ КАТЕГОРИИ”) you reset the sub category to an empty list except for the title row “ВСИЧКИ ПОД КАТЕГОРИИ”.

If you have items in the filtered list that are sub categories these are appended to the sub category drop down.

The only way you can have a change event on the sub category list that doesn’t have the value “ВСИЧКИ ПОД КАТЕГОРИИ” is if you have a selected main category with sub categories.

Now to filter on both the main and sub categories your filter needs to include both the main and the sub category values. So we do this by concatenating .eq() query filters like this…

subCategoryFilter
.eq('mainCategory', $w('#dropdownMainCategory').value) .eq('subCategory', $w('#dropdownSubCategory').value);

This should solve your problem!

Lastly, I changed your wixData call that fetches the subcategory data from the data collection. This is inefficient because it will force another data collection query. Your filter of the dataset will already have the complete list of items that you need to extract the sub categories from. So all you need to do is get all of the items from the filtered dataset. These should already be loaded so you don’t need to fetch them again.

Good luck
Steve