=== Spirit Store ===
Contributors: automatedintelligentsolutions
Tags: woocommerce, storefront, bundles, elementor, multi-brand
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.9.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Branded storefront sections for WooCommerce — one site, many entities: schools, teams, leagues, companies, chapters. You choose what to call them.

== Description ==

Spirit Store turns one WooCommerce site into many branded stores. Each entity — a school, a little-league team, a company, a chapter — is a record (colors, logo, mascot, order deadlines); products and packages are scoped to entities with a taxonomy; and one Elementor Pro template renders every entity through dynamic tags.

The word "Entity" is just the default. A Terminology setting lets each site pick its own label — School/Schools, Team/Teams, Company/Companies — and the entire admin and front end follow it.

**For the sales rep / site admin**

* Entity post type with branding (primary/secondary color, logo, mascot) and order-deadline fields
* Products assigned to entities via a taxonomy (admin column included)
* Draft packages proposed by entity admins arrive as pending products for review
* Settings page for terminology and an n8n webhook (with shared secret) for automation events

**For customers**

* Pick a home entity on My Account → Account details; the store's chat assistant then knows which storefront they shop for, even on general pages

**For entity administrators**

* Front-end portal (`[ssf_school_portal]`) — no wp-admin access
* Toggle which catalog products appear on their store
* Propose product packages; the rep approves pricing and publishes

**For buyers**

* `[ssf_school_search]` — find-your-entity landing grid with live search
* Entity pages branded automatically via CSS variables and Elementor dynamic tags
* `[ssf_products]` — the entity's catalog through the native WooCommerce grid
* `[ssf_deadlines]` — order-deadline banner per entity

**Automation (n8n)**

* Read-only REST API: `/wp-json/ssf/v1/entities`, `/entities/{slug}`, `/entities/{slug}/inventory` — public storefront data for chatbot agents and reminder workflows (the older `/schools/...` routes stay registered as aliases)
* Outbound webhooks for plugin events (package proposed, entity saved)
* Order events: use WooCommerce's native webhooks (WooCommerce → Settings → Advanced → Webhooks)

Note: public URLs are entity-neutral — entity pages live under `/stores/`, per-entity catalogs under `/catalog/`, and the portal at `/portal/` (all filterable). Internal data identifiers keep their original `ssf_school` spellings for backward compatibility with existing sites, templates, and automations; they are never visible to visitors. Shortcodes have neutral aliases: `[ssf_entity_search]` and `[ssf_entity_portal]`.

== External Services ==

This plugin can send data to ONE external service, and only if you configure it: the automation webhook URL you enter under Settings → Spirit Store (typically your own n8n instance). When set, the plugin POSTs event notifications to that URL — when an entity is created/updated (entity name, slug, colors, mascot, page URL) and when an entity admin proposes a product package (package name, entity, product IDs, an admin edit link) — authenticated with the shared secret you configure, sent as an X-SSF-Secret header. No data is sent anywhere until you enter a webhook URL, and no visitor or customer personal data is ever included. The service receiving the data is chosen and operated by you; consult your automation provider's terms and privacy policy.

== Installation ==

1. Upload the `spirit-store` folder to `/wp-content/plugins/`, or install the zip via Plugins → Add New.
2. Activate the plugin. WooCommerce is required for commerce features; Elementor Pro enables the dynamic tags.
3. (Optional) Set your terminology under Settings → Spirit Store — e.g. School/Schools or Team/Teams.
4. Add entities under the **Entities** menu (the menu name follows your terminology setting).
5. Assign products to entities using the entity box on the product edit screen.
6. Create a page containing `[ssf_entity_portal]` (suggested slug: `portal`) and one with `[ssf_entity_search]` — or let the Setup screen create them for you.
7. Create admin users for each entity and assign their entity on the user profile.
8. (Optional) Enter your n8n webhook URL and shared secret under Settings → Spirit Store.

== Frequently Asked Questions ==

= Can I call them Schools (or Teams, or Companies) instead of Entities? =
Yes — that is the point. Settings → Spirit Store → Terminology sets the singular and plural label, and the admin menu, meta boxes, portal, search, checklist, importer column, and Elementor tag names all follow it.

= Does it work without Elementor Pro? =
Yes. Branding is exposed as CSS variables (`--ssf-primary`, `--ssf-secondary`) and a body class, so any theme or builder can use it. Elementor Pro just makes the one-template-for-all pattern effortless.

= How do bundles work? =
Proposed packages are created as grouped products in pending status. A bundles extension can be layered on later for true fixed-price bundles.

= Can I import products from a spreadsheet? =
Yes. Use WooCommerce's built-in importer (Products → All Products → Import). Save your Excel sheet as CSV UTF-8 first. Include a column named with your plural label (e.g. "Entities" — "Schools" also still works) containing comma-separated entity names or slugs, and imported products are assigned to those storefronts automatically. Entities must already exist — unknown names are skipped. The product exporter includes the same column, so export → edit in Excel → re-import round-trips.

