Created
November 28, 2018 10:39
-
-
Save mumin91/46f4392e8bbeaeb3afa4fe32a971277d to your computer and use it in GitHub Desktop.
Then trying to get user data through WP API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_data(request, user_id, nons): | |
| customer = services.wc_api_call('customers/' + user_id).json() | |
| print(nons) | |
| print(customer) | |
| print(customer['email']) | |
| obj, created = CustomUser.objects.get_or_create(password=make_password("1234567"), | |
| is_superuser=False, | |
| username=customer['username'], | |
| first_name= customer['first_name'], | |
| last_name= customer['last_name'], | |
| email= customer['email'], | |
| is_staff=False, | |
| is_active=True, | |
| mail_subscription=True) | |
| login(request, obj) | |
| investments = services.wc_api_call("orders?customer=" + user_id).json() | |
| print(investments) | |
| total_investment = 0.00 | |
| for line_items in investments: | |
| investment_id = line_items['id'] | |
| investment_date = line_items['date_created'] | |
| investment_currency = line_items['currency'] | |
| for line_item in line_items['line_items']: | |
| line_item_name = line_item['name'] | |
| line_item_product_id = line_item['product_id'] | |
| line_item_total = line_item['total'] | |
| total_investment += float(line_item_total) | |
| obj, created = Investment.objects.get_or_create(investment_id=investment_id, | |
| name=line_item_name, | |
| date_created=investment_date, | |
| principle=line_item_total, | |
| currency_pledged=investment_currency, | |
| product_id=line_item_product_id) | |
| obj.save() | |
| return redirect('home') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment