Integrations

Integrations

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

Building a New Provider

Building a New Provider

1. App Structure

provider_integration/
├── provider_integration/
│   ├── hooks.py
│   ├── controllers/
│   │   ├── __init__.py
│   │   ├── setting.py          # Extend SettingController
│   │   ├── inventory.py       # Inventory sync logic
│   │   └── orders.py          # Order processing
│   ├── doctype/
│   │   └── provider_settings/ # Settings doctype
│   └── utils/
│       ├── api.py             # Platform API client
│       └── mapping.py         # Field mapping utilities

2. Settings Doctype

Create Provider Settings doctype extending SettingController:

from ecommerce_core.controllers.setting import SettingController

class ProviderSettings(SettingController):
    def is_enabled(self) -> bool:
        return self.enable_integration
    
    def get_erpnext_warehouses(self) -> list[ERPNextWarehouse]:
        return [wh.warehouse for wh in self.warehouse_mapping]
    
    def get_erpnext_to_integration_wh_mapping(self) -> dict:
        return {wh.warehouse: wh.integration_warehouse for wh in self.warehouse_mapping}

3. API Integration

Implement platform-specific API client:

import requests

class ProviderAPI:
    def __init__(self, settings):
        self.base_url = settings.api_endpoint
        self.auth_token = settings.get_password("api_token")
    
    def get_items(self):
        """Fetch items from platform."""
        response = requests.get(
            f"{self.base_url}/items",
            headers={"Authorization": f"Bearer {self.auth_token}"}
        )
        return response.json()
    
    def update_inventory(self, sku, quantity):
        """Update inventory on platform."""
        requests.post(
            f"{self.base_url}/inventory",
            json={"sku": sku, "quantity": quantity},
            headers={"Authorization": f"Bearer {self.auth_token}"}
        )

4. Scheduled Jobs

Create scheduled tasks in hooks.py:

# In provider_integration/hooks.py
scheduler_events = {
    "cron": {
        "*/5 * * * *": "provider_integration.tasks.sync_inventory",
        "0 */2 * * *": "provider_integration.tasks.fetch_orders"
    }
}

5. Utility Integration

Leverage core utilities for common operations:

from ecommerce_core.utils.taxation import get_dummy_tax_category
from ecommerce_core.utils.price_list import get_dummy_price_list
from ecommerce_core.utils.address_mapping import map_address
from ecommerce_core.utils.naming_series import generate_name
Last updated 2 weeks ago
Was this helpful?
Thanks!