Jump to content

Repo comfac-webshop EntryPoints

From Game in the Brain Wiki
Revision as of 16:33, 9 March 2026 by Ocjustin260223 (talk | contribs) ("Repo analysis: comfac-hrms and comfac-webshop (14 pages)")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Repo:comfac-webshop/EntryPoints — Application Entry Points

How This App Starts

Installation & Startup

Frappe Webshop is a standard Frappe app that hooks into the framework:

  1. Bench loads the app via webshop/__init__.py
  2. Hooks (webshop/hooks.py) register with Frappe
  3. Website routes are registered for storefront pages
  4. DocTypes are synced to database

Key Commands

Command Purpose
bench --site [site] install-app webshop Install webshop on a site
bench --site [site] migrate Sync DocTypes, run patches
bench build Compile SCSS to CSS
bench start Start development server

Main Config Files

hooks.py

Location: webshop/hooks.py

Key configurations:

Config Section What It Controls
required_apps Dependencies: payments, erpnext
web_include_js/css Assets loaded on every web page
website_generators Auto-created pages (Website Item, Item Group)
override_doctype_class Python class overrides for Item, Item Group, Payment Request
doc_events Sync Item changes to Website Item
on_session_creation Initialize cart when user logs in
update_website_context Add cart data to all template contexts

Webshop Settings (DocType)

Location: Frappe Desk → Webshop Settings

Critical settings configured via UI:

Setting Purpose
Enabled Turn store on/off
Price List Which ERPNext Price List to use
Default Shopping Cart Company Company for quotations
Default Currency Currency for display
Enable Wishlist Feature toggle
Show Stock Availability Display stock levels
Redirect to Checkout on Add to Cart Behavior setting

Environment Variables

Standard Frappe environment variables apply:

Variable Purpose
FRAPPE_BENCH_ROOT Bench installation path

Webshop-specific context is set in update_website_context hook.

How to Verify It's Running Correctly

Health Checks

  1. Webshop Settings: Frappe Desk → Webshop Settings → Verify "Enabled" is checked
  2. Price List: Verify a Price List is selected and has items
  3. Website Items: Create/publish at least one Website Item
  4. Storefront: Visit /all-products — should see product listing
  5. Item Page: Click a product — should see detail page
  6. Cart: Add item to cart — cart count should update

Log Locations

Log Type Location
Frappe web logs logs/web.log or docker logs
Browser console F12 → Console (JavaScript errors)

Common Issues

Symptom Likely Cause Fix
/all-products 404 Website generator not synced Run bench migrate No products showing No published Website Items Create Website Items Cart not working Missing Price List Configure Webshop Settings Styles missing Assets not built Run bench build Images not loading File permissions Check sites/[site]/public/files/

Request/Task Flow

Example: Adding Item to Cart

  1. User Action: Clicks "Add to Cart" on product page
  2. Client-Side: JavaScript calls webshop.webshop.shopping_cart.cart.add_to_cart
  3. API Handler: cart.py::add_to_cart() whitelisted function
  4. Quotation Creation: Gets or creates cart Quotation for user
  5. Quotation Item: Adds Item to Quotation.items child table
  6. Save: Saves Quotation (draft state)
  7. Cookie Update: Updates cart_count cookie
  8. Response: Returns updated cart info
  9. UI Update: Cart icon shows updated count

Example: Product Page Display

  1. URL Request: /item/[website-item-name]
  2. Route Resolution: Frappe matches website_generators pattern
  3. Permission Check: has_website_permission hook validates access
  4. Context Building: WebsiteItem.get_context() prepares data
  5. Template Rendering: templates/webshop/website_item.html rendered
  6. Response: Full HTML page with product details

Example: Checkout Process

  1. Cart Review: User reviews cart at /cart
  2. Address Selection: User selects/changes shipping/billing address
  3. Shipping Rule: Available shipping options calculated
  4. Place Order: Cart Quotation converted to Sales Order
  5. Payment: Payment Request created, redirected to payment gateway
  6. Confirmation: On payment success, order confirmed
  7. Email: Order confirmation email sent

Integration Points

ERPNext Integration

ERPNext DocType Webshop Usage
Item Source for Website Item
Item Group Product categories
Quotation Shopping cart storage
Sales Order Final order creation
Price List Product pricing
Address Customer shipping/billing
Customer Registered shoppers

Website Routes

Route Handler
/all-products Product listing with filters
/item/<name> Individual product page (website generator)
/cart Shopping cart
/checkout Checkout flow
/orders Order history
/wishlist Saved items

API Endpoints (Whitelisted)

Endpoint Purpose
get_cart_quotation Get current cart data
add_to_cart Add item to cart
update_cart Update quantities
place_order Convert cart to order
get_product_info Get item availability/pricing