diff --git a/crud.py b/crud.py
index 986b7b5..e8ab117 100644
--- a/crud.py
+++ b/crud.py
@@ -292,8 +292,8 @@ async def create_product(merchant_id: str, data: PartialProduct) -> Product:
await db.execute(
f"""
INSERT INTO nostrmarket.products
- (merchant_id, id, stall_id, name, price, quantity, pending, event_id, event_created_at, image_urls, category_list, meta)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ (merchant_id, id, stall_id, name, price, quantity, active, pending, event_id, event_created_at, image_urls, category_list, meta)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO NOTHING
""",
(
@@ -303,6 +303,7 @@ async def create_product(merchant_id: str, data: PartialProduct) -> Product:
data.name,
data.price,
data.quantity,
+ data.active,
data.pending,
data.event_id,
data.event_created_at,
@@ -321,13 +322,14 @@ async def update_product(merchant_id: str, product: Product) -> Product:
await db.execute(
f"""
- UPDATE nostrmarket.products set name = ?, price = ?, quantity = ?, pending = ?, event_id =?, event_created_at = ?, image_urls = ?, category_list = ?, meta = ?
+ UPDATE nostrmarket.products set name = ?, price = ?, quantity = ?, active = ?, pending = ?, event_id =?, event_created_at = ?, image_urls = ?, category_list = ?, meta = ?
WHERE merchant_id = ? AND id = ?
""",
(
product.name,
product.price,
product.quantity,
+ product.active,
product.pending,
product.event_id,
product.event_created_at,
@@ -385,7 +387,7 @@ async def get_products_by_ids(
q = ",".join(["?"] * len(product_ids))
rows = await db.fetchall(
f"""
- SELECT id, stall_id, name, price, quantity, category_list, meta
+ SELECT id, stall_id, name, price, quantity, active, category_list, meta
FROM nostrmarket.products
WHERE merchant_id = ? AND pending = false AND id IN ({q})
""",
diff --git a/migrations.py b/migrations.py
index aa2ec04..005913e 100644
--- a/migrations.py
+++ b/migrations.py
@@ -172,4 +172,9 @@ async def m003_update_direct_message_type(db):
async def m004_add_merchant_timestamp(db):
await db.execute(
f"ALTER TABLE nostrmarket.merchants ADD COLUMN time TIMESTAMP;"
+ )
+
+async def m005_update_product_activation(db):
+ await db.execute(
+ "ALTER TABLE nostrmarket.products ADD COLUMN active BOOLEAN NOT NULL DEFAULT true;"
)
\ No newline at end of file
diff --git a/models.py b/models.py
index effd7f9..be04ea5 100644
--- a/models.py
+++ b/models.py
@@ -236,6 +236,7 @@ class PartialProduct(BaseModel):
images: List[str] = []
price: float
quantity: int
+ active: bool = True
pending: bool = False
config: ProductConfig = ProductConfig()
@@ -257,20 +258,24 @@ def to_nostr_event(self, pubkey: str) -> NostrEvent:
"currency": self.config.currency,
"price": self.price,
"quantity": self.quantity,
+ "active": self.active,
"shipping": [dict(s) for s in self.config.shipping or []]
}
categories = [["t", tag] for tag in self.categories]
- event = NostrEvent(
- pubkey=pubkey,
- created_at=round(time.time()),
- kind=30018,
- tags=[["d", self.id]] + categories,
- content=json.dumps(content, separators=(",", ":"), ensure_ascii=False),
- )
- event.id = event.event_id
+ if self.active:
+ event = NostrEvent(
+ pubkey=pubkey,
+ created_at=round(time.time()),
+ kind=30018,
+ tags=[["d", self.id]] + categories,
+ content=json.dumps(content, separators=(",", ":"), ensure_ascii=False),
+ )
+ event.id = event.event_id
- return event
+ return event
+ else:
+ return self.to_nostr_delete_event(pubkey)
def to_nostr_delete_event(self, pubkey: str) -> NostrEvent:
delete_event = NostrEvent(
diff --git a/static/components/stall-details/stall-details.html b/static/components/stall-details/stall-details.html
index 1a16461..bb07526 100644
--- a/static/components/stall-details/stall-details.html
+++ b/static/components/stall-details/stall-details.html
@@ -100,6 +100,16 @@
+
+
+
{{props.row.id}}
{{shortLabel(props.row.name)}}
diff --git a/static/components/stall-details/stall-details.js b/static/components/stall-details/stall-details.js
index 32fcad5..8a6cf8c 100644
--- a/static/components/stall-details/stall-details.js
+++ b/static/components/stall-details/stall-details.js
@@ -40,6 +40,12 @@ async function stallDetails(path) {
label: '',
field: ''
},
+ {
+ name: 'activate',
+ align: 'left',
+ label: '',
+ field: ''
+ },
{
name: 'id',