Hide products on woocommerce when deleted

This commit is contained in:
Sergi Almacellas Abellana 2020-06-30 11:01:40 +02:00
parent 30ed06fcbf
commit a577c3e032
2 changed files with 15 additions and 2 deletions

View File

@ -44,6 +44,12 @@ class Product(ShopWooCommerceIdMixin, metaclass=PoolMeta):
parent = parent.parent
return ''
def woocommerce_disable_data(self, shop):
return {
'status': 'private',
'catalog_visibility': 'hidden',
}
def get_woocommerce_entity(self):
short_description = description = (self.description or '')
lines = description.splitlines()

11
web.py
View File

@ -312,8 +312,15 @@ class Shop(metaclass=PoolMeta):
products,
'products')
# TODO: Manage removed
# shop.products_removed = []
logger.info("Removing products for %s", shop.rec_name)
wcapi = shop.get_woocommerce_api()
# Rebrowse to get proper context
for removed in Product.browse(shop.products_removed):
shop.woocommerce_response(
wcapi.post('products/%d' % (removed.woocommerce_id),
removed.woocommerce_disable_data(shop)))
shop.products_removed = []
# TODO: Manage category removal
# shop.categories_removed = []
logger.info("Finised syncronization for %s", shop.rec_name)