PolyStore Checkout, Orders, Invoices, Coupons & B2B Quotes Sync in Perfex CRM
PolyStore v1.0.0 (bundled with PolyCMS v1.4.0+) unifies e-commerce order-to-cash and B2B quote-to-cash directly inside Perfex CRM without external sync bridges, third-party middleware, or duplicate accounting ledgers. Powered by Polystore_Checkout, Polystore_Orders, Polystore_Payments, Polystore_Perfex_Hooks, Polystore_Coupons, and Polystore_Analytics, every storefront transaction automatically generates native Perfex Invoices or Estimates, inherits 100% of active Perfex payment gateways, prevents overselling with InnoDB SELECT ... FOR UPDATE row-level locks, synchronizes status updates bidirectionally across 6 CRM lifecycle hooks, evaluates 5 promotional coupon types including BOGO and Customer Group rules, dispatches 9 customizable Perfex email templates with 27 merge fields, and aggregates revenue telemetry in O(1) PHP memory via SQL GROUP BY.
Persistent Shopping Carts and Seamless Login Merge
Before a buyer ever reaches /checkout, PolyStore preserves cart state inside tblpolystore_carts so multi-variant selections, quantities, and applied promo codes survive browser refreshes and cross-session visits.
When a returning customer adds items as a guest and subsequently signs into their Perfex CRM Contact account, PolyStore listens on the contact_logged_in hook and merges their guest session cart into their authenticated account cart automatically. Buyers never lose selected SKUs when transitioning from anonymous browsing to account checkout, and B2B buyers can immediately unlock Perfex Client or Customer Group coupon eligibility upon sign-in.
Three Native Checkout Flows from One /checkout Experience
Polystore_Checkout supports retail consumers, repeat portal buyers, and enterprise procurement teams through three unified checkout paths:
| Checkout Flow | CRM Records Created | Customer Experience & Portal Access | Primary Use Case |
|---|---|---|---|
| 1. Guest Checkout | Store Order + Perfex Invoice (tblinvoices) |
Instant confirmation email with signed one-click /track-order link and direct Perfex Invoice payment URL |
Low-friction B2C impulse purchases and POD retail orders |
| 2. Create an Account at Checkout | tblclients + primary tblcontacts + Store Order + Perfex Invoice |
Buyer checks "Create an account?", sets or auto-generates a password, logs in automatically, receives welcome email, and accesses /my-account |
Repeat D2C customers, digital download buyers, and warranty tracking |
| 3. B2B Quote / Estimate Request | Store Order (quote_requested) + Perfex Estimate (tblestimates) |
Buyer submits formal RFQ; receives Estimate PDF link; sales negotiates in CRM and converts Estimate to Invoice in one click | Wholesale bundles, Quote-Only products, custom services, and enterprise procurement |
Inside the five-tab /my-account portal (Overview, My Orders, B2B Quotes, Downloads, and Addresses), registered buyers inspect fulfillment milestones, open official Perfex Invoice and Estimate PDFs, download paid tokenized digital files, and keep billing/shipping details synchronized with their Perfex Client profile. Guests and logged-in buyers alike can also check live shipment milestones anytime at /track-order ([polystore_order_tracking]).
Atomic Stock Concurrency and Zero-Oversell Protection
High-velocity flash sales and limited-run electronics drops expose race conditions in standard PHP shopping carts where two simultaneous checkouts read stock_qty = 1 and both succeed, leaving negative inventory.
PolyStore eliminates overselling at the database engine layer during checkout commit:
- InnoDB Transaction with Row-Level Locking:
Polystore_Checkoutwraps stock validation and deduction inside an InnoDB transaction usingSELECT ... FOR UPDATEon every targeted product andtblpolystore_product_variantsrow. Concurrent checkout requests targeting the same SKU serialize cleanly at the row lock rather than colliding. - Idempotent Inventory Flags: Every storefront order tracks explicit
stock_deductedandstock_restoredstate flags. Whether payment settles via an asynchronous Stripe webhook, a PayPal IPN callback, or a manual accountant entry inside Perfex CRM, stock is deducted exactly once and restored at most once if the order or linked invoice is cancelled.
Bidirectional Perfex CRM Hooks and Native UI Injection
Instead of treating Perfex CRM as a passive archive, Polystore_Perfex_Hooks keeps Storefront Orders and Perfex CRM financial documents continuously synchronized in both directions across six core hooks:
| Perfex CRM Hook | Triggering Action in Perfex CRM | Automated PolyStore Synchronization |
|---|---|---|
after_payment_added |
Online gateway payment succeeds or staff records a manual bank/cash payment | Marks order paid, advances status to processing, deducts stock if still pending, unlocks tokenized digital downloads, fires polystore-order-paid-customer email |
invoice_status_changed |
Accountant updates invoice status directly inside Perfex Sales | Reconciles payment and order state on the linked PolyStore order automatically |
invoice_marked_as_cancelled |
Staff cancels the linked Perfex Invoice | Transitions storefront order to cancelled, idempotently restores reserved stock (stock_restored), notifies buyer via polystore-order-cancelled-customer |
before_invoice_deleted |
Administrator deletes an invoice record | Safely guards and cleans up order-to-invoice linkage before deletion completes |
estimate_converted_to_invoice |
Sales rep converts an approved B2B Estimate into a Perfex Invoice | Automatically upgrades the B2B quote order (quote_requested) into a live invoice order bound to the new Perfex Invoice ID |
estimate_declined |
Client or staff marks the B2B Estimate as declined | Updates the linked PolyStore quote order state so storefront and CRM pipelines stay aligned |
Native CRM Admin and Client Portal UI Injection
Staff and customers do not have to hunt across disconnected dashboards to trace a transaction. PolyStore injects live e-commerce context directly into five native Perfex CRM screens:
Sales > InvoicesDataTable: Appends PolyStore Order badges next to storefront-originated invoices so finance staff immediately distinguish online orders from manual retainers.- Perfex Invoice Preview: Embeds a Fulfillment & Tracking card allowing staff to view shipping status, carrier details, and jump directly to the PolyStore order.
- Perfex Estimate Preview: Displays a B2B Quote card summarizing storefront quote origin, customer notes, and linked items.
- Public Invoice HTML View: Renders a live Order Tracking block right on the shareable Perfex Invoice page.
- Perfex Client Portal Navbar: Injects a "My Store Orders" navigation link so existing CRM clients move seamlessly between support tickets, invoices, and storefront order history.
9-Stage Fulfillment Lifecycle, Inherited Payments & Shipping Rules
Polystore_Orders tracks every retail purchase and B2B RFQ across 9 structured fulfillment statuses managed from Store > Orders (admin/polycms/plugin/polystore/orders):
| Fulfillment Status | Meaning & Typical Trigger | Automated Customer / Stock Behavior |
|---|---|---|
quote_requested |
B2B Estimate checkout submitted (tblestimates created) |
Sends quote confirmation to buyer and admin; no stock deduction until converted/confirmed |
pending_payment |
Standard checkout created awaiting gateway or offline transfer | Linked Perfex Invoice issued; sends order confirmation with payment link |
on_hold |
Order paused pending manual verification or bank clearance | Holds fulfillment queue until payment is recorded in Perfex CRM |
processing |
Payment verified (after_payment_added) |
Deducts stock idempotently, unlocks digital downloads, dispatches polystore-order-paid-customer |
packed |
Warehouse picked and packed physical SKUs | Updates visual tracking timeline on /track-order and /my-account |
shipped |
Staff enters shipping carrier, tracking number, and tracking URL | Dispatches polystore-order-shipped-customer with carrier and live tracking links |
completed |
Delivery confirmed or digital/service fulfillment finished | Dispatches polystore-order-completed-customer |
cancelled |
Cancelled by staff or via invoice_marked_as_cancelled |
Restores reserved stock idempotently and sends polystore-order-cancelled-customer |
refunded |
Order marked refunded after credit or gateway reversal | Dispatches polystore-order-refunded-customer |
Zero-Reconfiguration Payment Gateways (Polystore_Payments)
PolyStore never forces you to maintain duplicate payment gateway credentials. Polystore_Payments queries Perfex CRM's native Payment_modes_model and routes online payments through Payments_model::process_payment() via /polystore/pay/{order_number}.
Every payment method already configured inside Perfex CRM - including Stripe, PayPal, Authorize.Net, Mollie, and any active third-party Perfex gateway or offline bank transfer mode - works natively at /checkout on day one.
Storefront Shipping Methods
Configured under Store > Settings, PolyStore ships with three clean shipping rules that automatically skip physical shipping calculation for pure digital or service carts:
- Flat Rate: Predictable fixed shipping fee per order.
- Free Shipping over Threshold: Automatically unlocks free delivery when cart subtotal meets your target order value (ideal for lifting Average Order Value).
- Local Pickup: Zero-cost pickup option for local retail showrooms, studios, or B2B warehouses.
Advanced Promotional Coupon Engine (Polystore_Coupons)
Backed by tblpolystore_coupons and tblpolystore_coupon_usages (managed in Store > Coupons), PolyStore includes a CRM-aware promotion engine engineered for both consumer campaigns and targeted B2B contract discounts.
5 Supported Discount Types
| Coupon Type | Calculation Logic | Ideal Campaign Scenario |
|---|---|---|
percent |
Percentage off eligible items/cart with an optional maximum discount cap | Seasonal sales (SAVE15, capped at $100 max savings on flagship electronics) |
fixed |
Fixed currency amount deducted across the entire cart | Welcome vouchers ($20 off first order over $100) |
fixed_product |
Fixed discount applied to each qualifying item unit | Per-unit clearance on specific POD tees or accessories |
free_shipping |
Waives applicable cart shipping cost | Cart-recovery incentives or VIP free-delivery perks |
bogo |
Buy X Get Y at Z% Off, automatically discounting the cheapest eligible units | "Buy 2 Tees, Get 1 at 50% Off" or "Buy 3 Canvas Prints, Get 1 Free" without exposing margin leaks |
CRM-Aware Targeting Rules and Security Guards
Because PolyStore runs inside Perfex CRM, coupon eligibility rules tap directly into live CRM customer data:
- Email & Domain Wildcards: Restrict a promo code to exact email addresses or corporate domain wildcards such as
*@partner.comfor partner and employee benefits. - Perfex Client Accounts (
tblclients): Assign private negotiated promo codes directly to specific CRM client organizations. - Perfex Customer Groups (
tblcustomers_groups): Target wholesale, agency, distributor, or VIP groups automatically using the customer groups your sales team already maintains. - Acquisition & Catalog Scopes: Enforce
first_order_only, include or exclude specific products and categories (with automatic expansion of all nested subcategories), and toggle Exclude Sale Items to prevent double-discounting. - Spend, Quantity & Redemption Limits: Configure minimum/maximum order spend, minimum item quantity, total global redemption caps, and per-user usage limits tracked in
tblpolystore_coupon_usages. - Brute-Force Rate Limiting: Storefront AJAX coupon validation passes through
Polycms_Rate_Limiter, blocking automated bots from guessing private or partner coupon codes.
9 Native Perfex Email Templates and 27 Merge Fields
PolyStore registers 9 editable transactional email templates directly inside Perfex CRM under Setup > Email Templates > PolyStore, letting your team customize subjects, branding, and multilingual copy alongside standard CRM notifications:
| Template Slug | Recipient | Trigger Event |
|---|---|---|
polystore-order-created-customer |
Customer | Standard storefront order submitted |
polystore-new-order-admin |
Store Admin | New storefront order received |
polystore-order-paid-customer |
Customer | Linked Perfex Invoice paid online or manually recorded |
polystore-order-shipped-customer |
Customer | Fulfillment updated to shipped with carrier and tracking details |
polystore-order-completed-customer |
Customer | Fulfillment marked completed |
polystore-order-cancelled-customer |
Customer | Order or linked Perfex Invoice cancelled |
polystore-order-refunded-customer |
Customer | Order marked refunded |
polystore-quote-requested-customer |
Customer | B2B Quote / Estimate request submitted |
polystore-quote-requested-admin |
Store Admin | New B2B Quote / Estimate request received |
All 27 Dynamic Merge Fields
Every PolyStore template supports 27 structured merge fields organized across five functional groups:
- Order Summary & Totals (11):
{order_number},{order_date},{order_status},{order_payment_status},{order_payment_method},{order_subtotal},{order_discount},{order_shipping_cost},{order_tax},{order_total},{order_items_table} - Fulfillment & Tracking (4):
{order_shipping_carrier},{order_tracking_number},{order_tracking_url},{order_tracking_page_url} - Portal, Admin & Digital Assets (4):
{order_view_url},{order_admin_url},{order_digital_downloads_html},{order_notes} - Perfex CRM Financial Documents (4):
{invoice_number},{invoice_link},{estimate_number},{estimate_link} - Customer & Store Identity (4):
{customer_name},{customer_email},{store_name},{store_url}
Suppressing Duplicate Core Perfex Invoice Emails
Because placing a storefront order generates a real Perfex Invoice, Perfex CRM's default email trigger would normally fire a second plain invoice email moments after PolyStore's branded order confirmation. Enabling "Suppress duplicate Perfex invoice email" in Store > Settings hooks cleanly into before_email_template_send, preventing duplicate inbox clutter while retaining full PDF and payment links inside {invoice_link} in the PolyStore email.
SQL-Aggregated Store Analytics and Streaming CSV Exports (Polystore_Analytics)
Reporting plugins that load thousands of order records into PHP arrays routinely crash with out-of-memory errors once a store scales. Polystore_Analytics executes pure SQL GROUP BY aggregations directly against normalized tblpolystore_orders and tblpolystore_order_items tables, maintaining O(1) PHP memory consumption regardless of historical order volume.
Storefront KPIs and Revenue Breakdowns
Accessible in Store > Dashboard (admin/polycms/plugin/polystore/dashboard) and surfaced on the PolyCMS Blog Dashboard via the built-in widget-polystore-analytics widget:
- Headline Financial KPIs: Paid Revenue, Pending Revenue, active B2B Quote Pipeline value, Average Order Value (AOV), and Paid Conversion Rate.
- Trend & Mix Reports: Revenue timeseries chart, Category Revenue breakdown, Top 10 selling products, Payment Gateway mix (comparing Stripe, PayPal, bank transfer, and other modes), and Coupon ROI attribution showing total discount granted versus revenue generated.
- High-Volume Streaming CSV Export: Exports filtered order reports using keyset-paginated chunked streaming (
LIMIT 500) straight to the HTTP output stream, eliminating memory spikes and web server timeouts even when exporting tens of thousands of orders for quarterly tax audits.
Frequently Asked Questions
What happens automatically when an accountant marks a Perfex Invoice as Paid or Cancelled?
Through Polystore_Perfex_Hooks, recording payment (after_payment_added) immediately marks the linked PolyStore order paid, advances fulfillment to processing, deducts inventory idempotently if pending, unlocks digital downloads, and dispatches polystore-order-paid-customer. Cancelling the invoice (invoice_marked_as_cancelled) cancels the store order, restores reserved stock via stock_restored, and emails the buyer.
How does PolyStore convert a storefront B2B Quote Request into a payable order?
When a buyer submits a B2B Quote at /checkout, PolyStore creates an order with status quote_requested and a native Perfex Estimate (tblestimates). Once your sales team negotiates pricing and clicks Convert to Invoice inside Perfex CRM, the estimate_converted_to_invoice hook automatically upgrades the storefront order into a standard invoice order linked to the new Perfex Invoice.
Do I need to configure Stripe or PayPal separately inside PolyStore?
No. Polystore_Payments inherits 100% of active Perfex CRM online payment gateways (Stripe, PayPal, Authorize.Net, Mollie, and others) plus offline payment modes via Payment_modes_model and Payments_model::process_payment(). Any gateway active in Perfex CRM works automatically on /checkout and /polystore/pay/{order_number}.
How does the BOGO coupon discount protect store margins when carts hold mixed-price items?
When a bogo (Buy X Get Y at Z% Off) coupon is applied, Polystore_Coupons sorts qualifying units by unit price and automatically applies the discount to the cheapest eligible units in the cart. You can also combine BOGO or percentage coupons with category exclusions, Exclude Sale Items, Perfex Customer Groups, and per-user usage limits.
How does PolyStore stop two shoppers from buying the last unit of a SKU at the exact same millisecond?
During checkout commit, Polystore_Checkout opens an InnoDB database transaction and acquires SELECT ... FOR UPDATE row-level locks on the affected product and variant stock rows. The second request waits for the lock to release, sees updated inventory of 0, and rejects the oversell cleanly while idempotent stock_deducted / stock_restored flags guarantee accurate counts across every status change.
Related Documentation
- Selling Multi-Variant Products in Perfex CRM: POD Apparel, Electronics & Faceted Filters - Configure 4 visual swatch modes, POD and electronics variant matrices, exact same-variant faceted filtering, and dynamic variant URLs.
- All-in-One CRM, E-Commerce & Blog in Perfex CRM with PolyStore - Why unifying CRM, content publishing, and native e-commerce outperforms disconnected multi-platform stacks.
- PolyStore Catalog, Products & Categories Management in Perfex CRM - Manage simple, variable, digital, service, and quote-only products alongside Perfex Item Groups.
- PolyCMS Plugin: PolyStore - Native E-Commerce Storefront for Perfex CRM - Installation, automatic page provisioning, admin menu tour, shortcodes, and storefront widgets.
- Designing a Perfex CRM Storefront with MTBuilder and PolyStore - Customize checkout, cart, shop, and landing pages visually with MTBuilder Store blocks.
- PolyStore E-Commerce SEO: Dynamic Variant URLs, XML Sitemaps & GEO - Configure product XML sitemaps, Schema.org Product JSON-LD, and AI search optimization.
- PolyCMS Hooks & Filters Complete Reference - Extend checkout payloads, custom shipping methods, email merge fields, and order webhooks.
Launch Your CMS for Perfex CRM — Lifetime Access for Just $19
Create blogs, pages, themes, plugins, and manage everything from one powerful unified admin panel.
Early Adopter Advantage
Current pricing reflects the module’s present feature set. As additional plugins, themes, multilingual capabilities, builders (MTBuilder), and ecosystem integrations are released, pricing may be adjusted. Early customers secure today’s price while benefiting from future updates.