Skip to content

Commit 9d48267

Browse files
committed
104362 Update product title with data from endpoint
1 parent d190fec commit 9d48267

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

view/adminhtml/web/vue/menu-type/product.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
v-model="item.content"
66
:label="config.translation.productId"
77
type="textarea"
8-
@input="updateTitle"
8+
@input="debouncedUpdateTitle"
99
/>
1010
</div>
1111
</template>
@@ -26,7 +26,18 @@
2626
}
2727
},
2828
template: template,
29+
data() {
30+
return {
31+
updateTitleTimeout: null
32+
};
33+
},
2934
methods: {
35+
debouncedUpdateTitle(value) {
36+
clearTimeout(this.updateTitleTimeout);
37+
this.updateTitleTimeout = setTimeout(() => {
38+
this.updateTitle(value);
39+
}, 300);
40+
},
3041
updateTitle(value) {
3142
let adminPath = window.location.pathname.split('/snowmenu')[0];
3243
fetch(`${adminPath}/snowmenu/node/productName?isAjax=true&product_id=${value}&form_key=${window.FORM_KEY}`, {
@@ -36,15 +47,16 @@
3647
},
3748
})
3849
.then((response) => {
39-
console.log(response)
40-
// return response.json();
50+
if (!response.ok) {
51+
throw new Error(response.status);
52+
}
53+
return response.json();
54+
})
55+
.then(data => {
56+
data.product_name && this.$set(this.item, 'title', data.product_name);
4157
})
42-
// .then(data => {
43-
// this.$set(this.item, 'title', data.name);
44-
// })
4558
.catch(error => {
4659
console.error('Error fetching product name:', error);
47-
// this.$set(this.item, 'title', value);
4860
});
4961
}
5062
}

0 commit comments

Comments
 (0)