def delete_a_customer(customer_id): session = shopify.Session(shop_url, api_version, access_token) shopify.ShopifyResource.activate_session(session) try: customer = shopify.Customer().find(customer_id) customer.destroy() except: print("Failed to delete")
def edit_a_customer(customer_id, **kwargs): session = shopify.Session(shop_url, api_version, access_token) shopify.ShopifyResource.activate_session(session) customer = shopify.Customer().find(customer_id) for key, value in kwargs.items(): setattr(customer, key, value) result = customer.save() print(result)
def create_a_customer(**kwargs): session = shopify.Session(shop_url, api_version, access_token) shopify.ShopifyResource.activate_session(session) new_customer = shopify.Customer() for key, value in kwargs.items(): setattr(new_customer, key, value) new_customer.save() print(new_customer.to_dict())
def test_create_customer(self): self.fake("customers", method="POST", body=self.load_fixture("customer"), headers={"Content-type": "application/json"}) customer = shopify.Customer() customer.first_name = "Bob" customer.last_name = "Lastnameson" customer.email = "*****@*****.**" customer.verified_email = True customer.password = "******" customer.password_confirmation = "newpass" self.assertEqual("newpass", customer.attributes["password"]) customer.save() self.assertEqual("Bob", customer.first_name) self.assertEqual("newpass", customer.attributes["password"])
def test_create_customer(self): self.fake("customers", method='POST', body=self.load_fixture('customer'), headers={'Content-type': 'application/json'}) customer = shopify.Customer() customer.first_name = 'Bob' customer.last_name = 'Lastnameson' customer.email = '*****@*****.**' customer.verified_email = True customer.password = "******" customer.password_confirmation = "newpass" self.assertEqual("newpass", customer.attributes['password']) customer.save() self.assertEqual("Bob", customer.first_name) self.assertEqual("newpass", customer.attributes['password'])
def create(self, number_customers): customers_created = [] for counter in range(number_customers): print("Generating Customer: {0}".format(str(counter + 1))) new_customer = shopify.Customer().create(self.generate_data()) if new_customer.errors: # something went wrong! for message in new_customer.errors.full_messages(): print(message) return customers_created.append(str(new_customer.id)) with open('stdg-customers.csv', mode='a') as customers_file: customers_file.write('\n'.join(customers_created) + '\n') return
def single_draft(customer: Customer): order = shopify.DraftOrder({ 'email': customer.data['email'], 'customer': shopify.Customer({ 'email': customer.data['email'], 'first_name': name_split(customer.data['shipping_details']['name']), 'last_name': name_split(customer.data['shipping_details']['name'], False), 'phone': customer.data['shipping_details']['phone_number'] }), 'shipping_address': shopify.ShippingAddress({ 'address1': customer.data['shipping_details']['address1'], 'address2': customer.data['shipping_details']['address2'] or '', 'city': customer.data['shipping_details']['city'], 'country': customer.data['shipping_details']['country_name'], 'name': customer.data['shipping_details']['name'], 'phone': customer.data['shipping_details']['phone_number'], 'zip': customer.data['shipping_details']['postal_code'], 'province': customer.data['shipping_details']['state'] or '', 'first_name': name_split(customer.data['shipping_details']['name']), 'last_name': name_split(customer.data['shipping_details']['name'], False) }), 'billing_address': shopify.BillingAddress({ 'address1': customer.data['shipping_details']['address1'], 'address2': customer.data['shipping_details']['address2'] or '', 'city': customer.data['shipping_details']['city'], 'country': customer.data['shipping_details']['country_name'], 'name': customer.data['shipping_details']['name'], 'phone': customer.data['shipping_details']['phone_number'], 'zip': customer.data['shipping_details']['postal_code'], 'province': customer.data['shipping_details']['state'] or '', 'first_name': name_split(customer.data['shipping_details']['name']), 'last_name': name_split(customer.data['shipping_details']['name'], False) }), 'line_items': [ shopify.LineItem({ 'title': str(tuple(customer.line_info.keys())[0]), 'price': "%.2f" % (tuple(customer.line_info.values())[0]), 'quantity': 1, 'taxable': False, 'requires_shipping': True, 'applied_discount': { 'title': "Custom", 'description': "Pre-order", 'value_type': "percentage", 'value': "100.0", 'amount': "%.2f" % (tuple(customer.line_info.values())[0]) } }) ], 'tax_exempt': True, 'note': b"Nyahallo there, thank you so much for supporting my first launch \u2764 These are the shipping costs ^^" .decode('unicode-escape'), 'shipping_line': shopify.ShippingLine({ 'handle': None, 'title': find_shipping_title( customer.data['shipping_details']['country_name']), 'price': find_shipping_price( customer.data['shipping_details']['country_name'], tuple(customer.line_info.values())[0]) }) }) return order