Initial support for basic WooCommerce integration
can export products to WooCommerce, plus maintain local cache, and track Woo ID for each rattail product
This commit is contained in:
commit
950a153342
24 changed files with 2214 additions and 0 deletions
0
rattail_woocommerce/db/__init__.py
Normal file
0
rattail_woocommerce/db/__init__.py
Normal file
|
@ -0,0 +1,152 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""initial WooCommerce-related tables
|
||||
|
||||
Revision ID: c0bcca7bd1f9
|
||||
Revises: a3a6e2f7c9a5
|
||||
Create Date: 2021-01-19 19:05:51.962092
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c0bcca7bd1f9'
|
||||
down_revision = None
|
||||
branch_labels = ('rattail_woocommerce',)
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
# woocommerce_product
|
||||
op.create_table('woocommerce_product',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('woocommerce_id', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['uuid'], ['product.uuid'], name='woocommerce_product_fk_product'),
|
||||
sa.PrimaryKeyConstraint('uuid')
|
||||
)
|
||||
op.create_table('woocommerce_product_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('woocommerce_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_woocommerce_product_version_end_transaction_id'), 'woocommerce_product_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_woocommerce_product_version_operation_type'), 'woocommerce_product_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_woocommerce_product_version_transaction_id'), 'woocommerce_product_version', ['transaction_id'], unique=False)
|
||||
|
||||
# woocommerce_cache_product
|
||||
op.create_table('woocommerce_cache_product',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('product_uuid', sa.String(length=32), nullable=True),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('slug', sa.String(length=100), nullable=True),
|
||||
sa.Column('permalink', sa.String(length=255), nullable=True),
|
||||
sa.Column('date_created', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_created_gmt', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_modified', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_modified_gmt', sa.DateTime(), nullable=True),
|
||||
sa.Column('type', sa.String(length=20), nullable=True),
|
||||
sa.Column('status', sa.String(length=20), nullable=True),
|
||||
sa.Column('featured', sa.Boolean(), nullable=True),
|
||||
sa.Column('catalog_visibility', sa.String(length=20), nullable=True),
|
||||
sa.Column('description', sa.String(length=255), nullable=True),
|
||||
sa.Column('short_description', sa.String(length=255), nullable=True),
|
||||
sa.Column('sku', sa.String(length=50), nullable=True),
|
||||
sa.Column('price', sa.String(length=20), nullable=True),
|
||||
sa.Column('regular_price', sa.String(length=20), nullable=True),
|
||||
sa.Column('sale_price', sa.String(length=20), nullable=True),
|
||||
sa.Column('date_on_sale_from', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_on_sale_from_gmt', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_on_sale_to', sa.DateTime(), nullable=True),
|
||||
sa.Column('date_on_sale_to_gmt', sa.DateTime(), nullable=True),
|
||||
sa.Column('price_html', sa.String(length=255), nullable=True),
|
||||
sa.Column('on_sale', sa.Boolean(), nullable=True),
|
||||
sa.Column('purchasable', sa.Boolean(), nullable=True),
|
||||
sa.Column('total_sales', sa.Integer(), nullable=True),
|
||||
sa.Column('tax_status', sa.String(length=20), nullable=True),
|
||||
sa.Column('tax_class', sa.String(length=50), nullable=True),
|
||||
sa.Column('manage_stock', sa.Boolean(), nullable=True),
|
||||
sa.Column('stock_quantity', sa.Integer(), nullable=True),
|
||||
sa.Column('stock_status', sa.String(length=20), nullable=True),
|
||||
sa.Column('backorders', sa.String(length=20), nullable=True),
|
||||
sa.Column('backorders_allowed', sa.Boolean(), nullable=True),
|
||||
sa.Column('backordered', sa.Boolean(), nullable=True),
|
||||
sa.Column('sold_individually', sa.Boolean(), nullable=True),
|
||||
sa.Column('weight', sa.String(length=20), nullable=True),
|
||||
sa.Column('reviews_allowed', sa.Boolean(), nullable=True),
|
||||
sa.Column('parent_id', sa.Integer(), nullable=True),
|
||||
sa.Column('purchase_note', sa.String(length=255), nullable=True),
|
||||
sa.Column('menu_order', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['product_uuid'], ['product.uuid'], name='woocommerce_cache_product_fk_product'),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='woocommerce_cache_product_uq_id')
|
||||
)
|
||||
op.create_table('woocommerce_cache_product_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('product_uuid', sa.String(length=32), autoincrement=False, nullable=True),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('slug', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('permalink', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('date_created', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('date_created_gmt', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('type', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('status', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('featured', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('catalog_visibility', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('description', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('short_description', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('sku', sa.String(length=50), autoincrement=False, nullable=True),
|
||||
sa.Column('price', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('regular_price', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('sale_price', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('date_on_sale_from', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('date_on_sale_from_gmt', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('date_on_sale_to', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('date_on_sale_to_gmt', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('price_html', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('on_sale', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('purchasable', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('tax_status', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('tax_class', sa.String(length=50), autoincrement=False, nullable=True),
|
||||
sa.Column('manage_stock', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('backorders', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('backorders_allowed', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('sold_individually', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('weight', sa.String(length=20), autoincrement=False, nullable=True),
|
||||
sa.Column('reviews_allowed', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('parent_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('purchase_note', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('menu_order', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_woocommerce_cache_product_version_end_transaction_id'), 'woocommerce_cache_product_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_woocommerce_cache_product_version_operation_type'), 'woocommerce_cache_product_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_woocommerce_cache_product_version_transaction_id'), 'woocommerce_cache_product_version', ['transaction_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
# woocommerce_cache_product
|
||||
op.drop_index(op.f('ix_woocommerce_cache_product_version_transaction_id'), table_name='woocommerce_cache_product_version')
|
||||
op.drop_index(op.f('ix_woocommerce_cache_product_version_operation_type'), table_name='woocommerce_cache_product_version')
|
||||
op.drop_index(op.f('ix_woocommerce_cache_product_version_end_transaction_id'), table_name='woocommerce_cache_product_version')
|
||||
op.drop_table('woocommerce_cache_product_version')
|
||||
op.drop_table('woocommerce_cache_product')
|
||||
|
||||
# woocommerce_product
|
||||
op.drop_index(op.f('ix_woocommerce_product_version_transaction_id'), table_name='woocommerce_product_version')
|
||||
op.drop_index(op.f('ix_woocommerce_product_version_operation_type'), table_name='woocommerce_product_version')
|
||||
op.drop_index(op.f('ix_woocommerce_product_version_end_transaction_id'), table_name='woocommerce_product_version')
|
||||
op.drop_table('woocommerce_product_version')
|
||||
op.drop_table('woocommerce_product')
|
182
rattail_woocommerce/db/model.py
Normal file
182
rattail_woocommerce/db/model.py
Normal file
|
@ -0,0 +1,182 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Database schema extensions for WooCommerce integration
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.db.model.shopfoo import ShopfooProductBase
|
||||
|
||||
|
||||
__all__ = [
|
||||
'WooProductExtension',
|
||||
'WooCacheProduct',
|
||||
]
|
||||
|
||||
|
||||
class WooProductExtension(model.Base):
|
||||
"""
|
||||
WooCommerce-specific extension to Rattail Product
|
||||
"""
|
||||
__tablename__ = 'woocommerce_product'
|
||||
__table_args__ = (
|
||||
sa.ForeignKeyConstraint(['uuid'], ['product.uuid'],
|
||||
name='woocommerce_product_fk_product'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
uuid = model.uuid_column(default=None)
|
||||
product = orm.relationship(
|
||||
model.Product,
|
||||
doc="""
|
||||
Reference to the actual product record, which this one extends.
|
||||
""",
|
||||
backref=orm.backref(
|
||||
'_woocommerce',
|
||||
uselist=False,
|
||||
cascade='all, delete-orphan',
|
||||
doc="""
|
||||
Reference to the WooCommerce extension record for this product.
|
||||
"""))
|
||||
|
||||
woocommerce_id = sa.Column(sa.Integer(), nullable=False, doc="""
|
||||
``id`` value for the product, within WooCommerce.
|
||||
""")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.product)
|
||||
|
||||
WooProductExtension.make_proxy(model.Product, '_woocommerce', 'woocommerce_id')
|
||||
|
||||
|
||||
class WooCacheProduct(ShopfooProductBase, model.Base):
|
||||
"""
|
||||
Local cache table for WooCommerce Products
|
||||
|
||||
https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties
|
||||
"""
|
||||
__tablename__ = 'woocommerce_cache_product'
|
||||
model_title = "WooCommerce Product"
|
||||
|
||||
@declared_attr
|
||||
def __table_args__(cls):
|
||||
return cls.__product_table_args__() + (
|
||||
sa.UniqueConstraint('id', name='woocommerce_cache_product_uq_id'),
|
||||
)
|
||||
|
||||
__versioned__ = {
|
||||
'exclude': [
|
||||
'date_modified',
|
||||
'date_modified_gmt',
|
||||
'total_sales',
|
||||
'stock_quantity',
|
||||
'stock_status',
|
||||
'backordered',
|
||||
]}
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
name = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
slug = sa.Column(sa.String(length=100), nullable=True)
|
||||
|
||||
permalink = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
date_created = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_created_gmt = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_modified = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_modified_gmt = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
type = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
status = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
featured = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
catalog_visibility = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
description = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
short_description = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
sku = sa.Column(sa.String(length=50), nullable=True)
|
||||
|
||||
price = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
regular_price = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
sale_price = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
date_on_sale_from = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_on_sale_from_gmt = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_on_sale_to = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
date_on_sale_to_gmt = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
price_html = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
on_sale = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
purchasable = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
total_sales = sa.Column(sa.Integer(), nullable=True)
|
||||
|
||||
tax_status = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
tax_class = sa.Column(sa.String(length=50), nullable=True)
|
||||
|
||||
manage_stock = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
stock_quantity = sa.Column(sa.Integer(), nullable=True)
|
||||
|
||||
stock_status = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
backorders = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
backorders_allowed = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
backordered = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
sold_individually = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
weight = sa.Column(sa.String(length=20), nullable=True)
|
||||
|
||||
reviews_allowed = sa.Column(sa.Boolean(), nullable=True)
|
||||
|
||||
parent_id = sa.Column(sa.Integer(), nullable=True)
|
||||
|
||||
purchase_note = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
menu_order = sa.Column(sa.Integer(), nullable=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name or ""
|
Loading…
Add table
Add a link
Reference in a new issue