Sync Products and Orders to e-conomic from magento 1.9.* using APIs of each system. The solution is created to one specific use case and may set certain attributes to constants - it would likely have to be adapted to work correctly for other shops.
Navigate to a folder where the folder with the code should be located.
git clone https://github.com/martinskeem/magento-economics-sync.git
create virtual environment
cd magento-economics-sync
virtualenv . -p /usr/bin/python3`
activate the virtual environment
source bin/activate
install dependencies
pip install -r requirements.txt
create log folder
mkdir log
In order for the synchronization scripts to work, various configuration variables need to be set in a file named secrets.py
. Add the file to the root of the project folder and use below template:
magento_api_xmlrpc_url = "" # url for magento api. E.g. "https://host/index.php/api/xmlrpc?type=xmlrpc"
magento_api_user = "" # xmlrpc api user
magento_api_pass = "" # xmlrpc api user password
# secrets obtained from economics administrative user interface
economics_headers = {'X-AppSecretToken': '',
'X-AgreementGrantToken': '',
'Content-Type': 'application/json'}
The script Synchronizes changes done last day by default (this can be changed in sync.py
with the delta_load_days parameter
). If the job is scheduled to more than once per day (e.g. every 30 minutes), this is sufficient. Later, this may be updated to handle delta load more elegantly by maintaining state of already synchronized entities. Example crontab schedule that synchronizes data every 30 minutes:
/30 * * * * /var/python/magento-economics-sync/bin/python /var/python/magento-economics-sync/sync.py
Emits logging to console and flat file in subfolder /log
. This can be configured in logging.conf
.
Some API end points (which are unlikely to require changing) and some default values use for VAT Zone, Customer Groups, Payment Terms etc. These are hardcoded constants - and may have to be configured differently for other shops.
roducts_url = 'https://restapi.e-conomic.com/products'
product_url = 'https://restapi.e-conomic.com/products/{0}'
customers_url = 'https://restapi.e-conomic.com/customers'
customer_url = 'https://restapi.e-conomic.com/customers/{0}'
invoice_url = 'https://restapi.e-conomic.com/invoices/drafts/{0}'
invoices_url = 'https://restapi.e-conomic.com/invoices/drafts'
customer_vatzone = 1
customer_group = 3
customer_paymentterms = 5
invoice_layout = 18
invoice_shipping_product_id = 'Fragt'
invoice_vat_reverse_rate = .8
product_group = 6000