From 4a7544f6fffe60ebd4c526c2277eaed34064c7c6 Mon Sep 17 00:00:00 2001 From: Sergio Villasenor <42443963+thatotherkid86@users.noreply.github.com> Date: Wed, 4 Mar 2020 19:59:04 -0800 Subject: [PATCH] Updated handling of Shopify Price & Compare Price MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated logic: Shopify “Compare Price” is the default Base Price in CSV, if it is empty, then Shopify “Price” is the Base Price. If “Compare Price” is empty, & only “Price” exists, the Base Price in the CSV is that value and Sale Price is null. If “Compare Price” is greater than the “Price”, then Base Price in the CSV is “Compare Price” and the Sale Price in the CSV is “Price”. If “Compare Price” and “Price” are equal, the Base Price will inherit the equal value & Sale Price is null. --- shopify.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/shopify.py b/shopify.py index 40e0368..8d9aca5 100644 --- a/shopify.py +++ b/shopify.py @@ -365,9 +365,33 @@ def get_product_row(i,metafields): if 'weight_unit' in k: unit_of_weight = k['weight_unit'] weight = k['weight'] - return [ k['price'] if 'price' in k else '', k['compare_at_price'] if 'compare_at_price' in k else (k['price'] if 'price' in k else '') , quantity , format_unit_weight(unit_of_weight) , weight if weight else '1' , "IN" , "3" , "3" , "3" ,seo_title,seo_desc ] + base_price = k['compare_at_price'] if 'compare_at_price' in k else '' + if(base_price == '' or base_price==None): base_price = k['price'] if 'price' in k else '' + sale_price = k['price'] if base_price!='' else '' + try: + if(base_price != '' and sale_price != '' and float(base_price) < float(sale_price)): + tmp_var = sale_price + sale_price = base_price + base_price = tmp_var + except Exception as e: + pass + if sale_price == base_price: + sale_price = '' + return [ base_price, sale_price , quantity , format_unit_weight(unit_of_weight) , weight if weight else '1' , "IN" , "3" , "3" , "3" ,seo_title,seo_desc ] else: - return [ i['price'] if 'price' in i else '', i['compare_at_price'] if 'compare_at_price' in i else (i['price'] if 'price' in i else '') , quantity , format_unit_weight(unit_of_weight) , weight if weight else '1' , "IN" , "3" , "3" , "3" ,seo_title,seo_desc ] + base_price = i['compare_at_price'] if 'compare_at_price' in i else '' + if(base_price == '' or base_price==None): base_price = i['price'] if 'price' in i else '' + sale_price = i['price'] if base_price!='' else '' + try: + if(base_price != '' and sale_price != '' and float(base_price) < float(sale_price)): + tmp_var = sale_price + sale_price = base_price + base_price = tmp_var + except Exception as e: + pass + if sale_price == base_price: + sale_price = '' + return [ base_price, sale_price , quantity , format_unit_weight(unit_of_weight) , weight if weight else '1' , "IN" , "3" , "3" , "3" ,seo_title,seo_desc ] if __name__ == '__main__': parser = argparse.ArgumentParser()