feat: make Product fully independent from MarketplaceProduct
- Add is_digital and product_type columns to Product model - Remove is_digital/product_type properties that derived from MarketplaceProduct - Update Create form with translation tabs, GTIN type, sale price, VAT rate, image - Update Edit form to allow editing is_digital (remove disabled state) - Add Availability field to Edit form - Fix Detail page for directly created products (no marketplace source) - Update vendor_product_service to handle new fields in create/update - Add VendorProductCreate/Update schema fields for translations and is_digital - Add unit tests for is_digital column and direct product creation - Add integration tests for create/update API with new fields - Create product-architecture.md documenting the independent copy pattern - Add migration y3d4e5f6g7h8 for is_digital and product_type columns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
114
static/vendor/js/product-create.js
vendored
Normal file
114
static/vendor/js/product-create.js
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
// static/vendor/js/product-create.js
|
||||
/**
|
||||
* Vendor product creation page logic
|
||||
*/
|
||||
|
||||
const vendorProductCreateLog = window.LogConfig.loggers.vendorProductCreate ||
|
||||
window.LogConfig.createLogger('vendorProductCreate', false);
|
||||
|
||||
vendorProductCreateLog.info('Loading...');
|
||||
|
||||
function vendorProductCreate() {
|
||||
vendorProductCreateLog.info('vendorProductCreate() called');
|
||||
|
||||
return {
|
||||
// Inherit base layout state
|
||||
...data(),
|
||||
|
||||
// Set page identifier
|
||||
currentPage: 'products',
|
||||
|
||||
// Back URL
|
||||
get backUrl() {
|
||||
return `/vendor/${this.vendorCode}/products`;
|
||||
},
|
||||
|
||||
// Loading states
|
||||
loading: false,
|
||||
saving: false,
|
||||
error: '',
|
||||
|
||||
// Form data
|
||||
form: {
|
||||
title: '',
|
||||
brand: '',
|
||||
vendor_sku: '',
|
||||
gtin: '',
|
||||
price: '',
|
||||
currency: 'EUR',
|
||||
availability: 'in_stock',
|
||||
is_active: true,
|
||||
is_featured: false,
|
||||
is_digital: false,
|
||||
description: ''
|
||||
},
|
||||
|
||||
async init() {
|
||||
// Guard against duplicate initialization
|
||||
if (window._vendorProductCreateInitialized) return;
|
||||
window._vendorProductCreateInitialized = true;
|
||||
|
||||
vendorProductCreateLog.info('Initializing product create page...');
|
||||
|
||||
try {
|
||||
// IMPORTANT: Call parent init first to set vendorCode from URL
|
||||
const parentInit = data().init;
|
||||
if (parentInit) {
|
||||
await parentInit.call(this);
|
||||
}
|
||||
|
||||
vendorProductCreateLog.info('Product create page initialized');
|
||||
} catch (err) {
|
||||
vendorProductCreateLog.error('Failed to initialize:', err);
|
||||
this.error = err.message || 'Failed to initialize';
|
||||
}
|
||||
},
|
||||
|
||||
async createProduct() {
|
||||
if (!this.form.title || !this.form.price) {
|
||||
this.showToast('Title and price are required', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
this.saving = true;
|
||||
this.error = '';
|
||||
|
||||
try {
|
||||
// Create product directly (vendor_id from JWT token)
|
||||
const response = await apiClient.post('/vendor/products/create', {
|
||||
title: this.form.title,
|
||||
brand: this.form.brand || null,
|
||||
vendor_sku: this.form.vendor_sku || null,
|
||||
gtin: this.form.gtin || null,
|
||||
price: parseFloat(this.form.price),
|
||||
currency: this.form.currency,
|
||||
availability: this.form.availability,
|
||||
is_active: this.form.is_active,
|
||||
is_featured: this.form.is_featured,
|
||||
description: this.form.description || null
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.message || 'Failed to create product');
|
||||
}
|
||||
|
||||
vendorProductCreateLog.info('Product created:', response.data);
|
||||
this.showToast('Product created successfully', 'success');
|
||||
|
||||
// Navigate back to products list
|
||||
setTimeout(() => {
|
||||
window.location.href = this.backUrl;
|
||||
}, 1000);
|
||||
|
||||
} catch (err) {
|
||||
vendorProductCreateLog.error('Failed to create product:', err);
|
||||
this.error = err.message || 'Failed to create product';
|
||||
this.showToast(this.error, 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vendorProductCreateLog.info('Loaded successfully');
|
||||
Reference in New Issue
Block a user