Easy Product Manager 2.0
========================

Target
------
CE Phoenix Cart 1.1.0.6
PHP 8.2

Purpose
-------
Provide a standalone one-page product add/edit workflow in Phoenix Admin. The
normal Phoenix Catalog page remains installed and unchanged as a fallback.

Core files
----------
No Phoenix core files are changed or replaced.

New files
---------
admin/easy_products.php
admin/includes/epm_product_helpers.php
admin/includes/actions/easy_products/create_category.php
admin/includes/actions/easy_products/organise.php
admin/includes/actions/easy_products/save.php
admin/includes/boxes/catalog_easy_products.php
admin/includes/js/easy_products.js
admin/includes/languages/english/easy_products.php
admin/includes/languages/english/modules/boxes/catalog_easy_products.php
admin/includes/languages/english/hooks/catalog/epmProductButton.php
includes/hooks/admin/siteWide/epmProductButton.php

Features
--------
* Search existing products by partial name, model or exact product ID.
* Open directly on the Add new product form.
* Switch to Edit existing product with a clear button; the edit fields remain
  hidden until a product search result is selected.
* Add and edit products through the same one-page form.
* Open an existing product directly in Easy Product Manager from the native
  Phoenix Catalog product page.
* Keep the Add new product and Edit existing product controls beside the page
  title where they are immediately visible.
* Choose one or more existing Phoenix categories.
* Create a category inline, choose its parent and immediately select it for the
  current product without leaving the form.
* Edit status, availability, manufacturer, importer, model, GTIN, weight,
  quantity, tax class and net/gross price.
* Store a product cost price in products.products_cost_price and show the live
  net-price markup as a combined configured-currency value and percentage.
* Edit product names, descriptions, URLs and SEO fields for every installed
  language.
* Automatically detect the optional Main/Long Product Description add-on. When
  installed, show separate required Main and optional Long Description fields;
  without it, retain the normal single product-description field.
* Format product descriptions on both Add and Edit with a page-specific
  TinyMCE editor.
* Open the optional Long Description editor at a compact height and expand it
  automatically as content is entered, up to a practical maximum height.
* Keep product names, descriptions and URLs at the top of the product form,
  while placing the dedicated SEO section after Product images.
* Upload a required main image for a new product or retain the current image
  while editing.
* Add, replace, remove and sort gallery images.
* Show thumbnails for the main image and existing gallery images, and preview
  a newly selected main image before saving.
* Keep each gallery image's optional HTML field collapsed until requested,
  while preserving and identifying existing HTML content.
* Link an existing product into another category without creating a second
  product record.
* Create an inactive independent duplicate in the same or another category,
  including descriptions, image references, gallery images, attributes and
  attribute download data.
* Move a product to another category, replacing all its current category
  assignments after confirmation.
* Keep the optional Link, Duplicate and Move buttons centred above the product
  description, revealing the destination category only after an action is
  selected.
* Allocate existing native Phoenix option/value pairs.
* Keep the attribute editor hidden until Add or edit attributes is selected,
  while showing how many values are already assigned.
* Edit the prefix and product-specific price adjustment for each allocation.
* Use Easy Attribute Manager defaults when its defaults table is installed.
* Preserve orphaned attribute rows for explicit review in Easy Attribute
  Manager rather than deleting them silently.
* Remove connected products_attributes_download rows when a valid product
  attribute is deliberately removed.
* Warn before leaving a changed product without saving.
* Save the database changes in one transaction.

Attribute scope
---------------
This page allocates existing option/value combinations only. It does not create,
rename, reorder or delete option names or values. Use Easy Attribute Manager or
Phoenix's native Products Attributes page for those operations.

The supported attribute fields are native Phoenix:
* products_id
* options_id
* options_values_id
* options_values_price
* price_prefix

QTPro and third-party per-attribute stock, weight, image, wholesale-price or
Option Types fields are not managed.

Installation
------------
See Install.md.

TinyMCE
-------
TinyMCE is loaded only on Easy Product Manager and is applied only to product
description fields. The optional Long Description editor starts compact and
grows with its content. TinyMCE is loaded from the cdnjs-hosted TinyMCE 5.5.1
file used by the supplied TinyMCE-for-PhoenixCart reference add-on. If the CDN
cannot be reached, the standard textareas remain available.

