kenkyhuang / shopify-dw

1 stars 0 forks source link

Order LIne function only brings back only one line item per order... #1

Open psm1963 opened 8 years ago

psm1963 commented 8 years ago

def order_line_json_to_flat(order, line):...function below...all else seems to work great with this code...

def order_line_json_to_flat(order, line):

fields = ['order_line_id',
          'order_id',
           'product_id',
           'sku_id',
           'fulfillment_id',
           'customer_id',
           'ordered_date_key',
           'sku_code',
           'quantity',
           'price',
           'gross_extended_price',
           'net_extended_price',
           'weight_in_grams',
           'weight_in_lbs',
           'fulfillment_status',
           'fulfillment_service',
           'currency',
           'oh_financial_status',
           'oh_fulfillment_status',
           'oh_created_on',
           'oh_updated_on',
           'oh_ordered_on',
           'oh_closed_on',
           'oh_cancelled_on']

d = {}

d['order_line_id'] = line['id']
d['order_id'] = order['id']
d['product_id'] = line['product_id']
d['sku_id'] = line['variant_id'] or "N/A"
d['customer_id'] = order['customer']['id']

d['fulfillment_id'] = 'N/A'
for f in order['fulfillments']:
    for li in f['line_items']:
        if li['id'] == line['id']:
            d['fulfillment_id'] = f['id']

ordered_dt = get_python_datetime_from_str(order['created_at'])
d['ordered_date_key'] = get_datekey_from_datetime(ordered_dt)

d['sku_code'] = line['sku']

# Facts
d['quantity'] = line['quantity']
d['price'] = line['price']
d['gross_extended_price'] = round(float(line['quantity']) * float(line['price']),2)
d['net_extended_price'] = d['gross_extended_price']
d['weight_in_grams'] = line['grams']
d['weight_in_lbs'] = round(line['grams']/453.592,2)

# Other
d['fulfillment_status'] = line['fulfillment_status'] or "unfulfilled"
d['fulfillment_service'] = line['fulfillment_service']
d['currency'] = order['currency']

d['oh_financial_status'] = order['financial_status']
d['oh_fulfillment_status'] = order.get('fulfillment_status', 'unfulfilled')

dates = {
        'oh_created': 'created_at',
        'oh_updated': 'updated_at', 
        'oh_ordered': 'created_at',
        'oh_closed': 'closed_at', 
        'oh_cancelled': 'cancelled_at'
        }

d = assign_date_attributes(order, d, dates)

"""
STEP 3: Convert python dictionary into a tab-delimited string.
"""
flat = '\t'.join([prepare_value(d.get(f, None)) for f in fields])

return flat    
psm1963 commented 8 years ago

Actually def sku_json_to_flat(data, product_data): only brings back the first variant for a particular product...wonderiing if I am doing something wrong or if there is a way to get all variants for a product and/or all line items for an order