Ejemplo n.º 1
0
def update_size_info(spid, sizes, prices):
    global PSDAO
    for size in sizes:
        for price in prices:
            if size["variantId"] == price["variantId"]:
                if not price["isInStock"]:
                    PSDAO.set_sku_out_of_stock(spid, size["size"])
                    print "".join([str(spid), ":", str(size["size"])])
                else:
                    psku = ProductSku()
                    psku.spid = spid
                    psku.size = size['size']
                    curr_price = price['price']['current']['value']
                    rrp_price = price['price']['rrp']['value']
                    previous_price = price['price']['previous']['value']
                    psku.discount_price = curr_price
                    if rrp_price == 0 and previous_price == 0:
                        psku.price = curr_price
                    else:
                        psku.price = rrp_price or previous_price
                    exists_id = PSDAO.get_id_by_spid_size(psku)
                    if exists_id is not None:
                        psku.spider_product_sku_id = exists_id
                        PSDAO.update_product_sku(psku)
                        print "".join([
                            str(spid), ":",
                            str(psku.spider_product_sku_id), ":", psku.size,
                            ":",
                            str(psku.price)
                        ])
Ejemplo n.º 2
0
 def ana_and_save_skus(self, spid, sku_info):
     # sku 信息在参数 SizesInformationViewModel 的 AvailableSizes中
     skus = sku_info["SizesInformationViewModel"]["AvailableSizes"]
     if len(skus) == 0:
         # 记录没有尺码的商品
         tipstr = "".join([str(spid), " no sku find!"])
         print tipstr
         self.log_info(tipstr)
         return
     psku = ProductSku()
     psku.spid = spid
     for sku in skus:
         # 尺码
         size_str = sku["Description"]
         # 尺码所属(国家标准)
         size_scale = sku["ScaleDescription"]
         if size_scale is not None:
             # 以 尺码[标准] 形式保存
             size_str = "".join([size_str, "[", size_scale, "]"])
         psku.size = size_str
         # 价格信息
         pinfo = sku["PriceInfo"]
         # 原价
         oprice = self.get_price_num(pinfo["FormatedPriceWithoutPromotion"])
         # 当前售价
         dprice = self.get_price_num(pinfo["FormatedPrice"])
         psku.discount_price = dprice
         if oprice is not None:
             psku.price = oprice
         else:
             psku.price = dprice
         # 保存
         self.save_product_skus(psku)
Ejemplo n.º 3
0
def save_product_sku(spid, p_variants, price_variants, psdao):
    psku = ProductSku()
    psku.spid = spid
    for provitem in p_variants:
        p_variant_id = provitem['variantId']
        for priceitem in price_variants:
            price_variant_id = priceitem['variantId']
            if p_variant_id == price_variant_id:
                psku.size = provitem['size']
                curr_price = priceitem['price']['current']['value']
                rrp_price = priceitem['price']['rrp']['value']
                previous_price = priceitem['price']['previous']['value']
                psku.discount_price = curr_price
                if rrp_price == 0 and previous_price == 0:
                    psku.price = curr_price
                else:
                    psku.price = rrp_price or previous_price
                exists_id = psdao.get_id_by_spid_size(psku)
                if exists_id is not None:
                    psku.spider_product_sku_id = exists_id
                    # psdao.update_product_sku(psku)
                    print "".join([str(exists_id), " sku is exists!"])
                else:
                    psdao.save(psku)