= Is customer data exposed through the REST API? =
No. The plugin's endpoints expose only published, public storefront data (entities, products, stock status). Orders stay behind WooCommerce's authenticated API.

== Changelog ==

= 0.9.2 =
* Fix: the Entity Admin role now self-heals on every page load. If the role or its capability is missing — typically because deleting an older edition of the plugin ran an uninstall routine that removed them — it is recreated automatically, restoring portal access for entity admins and administrators. If this affected your site, also re-check Settings → Spirit Store (terminology, webhook URL and secret), which the old uninstall may have cleared.

= 0.9.1 =
* Fix: the portal page no longer shows the login form again to users who are already signed in but lack the admin capability (which looked like a login loop). Customers now see who they're signed in as, with a Go to My Account button and a log-out link; the login form appears only when actually logged out, and returns to the portal page on success.

= 0.9.0 =
* Entity-neutral URLs. Entity pages now live at /stores/{slug} (was /schools/), per-entity catalog archives at /catalog/{slug} (was /school-store/), and the Setup screen creates the portal page at /portal/ (was /school-portal/). All three bases are filterable (ssfstore_entity_rewrite_slug, ssfstore_catalog_rewrite_slug, ssfstore_portal_path). Old URLs 301-redirect automatically, and rewrite rules flush themselves on update — no settings-save needed.
* The wp-admin redirect for entity admins now finds the portal page by its shortcode instead of a hardcoded slug, so you can rename the portal page freely.
* REST: new primary routes /wp-json/ssf/v1/entities/... ; the /schools/... routes remain as permanent aliases so existing automations keep working.
* Shortcode aliases [ssf_entity_search] and [ssf_entity_portal]; the original names keep working. Elementor previews accept ?ssf_entity=slug (legacy ?ssf_school= still accepted). Body class now includes ssf-entity-{slug} alongside the legacy class.

= 0.8.0 =
* New: customer membership. Registered customers can pick their home entity on My Account → Account details ("Which school/team/company do you shop for?"). Stored in the same per-user field the admin assignment uses; grants no admin access. New template helpers ssfstore_user_entity() / ssfstore_user_entity_slug() — the Spirit Store Chat widget uses them so the assistant knows a logged-in customer's storefront even on general pages.

= 0.7.0 =
* Renamed to Spirit Store. New plugin slug/folder `spirit-store` and text domain to match (WordPress.org preparation). Upgrading from School/Entity Storefronts: deactivate and delete the old plugin, then install and activate this one — all entities, products, settings, pages, shortcodes, and integrations carry over unchanged (every data identifier is identical).

= 0.6.0 =
* Rebranded to Spirit Store: the plugin is no longer school-specific. All visible labels now come from a new Terminology setting (Settings → Spirit Store) with singular/plural fields, defaulting to Entity/Entities — set it to School/Schools to keep the previous wording. No functionality changed: shortcodes, REST routes, post types, taxonomies, roles, meta keys, and CSS hooks are all identical, and existing content and integrations keep working. The importer/exporter column follows the label, while legacy "Schools" CSV headers still auto-map.

= 0.5.1 =
* Fix: fatal error on load in 0.5.0 (a renamed include path pointed at a non-existent file). If 0.5.0 took your site down, upload this version over it.

= 0.5.0 =
* Internal namespace rename to the unique ssfstore_/SSFStore_ prefix (WordPress.org directory preparation). Settings migrate automatically; all content, shortcodes, school data, REST endpoints, and integrations are unchanged.
* Declared WordPress 7.0 compatibility; added External Services documentation.

= 0.4.0 =
* New: Setup screen (Schools → Setup) — an environment checklist covering WooCommerce, Elementor Pro, permalinks, required pages (with one-click page creation), schools, product assignments, and n8n connection.

= 0.3.0 =
* Live search: [ssf_school_search] now searches schools by title AND page content as you type, showing a Schools section plus a Products & Packages section with everything available at the matched schools (packages listed first, with a Package badge).

= 0.2.2 =
* School search wrapper and grid now carry zero outer margin/padding, so the section aligns flush with other Elementor elements in same-width containers.

= 0.2.1 =
* School search cards now show the school's featured image as a thumbnail and an excerpt drawn from the school page content.

= 0.2.0 =
* New: "Schools" column for the native WooCommerce product importer and exporter. Import a CSV (saved from Excel) with comma-separated school names or slugs and products are assigned to those school storefronts automatically.

= 0.1.1 =
* School search grid now centers its tiles by default. Use [ssf_school_search align="left"] for the previous left-filled, full-width layout.

= 0.1.0 =
* Initial scaffold: School post type, product taxonomy sync, School Admin role + portal, branding CSS variables, Elementor dynamic tags, shortcodes, REST API for n8n, outbound webhooks, settings page.
