feat(marketplace): featured Items for sellers
diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
index 1283711..4b49f19 100644
--- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
+++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
+ "allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
@@ -351,8 +352,8 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-09-01 17:05:59.600583",
- "modified_by": "cave@aperture.com",
+ "modified": "2019-02-01 14:21:16.729848",
+ "modified_by": "Administrator",
"module": "Hub Node",
"name": "Marketplace Settings",
"name_case": "",
diff --git a/erpnext/public/js/hub/PageContainer.vue b/erpnext/public/js/hub/PageContainer.vue
index a101eaf..7935837 100644
--- a/erpnext/public/js/hub/PageContainer.vue
+++ b/erpnext/public/js/hub/PageContainer.vue
@@ -10,6 +10,7 @@
import Search from './pages/Search.vue';
import Category from './pages/Category.vue';
import SavedItems from './pages/SavedItems.vue';
+import FeaturedItems from './pages/FeaturedItems.vue';
import PublishedItems from './pages/PublishedItems.vue';
import Item from './pages/Item.vue';
import Seller from './pages/Seller.vue';
@@ -32,6 +33,7 @@
const registered_routes = {
'marketplace/profile': Profile,
'marketplace/saved-items': SavedItems,
+ 'marketplace/featured-items': FeaturedItems,
'marketplace/publish': Publish,
'marketplace/published-items': PublishedItems,
'marketplace/buying': Buying,
diff --git a/erpnext/public/js/hub/Sidebar.vue b/erpnext/public/js/hub/Sidebar.vue
index ef3510d..66c291e 100644
--- a/erpnext/public/js/hub/Sidebar.vue
+++ b/erpnext/public/js/hub/Sidebar.vue
@@ -31,6 +31,11 @@
condition: () => this.hub_registered
},
{
+ label: __('Your Featured Items'),
+ route: 'marketplace/featured-items',
+ condition: () => this.hub_registered
+ },
+ {
label: __('Your Profile'),
route: 'marketplace/profile',
condition: () => this.hub_registered
diff --git a/erpnext/public/js/hub/components/EmptyState.vue b/erpnext/public/js/hub/components/EmptyState.vue
index d6216c9..e3a33a0 100644
--- a/erpnext/public/js/hub/components/EmptyState.vue
+++ b/erpnext/public/js/hub/components/EmptyState.vue
@@ -3,7 +3,7 @@
:class="{ 'bordered': bordered, 'align-center': centered, 'justify-center': centered }"
:style="{ height: height + 'px' }"
>
- <p class="text-muted">{{ message }}</p>
+ <p class="text-muted" v-html="message" ></p>
<p v-if="action">
<button class="btn btn-default btn-xs"
@click="action.on_click"
diff --git a/erpnext/public/js/hub/pages/FeaturedItems.vue b/erpnext/public/js/hub/pages/FeaturedItems.vue
new file mode 100644
index 0000000..ab9990a
--- /dev/null
+++ b/erpnext/public/js/hub/pages/FeaturedItems.vue
@@ -0,0 +1,118 @@
+<template>
+ <div
+ class="marketplace-page"
+ :data-page-name="page_name"
+ >
+ <h5>{{ page_title }}</h5>
+ <p v-if="items.length"
+ class="text-muted margin-bottom">
+ {{ __('You can Feature upto 8 items.') }}
+ </p>
+
+ <item-cards-container
+ :container_name="page_title"
+ :items="items"
+ :item_id_fieldname="item_id_fieldname"
+ :on_click="go_to_item_details_page"
+ :editable="true"
+ @remove-item="on_item_remove"
+ :empty_state_message="empty_state_message"
+ >
+ </item-cards-container>
+ </div>
+</template>
+
+<script>
+export default {
+ name: 'featured-items-page',
+ data() {
+ return {
+ page_name: frappe.get_route()[1],
+ items: [],
+ item_id_fieldname: 'name',
+
+ // Constants
+ page_title: __('Your Featured Items'),
+ empty_state_message: __(`No featured items yet. Got to your
+ <a href="#marketplace/published-items">
+ Published Items</a>
+ and feature upto 8 items that you want to highlight to your customers.`)
+ };
+ },
+ created() {
+ this.get_items();
+ },
+ methods: {
+ get_items() {
+ hub.call(
+ 'get_featured_items_of_seller', {},
+ 'action:item_feature'
+ )
+ .then((items) => {
+ this.items = items;
+ })
+ },
+
+ go_to_item_details_page(hub_item_name) {
+ frappe.set_route(`marketplace/item/${hub_item_name}`);
+ },
+
+ on_item_remove(hub_item_name) {
+ const grace_period = 5000;
+ let reverted = false;
+ let alert;
+
+ const undo_remove = () => {
+ this.toggle_item(hub_item_name);;
+ reverted = true;
+ alert.hide();
+ return false;
+ }
+
+ const item_name = this.items.filter(item => item.hub_item_name === hub_item_name);
+
+ alert = frappe.show_alert(__(`<span>${item_name} removed.
+ <a href="#" data-action="undo-remove"><b>Undo</b></a></span>`),
+ grace_period/1000,
+ {
+ 'undo-remove': undo_remove.bind(this)
+ }
+ );
+
+ this.toggle_item(hub_item_name, false);
+
+ setTimeout(() => {
+ if(!reverted) {
+ this.remove_item_from_featured_items(hub_item_name);
+ }
+ }, grace_period);
+ },
+
+ remove_item_from_featured_items(hub_item_name) {
+ erpnext.hub.trigger('action:item_feature');
+ hub.call('remove_item_from_seller_featured_items', {
+ hub_item_name,
+ hub_user: frappe.session.user
+ })
+ .then(() => {
+ this.get_items();
+ })
+ .catch(e => {
+ console.log(e);
+ });
+ },
+
+ // By default show
+ toggle_item(hub_item_name, show=true) {
+ this.items = this.items.map(item => {
+ if(item.name === hub_item_name) {
+ item.seen = show;
+ }
+ return item;
+ });
+ }
+ }
+}
+</script>
+
+<style scoped></style>
diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue
index c379fc7..841d004 100644
--- a/erpnext/public/js/hub/pages/Item.vue
+++ b/erpnext/public/js/hub/pages/Item.vue
@@ -73,6 +73,11 @@
action: this.add_to_saved_items
},
{
+ label: __('Add to Featured Item'),
+ condition: hub.is_user_registered() && this.is_own_item,
+ action: this.add_to_featured_items
+ },
+ {
label: __('Report this Item'),
condition: !this.is_own_item,
action: this.report_item
@@ -212,6 +217,21 @@
});
},
+ add_to_featured_items() {
+ hub.call('add_item_to_seller_featured_items', {
+ hub_item_name: this.hub_item_name,
+ hub_user: frappe.session.user
+ },)
+ .then(() => {
+ const featured_items_link = `<b><a href="#marketplace/featured-items">${__('Added to Featured Items')}</a></b>`
+ frappe.show_alert(featured_items_link);
+ erpnext.hub.trigger('action:item_feature');
+ })
+ .catch(e => {
+ console.error(e);
+ });
+ },
+
make_contact_seller_dialog() {
this.contact_seller_dialog = new frappe.ui.Dialog({
title: __('Send a message'),