def add_product_to_cart(cart_name, product_id, quantity): method = f'carts/{cart_name}/items' payload = { 'data': { 'id': product_id, 'type': 'cart_item', 'quantity': quantity, } } moltin_requests.make_post_request(method, payload) moltin_logger.debug(f'Product was added to «{cart_name}» cart')
def create_customer(customer_info): payload = {'data': {'type': 'customer'}} payload['data'].update(customer_info) method = 'customers' response = moltin_requests.make_post_request(method, payload) moltin_logger.debug('Customer created') return response
def create_product(product_info): method = 'products' payload = {'data': {'type': 'product'}} payload['data'].update(product_info) product_info = moltin_requests.make_post_request( method, method_headers=APP_JSON_HEADER, payload=payload)['data'] moltin_logger.debug('Product created') return product_info
def create_file(filepath, public_status): method = 'files' with open(filepath, 'rb') as file: files = { 'file': (filepath, file), 'public': (None, public_status), } file_info = moltin_requests.make_post_request(method, files=files)['data'] moltin_logger.debug('File created') return file_info
def add_product_main_image(product_id, image_id): method = f'products/{product_id}/relationships/main-image' payload = { 'data': { 'type': "main_image", 'id': image_id, } } response = moltin_requests.make_post_request( method, method_headers=APP_JSON_HEADER, payload=payload) moltin_logger.debug('Main image was added') return response
def add_field_entry(entry_values, flow_slug): ''' entry_values = { 'entry-1-slug': 'entry_1_value', 'entry-2-slug': 'entry_2_value', ... } ''' method = f'flows/{flow_slug}/entries' payload = {'data': {'type': 'entry'}} payload['data'].update(entry_values) entry_info = moltin_requests.make_post_request(method, APP_JSON_HEADER, payload=payload)['data'] return entry_info
def create_flow(flow_info, enabled=True): ''' flow_info = { 'name': 'Flow name', 'description': 'Flow description', } ''' method = 'flows' flow_info.update({ 'slug': slugify(flow_info['name']), 'enabled': enabled, }) payload = {'data': {'type': 'flow'}} payload['data'].update(flow_info) flow_info = moltin_requests.make_post_request(method, APP_JSON_HEADER, payload=payload)['data'] return flow_info
def create_field(flow_id, name, description, field_type, required=False, unique=False, default=None, enabled=True, omit_null=False): ''' Field types: 'string', 'integer', 'boolean', 'float', 'date', 'relationship' ''' method = 'fields' slug = slugify(name) payload = { 'data': { 'type': 'field', 'name': name, 'slug': slug, 'description': description, 'field_type': field_type, 'required': required, 'unique': unique, 'enabled': enabled, 'omit_null': omit_null, 'relationships': { 'flow': { 'data': { 'type': 'flow', 'id': flow_id, } } } } } if not unique and default: payload['data']['default'] = default field_info = moltin_requests.make_post_request(method, APP_JSON_HEADER, payload=payload)['data'] return field_info