Skip to content

Commit

Permalink
better omni bot
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed May 19, 2016
1 parent dd5a00a commit 1009082
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/budy/bots/omni_bot.py
Expand Up @@ -80,14 +80,19 @@ def sync_products(self):
if not merchandise: break
offset += len(merchandise)

parents = []

for merchandise in merchandise:
_class = merchandise["_class"]
is_product = _class in ("Product",)
is_sub_product = _class in ("SubProduct",)
is_valid = is_product or is_sub_product
if not is_valid: continue
if is_product: self.sync_product(merchandise)
else: self.sync_sub_product(merchandise)
else: self.sync_sub_product(merchandise, parents = parents)

for _object_id, merchandise in appier.legacy.iteritems(parents):
self.sync_product(merchandise)

def sync_product(self, merchandise):
# retrieves the reference to the api object that is
Expand Down Expand Up @@ -156,7 +161,7 @@ def sync_product(self, merchandise):
product.images.append(_media)
product.save()

def sync_sub_product(self, merchandise):
def sync_sub_product(self, merchandise, parents = []):
api = self.get_api()

object_id = merchandise["object_id"]
Expand All @@ -172,6 +177,11 @@ def sync_sub_product(self, merchandise):

if not measurement: return

# adds the (parent) product reference to the map of
# parents that may be used latter for extra sync, this
# is required otherwise out of sync errors may occur
parents[product["object_id"]] = product

measurement.save()

parent = measurement.product
Expand Down

0 comments on commit 1009082

Please sign in to comment.