Optional Main/Long Product Description support
----------------------------------------------
Easy Product Manager checks whether
products_description.products_long_description exists. If present, it shows
both Main Product Description and Long Product Description editors and saves
each to the matching database column. The main description remains required;
the long description is optional. If the column is absent, no database change
is made and the standard single product-description editor is used.

See THIRD_PARTY_NOTICES.txt for attribution and licensing information.

Database change
---------------
When Easy Product Manager is opened, it checks for
products.products_cost_price. If the column is absent, it creates:

products_cost_price DECIMAL(15,4) NOT NULL DEFAULT 0.0000

Uninstall
---------
Delete only the eleven new files listed above. The Product Manager creates no
database tables. The products_cost_price column is deliberately retained so
stored cost data is not destroyed. Products and native product attributes
remain in Phoenix.

Change log
----------
0.1.1
* Replaced the unavailable IMAGE_SEARCH core constant with the add-on-owned
  TEXT_SEARCH_BUTTON language definition.

0.2.0
* Hid the product form on the landing page until Add new product or a product
  search result is selected.
* Moved product attributes below descriptions and SEO.
* Added inline category creation with parent-category and sort-order selection.

0.2.1
* Renamed local language-loop variables so they cannot overwrite Phoenix's
  session language through the references created by application_top.php.

0.2.2
* Made Add new product the default page view.
* Added a dedicated Edit existing product button which opens product search and
  keeps the edit form hidden until a result is selected.

0.2.3
* Rebuilt both category selectors immediately after inline category creation so
  the new category appears beneath its correct parent without leaving or
  refreshing the page.

0.2.4
* Kept the attribute options, filters and manager links hidden until the
  administrator selects Add or edit attributes.
* Added a visible count of existing assignments while the editor is closed.

0.2.5
* Moved Descriptions and SEO to the first section of the product form.
* Made the first language panel open reliably without assuming that the
  language array starts at index zero.
* Built unique language-panel targets from the Phoenix language directory and
  language ID so the description panel also opens correctly while editing.

0.3.0
* Added TinyMCE formatting to product descriptions on both Add and Edit.
* Scoped the editor to Easy Product Manager product-description fields only.
* Kept the normal textarea as a fallback when the TinyMCE CDN is unavailable.
* Synchronised editor changes before save and retained unsaved-change warnings.

0.3.1
* Added an add-on-owned Catalog page hook which shows Edit with Easy Product
  Manager when an existing product is selected or open for native editing.
* Passed the selected product ID directly to Easy Product Manager edit mode.

0.3.2
* Added the Edit with Easy Product Manager action to the selected product
  infobox using Phoenix's infoBox hook, matching the proven AOM orders-page
  integration pattern.
* Retained the page-header listener for the native product-edit form.

0.3.3
* Registered the native Catalog integration through Phoenix's admin siteWide
  hook pipeline and restricted both listeners to catalog.php.
* Returned an empty string from non-output listener paths to match the Phoenix
  hook concatenation contract.

0.3.4
* Removed the duplicate native Catalog header button.
* Kept the Edit with Easy Product Manager action in the selected product
  infobox, matching AOM's native Orders-page behaviour.

0.4.0
* Added editable products.products_cost_price support.
* Created the cost-price column automatically when it is absent.
* Added live markup percentage and configured-currency markup value displays,
  calculated from the net selling price.

0.4.1
* Combined markup value and percentage into one unboxed display.
* Coloured markup above 15% green, below 15% red and exactly 15% neutral.

0.4.2
* Made the live markup display smaller, normal-weight and italic so it remains
  useful without dominating the price fields.

0.5.0
* Moved the Add/Edit mode buttons beside the page title.
* Moved SEO to the bottom of the form after Product images.
* Added main-image thumbnail and new-file preview support.
* Added product linking, independent duplication and moving between categories.
* Duplicated products open immediately for editing and start inactive to avoid
  an accidental duplicate storefront listing.

2.0
* Finalised the product-form layout with product content at the top and SEO
  after images.
* Added thumbnails for existing additional images.
* Centred the optional product-organisation actions and kept the category
  selector hidden until Link, Duplicate or Move is chosen.
* Collapsed gallery-image HTML fields behind individual Add/edit controls.
* Added automatic compatibility with the optional Main/Long Product
  Description add-on.
* Added separate Main and Long Description editors when the add-on's database
  column is detected; Main remains required and Long remains optional.
* Made the optional Long Description editor start compact and grow as content
  is entered.
