Exemplo n.º 1
0
def item_groups_post(request):
    """Create new item group entities

       request body :

       * item_groups : Sequence of ItemGroup
    """

    save_in_webshop = request.validated.get("save_in_webshop", True)
    appstructs = request.validated["item_groups"]
    item_groups = utils.store(appstructs, models.ItemGroup, "item_groups",
                              request)
    if save_in_webshop:
        with magentoapi.ItemGroups(request) as proxy:
            try:
                # create item_groups in webshop
                webshop_ids = proxy.create(appstructs)
                utils.set_webshop_ids(item_groups, webshop_ids)
                # activate categories in webshop shops
                proxy.update_shops(webshop_ids, appstructs)
                # link item_group parents in webshop
                proxy.link_item_parents(webshop_ids, appstructs)
                # link item_group children in webshop
                item_webshop_ids, items = utils.get_entities_item_children(
                    item_groups, request)
                proxy.link_item_parents(item_webshop_ids, items)
            except exceptions._502 as e:
                proxy.delete([x for x in e.success if isinstance(x, int)])
                raise
        magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}
Exemplo n.º 2
0
 def test_load_create_items_time_10(self):
     import time
     from organicseeds_webshop_api import magentoapi
     proxy = self.items_proxy
     start = time.time()
     appstruct = self.testdata["items"][0]
     appstructs = []
     items = []
     for x in range(0, 10):
         appstruct_ = copy.deepcopy(appstruct)
         appstruct_["id"] = u"id" + str(x)
         appstruct_["sku"] = u"sku" + str(x)
         appstruct_["title"]["default"] = u"title" + str(x)
         appstruct_["title"]["fr"] = u"titlefr" + str(x)
         appstruct_["title"]["de"] = u"titlede" + str(x)
         appstructs.append(appstruct_)
         items.append(create_item(appstruct_, self.request))
     print("\ncreating items")
     magentoapi.indexing_enable_manual(self.request)
     webshop_ids = proxy.create(appstructs)
     for i, webshop_id in enumerate(webshop_ids):
         items[i].webshop_id = webshop_id
     print("\nupdateing items")
     proxy.update_shops(webshop_ids, appstructs)
     print("\nlinking item parents")
     proxy.link_item_parents(webshop_ids, appstructs)
     end = time.time()
     magentoapi.indexing_reindex(self.request)
     print("\n\nTime to create 10 items:")
     print(end - start)
     print("\n")
Exemplo n.º 3
0
def item_groups_delete(request):
    """Delete item group entities
    """

    utils.delete_all("item_groups", request)
    with magentoapi.ItemGroups(request) as proxy:
        proxy.delete_all()
    magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}
Exemplo n.º 4
0
def categories_delete(request):
    """Delete category entities.
       You should delete item_group children first.
    """

    utils.delete_all("categories", request)
    with magentoapi.Categories(request) as proxy:
        proxy.delete_all()
    magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}
Exemplo n.º 5
0
def items_delete(request):
    """Delete item entities
    """

    utils.delete_all("items", request)
    magentoapi.indexing_enable_manual(request)
    with magentoapi.Items(request) as proxy:
        proxy.delete_all()
    magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}
Exemplo n.º 6
0
def items_put(request):
    """Update existing item entities

       request body :

       * items: Sequence of ItemUpdate
    """
    save_in_webshop = request.validated.get("save_in_webshop", True)
    appstructs = utils.remove_none_values(request.validated["items"])
    utils.store(appstructs, models.Item, "items", request)
    items = request.root.app_root["items"]
    if save_in_webshop:
        magentoapi.indexing_enable_manual(request)
        with magentoapi.Items(request) as proxy:
            webshop_ids = []
            for a in appstructs:
                webshop_id = items[a["id"]].webshop_id
                webshop_ids.append(webshop_id)
            proxy.update(appstructs)
            proxy.update_shops(webshop_ids, appstructs)
            magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}
Exemplo n.º 7
0
def items_post(request):
    """Create new item entities

       body :

       * Sequence of Item
    """
    save_in_webshop = request.validated.get("save_in_webshop", True)
    appstructs = request.validated["items"]
    items = utils.store(appstructs, models.Item, "items", request)
    if save_in_webshop:
        magentoapi.indexing_enable_manual(request)
        with magentoapi.Items(request) as proxy:
            try:
                webshop_ids = proxy.create(appstructs)
                utils.set_webshop_ids(items, webshop_ids)
                proxy.update_shops(webshop_ids, appstructs)
                proxy.link_item_parents(webshop_ids, appstructs)
            except exceptions._502 as e:
                proxy.delete([x for x in e.success if isinstance(x, int)])
                raise
        magentoapi.indexing_reindex(request)
    return {"status": "succeeded"}