Skip to content

Commit

Permalink
feat(shopify): resync item in bulk import
Browse files Browse the repository at this point in the history
  • Loading branch information
penieldev committed Sep 5, 2022
1 parent d66f3ae commit bed3723
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Expand Up @@ -176,7 +176,9 @@ shopify.ProductImporter = class {
'Name': product.title,
'SKUs': product.variants && product.variants.map(a => `${a.sku}`).join(', '),
'Status': this.getProductSyncStatus(product.synced),
'Action': !product.synced ? `<button type="button" class="btn btn-default btn-xs btn-sync mx-2" data-product="${product.id}"> Sync </button>` : '-',
'Action': !product.synced ?
`<button type="button" class="btn btn-default btn-xs btn-sync mx-2" data-product="${product.id}"> Sync </button>` :
`<button type="button" class="btn btn-default btn-xs btn-resync mx-2" data-product="${product.id}"> Re-sync </button>`,
}));

return shopifyProducts;
Expand Down Expand Up @@ -217,12 +219,39 @@ shopify.ProductImporter = class {
.find('.indicator-pill')
.replaceWith(this.getProductSyncStatus(true));

_this.remove();
_this.replaceWith(`<button type="button" class="btn btn-default btn-xs btn-resync mx-2" data-product="${product}"> Re-sync </button>`);

});

});

this.wrapper.on('click', '.btn-resync', e => {
const _this = $(e.currentTarget);

_this.prop('disabled', true).text('Syncing...');

const product = _this.attr('data-product');
this.resyncProduct(product)
.then(status => {

if (!status) {
frappe.throw(__('Error syncing product'));
return;
}

_this.parents('.dt-row')
.find('.indicator-pill')
.replaceWith(this.getProductSyncStatus(true));

_this.prop('disabled', false).text('Re-sync');

})
.catch(ex => {
_this.prop('disabled', false).text('Re-sync');
frappe.throw(__('Error syncing Product'));
});
});

// pagination
this.wrapper.on('click', '.btn-prev,.btn-next', e => this.switchPage(e));

Expand All @@ -245,6 +274,20 @@ shopify.ProductImporter = class {

}

async resyncProduct(product) {

const { message: status } = await frappe.call({
method: 'ecommerce_integrations.shopify.page.shopify_import_products.shopify_import_products.resync_product',
args: { product },
});

if (status)
this.fetchProductCount();

return status;

}

async switchPage({ currentTarget }) {

const _this = $(currentTarget);
Expand Down
Expand Up @@ -90,6 +90,25 @@ def sync_product(product):
return False


@frappe.whitelist()
def resync_product(product):
return _resync_product(product)


@temp_shopify_session
def _resync_product(product):
try:
item = Product.find(product)

for variant in item.variants:
shopify_product = ShopifyProduct(product, variant_id=variant.id)
shopify_product.sync_product()

return True
except Exception:
return False


def is_synced(product):
return ecommerce_item.is_synced(MODULE_NAME, integration_item_code=product)

Expand Down

0 comments on commit bed3723

Please sign in to comment.