diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py
index c4a7925582..9f4499f7a0 100644
--- a/erpnext/hub_node/api.py
+++ b/erpnext/hub_node/api.py
@@ -81,13 +81,14 @@ def publish_selected_items(items_to_publish):
'item_code': item_code,
'hub_category': item.get('hub_category'),
'image_list': item.get('image_list')
- }).insert()
+ }).insert(ignore_if_duplicate=True)
items = map_fields(items_to_publish)
try:
item_sync_preprocess()
+ load_base64_image_from_items(items)
# TODO: Publish Progress
connection = get_hub_connection()
@@ -97,10 +98,8 @@ def publish_selected_items(items_to_publish):
'status': 'Success',
'stats': len(items)
})
-
except Exception as e:
- frappe.db.set_value("Hub Settings", "Hub Settings", "sync_in_progress", 0)
- frappe.throw(e)
+ frappe.log_error(title='Hub Sync Error')
def item_sync_preprocess():
hub_seller = frappe.db.get_value("Hub Settings", "Hub Settings", "company_email")
@@ -137,6 +136,31 @@ def item_sync_postprocess(sync_details):
frappe.db.set_value('Hub Settings', 'Hub Settings', 'sync_in_progress', 0)
+
+def load_base64_image_from_items(items):
+ import io, base64, urllib, os
+ from frappe.utils.file_manager import get_file_path
+
+ for item in items:
+ file_path = item['image']
+ file_name = os.path.basename(file_path)
+
+ if file_path.startswith('http'):
+ url = file_path
+ file_path = os.path.join('/tmp', file_name)
+ urllib.urlretrieve(url, file_path)
+ else:
+ file_path = os.path.abspath(get_file_path(file_path))
+
+ with io.open(file_path, 'rb') as f:
+ image_data = json.dumps({
+ 'file_name': file_name,
+ 'base64': base64.b64encode(f.read())
+ })
+
+ item['image'] = image_data
+
+
def get_hub_connection():
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
diff --git a/erpnext/public/js/hub/Sidebar.vue b/erpnext/public/js/hub/Sidebar.vue
index b5a4e46cb3..6728664cad 100644
--- a/erpnext/public/js/hub/Sidebar.vue
+++ b/erpnext/public/js/hub/Sidebar.vue
@@ -19,48 +19,44 @@
export default {
data() {
return {
+ hub_registered: hub.settings.registered,
items: [
{
label: __('Browse'),
route: 'marketplace/home'
},
- {
- label: __('Become a Seller'),
- action: this.show_register_dialog,
- condition: () => !hub.settings.registered
- },
{
label: __('Saved Products'),
route: 'marketplace/saved-products',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
{
label: __('Your Profile'),
route: 'marketplace/profile',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
{
label: __('Your Products'),
route: 'marketplace/my-products',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
{
label: __('Publish Products'),
route: 'marketplace/publish',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
{
label: __('Selling'),
route: 'marketplace/selling',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
{
label: __('Buying'),
route: 'marketplace/buying',
- condition: () => hub.settings.registered
+ condition: () => this.hub_registered
},
],
- categories: []
+ categories: [],
}
},
created() {
@@ -80,6 +76,10 @@ export default {
this.update_sidebar_state();
});
});
+
+ erpnext.hub.on('seller-registered', () => {
+ this.hub_registered = true;
+ })
},
mounted() {
this.update_sidebar_state();
@@ -99,7 +99,7 @@ export default {
const $siblings = container.find('[data-route]');
$siblings.removeClass('active').addClass('text-muted');
$sidebar_item.addClass('active').removeClass('text-muted');
- }
+ },
}
}
diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js
index 95a7542863..373f552c20 100644
--- a/erpnext/public/js/hub/marketplace.js
+++ b/erpnext/public/js/hub/marketplace.js
@@ -21,15 +21,17 @@ erpnext.hub.Marketplace = class Marketplace {
this.page = parent.page;
frappe.db.get_doc('Hub Settings')
- .then(doc => {
+ .then(doc => {
hub.settings = doc;
- this.registered = doc.registered;
-
+ const is_registered = hub.settings.registered
this.setup_header();
this.make_sidebar();
this.make_body();
this.setup_events();
this.refresh();
+ if (!is_registered) {
+ this.page.set_primary_action('Become A Seller', this.show_register_dialog.bind(this))
+ }
});
}
@@ -74,8 +76,10 @@ erpnext.hub.Marketplace = class Marketplace {
});
erpnext.hub.on('seller-registered', () => {
- this.registered = 1;
- this.make_sidebar_nav_buttons();
+ this.page.clear_primary_action()
+ frappe.db.get_doc('Hub Settings').then((doc)=> {
+ hub.settings = doc;
+ });
});
}
@@ -83,86 +87,6 @@ erpnext.hub.Marketplace = class Marketplace {
}
- _refresh() {
- const route = frappe.get_route();
- this.subpages = this.subpages || {};
-
- for (let page in this.subpages) {
- this.subpages[page].hide();
- }
-
- if (route[1] === 'home' && !this.subpages.home) {
- this.subpages.home = new erpnext.hub.HomePage(this.$body);
- }
-
- if (route[1] === 'search' && !this.subpages.search) {
- this.subpages.search = new erpnext.hub.SearchPage(this.$body);
- }
-
- if (route[1] === 'category' && route[2] && !this.subpages.category) {
- this.subpages.category = new erpnext.hub.CategoryPage(this.$body);
- }
-
- if (route[1] === 'item' && route[2] && !this.subpages.item) {
- this.subpages.item = new erpnext.hub.ItemPage(this.$body);
- }
-
- if (route[1] === 'seller' && !this.subpages['seller']) {
- this.subpages['seller'] = new erpnext.hub.SellerPage(this.$body);
- }
-
- if (route[1] === 'register' && !this.subpages.register) {
- if (this.registered) {
- frappe.set_route('marketplace', 'home');
- return;
- }
- this.subpages.register = new erpnext.hub.Register(this.$body);
- }
-
- // registered seller routes
- if (route[1] === 'saved-products' && !this.subpages['saved-products']) {
- this.subpages['saved-products'] = new erpnext.hub.SavedProductsPage(this.$body);
- }
-
- if (route[1] === 'profile' && !this.subpages.profile) {
- this.subpages.profile = new erpnext.hub.ProfilePage(this.$body);
- }
-
- if (route[1] === 'publish' && !this.subpages.publish) {
- this.subpages.publish = new erpnext.hub.PublishPage(this.$body);
- }
-
- if (route[1] === 'my-products' && !this.subpages['my-products']) {
- this.subpages['my-products'] = new erpnext.hub.PublishedProductsPage(this.$body);
- }
-
- if (route[1] === 'buying' && !this.subpages['buying']) {
- this.subpages['buying'] = new erpnext.hub.Buying(this.$body);
- }
-
- if (route[1] === 'selling' && !this.subpages['selling']) {
- this.subpages['selling'] = new erpnext.hub.Selling(this.$body, 'Selling');
- }
-
- // dont allow unregistered users to access registered routes
- const registered_routes = ['saved-products', 'profile', 'publish', 'my-products', 'messages'];
- if (!hub.settings.registered && registered_routes.includes(route[1])) {
- frappe.set_route('marketplace', 'home');
- return;
- }
-
- if (!Object.keys(this.subpages).includes(route[1])) {
- if (!this.subpages.not_found) {
- this.subpages.not_found = new erpnext.hub.NotFoundPage(this.$body);
- }
- route[1] = 'not_found';
- }
-
- this.update_sidebar();
- frappe.utils.scroll_to(0);
- this.subpages[route[1]].show();
- }
-
show_register_dialog() {
this.register_dialog = ProfileDialog(
__('Become a Seller'),
@@ -186,4 +110,5 @@ erpnext.hub.Marketplace = class Marketplace {
erpnext.hub.trigger('seller-registered');
});
}
+
}
diff --git a/erpnext/public/js/hub/pages/Buying.vue b/erpnext/public/js/hub/pages/Buying.vue
index 7c3fc27bbd..ddb4b11db9 100644
--- a/erpnext/public/js/hub/pages/Buying.vue
+++ b/erpnext/public/js/hub/pages/Buying.vue
@@ -3,7 +3,7 @@
{{ __('Buying') }}
${message.content}
-