osCommerce 2 Documentation

repository·master·Indexed 43 days ago

https://github.com/oscommerce/oscommerce2

An open-source e-commerce platform for online merchants. Documentation covers the storefront and admin panel entrypoints, Admin Dashboard configuration via MODULE_ADMIN_DASHBOARD_INSTALLED, product listing column configuration, category depth determination, and Sage Pay server-to-server notification handling using the sage_pay_server class.

Tokens
2K
Snippets
2
Records
9
Agent score
55%

What's inside osCommerce

  1. Understand the Storefront Entrypoint (catalog/index.php)

    master

    The catalog/index.php file serves as the primary entrypoint for the customer-facing storefront. It handles routing for different types of content based on the request state:

    1. Site Pages: If OSCOM::hasSitePage() returns true, the system fetches a specific page file via OSCOM::getSitePageFile() and renders it within the site template (top and bottom).
    2. Category Navigation: If a category path ($cPath) is provided, the system determines the category_depth:
      • nested: The category contains sub-categories. The system renders the category name, description, and uses the index_nested template content.
      • products: The category contains products. The system builds a dynamic SQL query to list products based on configured columns (e.g., PRODUCT_LIST_NAME, PRODUCT_LIST_PRICE) and renders the product_listing.php content.
    3. Manufacturer Views: If manufacturers_id is present in the GET parameters, the system displays products associated with that manufacturer.
    4. Default Home Page: If no specific page or category is matched, it renders the default index content using the index template content.

    Key Components Involved:

    • OSCOM: Core static methods for site page detection, configuration, and link generation.
    • $oscTemplate: Handles template file retrieval (template_top.php, template_bottom.php) and content injection (getContent()).
    • $OSCOM_Db: Used for prepared statements to fetch categories, products, and manufacturers.
    • $OSCOM_Language: Manages language IDs and definition loading.
    • $messageStack: Handles displaying user messages (e.g., product_action).
  2. How category depth is determined

    master

    When a $cPath is provided, the system determines how to display the content by checking the relationship between the current category and its contents:

    • products: If the current category ID is found in the products_to_categories table, the system treats it as a product listing page.
    • nested: If the current category has child categories (checked via parent_id in the categories table), the system treats it as a navigation page for sub-categories.
    • Fallback products: If no children are found, it defaults to a product listing (which may result in a 'no products' message if empty).
  3. Access the Admin Panel Entrypoint

    master

    The catalog/admin/index.php file serves as the primary entrypoint for the osCommerce administrative interface. It handles routing to site pages, manages template inclusion (top and bottom), and initializes the Admin Dashboard if configured.

    When a request is made to the admin index:

    1. It loads the application environment via includes/application_top.php.
    2. It checks if a specific site page is requested via OSCOM::hasSitePage().
    3. If a valid page file is found, it wraps the page content with template_top.php and template_bottom.php using the $oscTemplate object.
    4. If no specific page is requested, it renders the default dashboard view, which iterates through modules defined in MODULE_ADMIN_DASHBOARD_INSTALLED.
  4. Start the osCommerce installation process

    master
    To begin the installation and configuration of osCommerce, navigate to the catalog/install/ directory in your web browser. The index.php file serves as the entrypoint for the setup wizard, which initializes the application environment by loading includes/application.php and rendering the installation interface via templates/main_page.php.
  5. Handle Sage Pay server-to-server notifications

    master

    The sage_pay/server.php file acts as the callback entrypoint for Sage Pay server-to-server notifications. It validates incoming POST data from Sage Pay using a security signature and a security key associated with a specific skcode provided via GET.

    Workflow

    1. Validation: The script checks for the presence of skcode (GET) and required POST parameters (VPSSignature, VPSTxId, VendorTxCode, Status).
    2. Signature Verification: It constructs a signature string by concatenating specific transaction fields and the security key retrieved from the sagepay_server_securitykeys table. The signature is verified against the provided VPSSignature using an MD5 hash.
    3. Success Handling: If the signature is valid and the status is OK, AUTHENTICATED, or REGISTERED, the transaction details are sanitized and saved to the database. The script returns a Status=OK response with a RedirectURL pointing to checkout_process.php.
    4. Failure Handling:
      • If the signature is invalid, it returns Status=INVALID and redirects to the shopping cart.
      • If the transaction status is not successful, it returns Status=OK (to acknowledge receipt to Sage Pay) but redirects the user to an error page (checkout_payment.php or a custom redirect script) and deletes the security key record.
    5. Response Format: The script outputs a plain text response in the format:
      Status=[OK|INVALID|ERROR]
      RedirectURL=[URL]
    6. **Session Management**: Upon completion, the current session is killed via `Registry::get('Session')->kill()` to prevent session fixation or reuse.
    
  6. Configure product listing columns

    master

    The product listing on the index page is driven by several constants that determine which database columns are included in the search query and display. These are used to build the $search_query dynamically.

    Available configuration constants:

    • PRODUCT_LIST_MODEL: Displays the product model.
    • PRODUCT_LIST_NAME: Displays the product name.
    • PRODUCT_LIST_MANUFACTURER: Displays the manufacturer name.
    • PRODUCT_LIST_QUANTITY: Displays the product quantity.
    • PRODUCT_LIST_IMAGE: Displays the product image.
    • PRODUCT_LIST_WEIGHT: Displays the product weight.
    • PRODUCT_LIST_PRICE: Displays the product price.
    • PRODUCT_LIST_BUY_NOW: Controls the 'Buy Now' visibility.
  7. Configure the Admin Dashboard via MODULE_ADMIN_DASHBOARD_INSTALLED

    master

    The Admin Dashboard is populated by modules defined in the MODULE_ADMIN_DASHBOARD_INSTALLED constant. This constant accepts a semicolon-separated list of module identifiers.

    Modules can be specified in two ways:

    1. Namespaced Classes: A fully qualified class name (e.g., \Namespace\ModuleClass). The system uses Apps::getModuleClass($adm, 'AdminDashboard') to resolve these.
    2. File-based Modules: A filename (e.g., module_name.php). The system will attempt to load the class from includes/modules/dashboard/{class}.php after loading the corresponding language definitions from modules/dashboard/{filename}.php.

    Each dashboard module must implement an isEnabled() method and a getOutput() method to render its content.

    // Example of how the constant might be defined in a configuration file
    define('MODULE_ADMIN_DASHBOARD_INSTALLED', 'ModuleClass1;\Namespace\ModuleClass2;module_name.php');
  8. Sort product listings via GET parameters

    master

    Product listings can be sorted using the sort GET parameter. The format follows a pattern of [column_index][direction], where direction is a (ascending) or d (descending).

    Example Sort Keys:

    • 1a: Sort by Name, Ascending
    • 1d: Sort by Name, Descending
    • 7d: Sort by Price, Descending

    The system validates the sort parameter against the active $column_list to prevent SQL injection and ensure the requested column is actually being displayed.

  9. sage_pay_server class

    master

    The sage_pay_server class is instantiated within the Sage Pay callback handler to provide utility methods for URL formatting, error message retrieval, and debugging.

    Note: The class definition itself is located in includes/modules/payment/sage_pay_server.php, which is included by the server entrypoint.

    Key Methods

    • formatURL($url): Formats the redirect URL for the Sage Pay response.
    • getErrorMessageNumber($statusDetail): Retrieves a human-readable error message based on the Sage Pay status detail code.
    • sendDebugEmail(): Sends a debug email notification, typically triggered during signature mismatches or transaction failures.
    $sage_pay_server = new sage_pay_server();