ProductCat Documentation

Product Category Controller Documentation

File: /controllers/productCatController.php

Purpose: Manages product categories, category hierarchy, units assignment, and category-level pricing and discounts

Last Updated: December 19, 2024

Total Functions: 12

Lines of Code: 883

---

๐Ÿ“‹ Overview

The Product Category Controller is a core component for managing product categorization in the ERP system. It handles hierarchical category structures, category-specific pricing, discount management, and unit assignments.

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
productcatMain category tableproductCatId, productCatName, productCatParent, conditions
productcatunitCategory-unit relationshipsproductcatunitid, productcatid, unitid, productnumber
### Related Tables (Referenced)

Table NamePurposeRelationship
productProducts in categoriesForeign Key: productcat.productCatId
unitAvailable unitsForeign Key: productcatunit.unitid
userUser who created categoryForeign Key: productcat.userId
---

๐Ÿ”ง Key Functions

1. add()

Purpose: Creates a new product category with all associated settings

Called By: POST request with do=add

Parameters:

Returns: int - New category ID

Database Operations:

Business Logic Flow:

1. Validate and process form data
   โ†“
2. Handle image upload
   โ†“
3. Insert category record
   โ†“
4. Process category units
   โ†“
5. Call online sync function
   โ†“
6. Return category ID

Example:

// Called via POST with category data
$categoryId = add();

2. show()

Purpose: Displays all categories for management interface

Called By: GET request with do=show

Database Operations:

Business Logic:

1. Fetch all categories with extended data

2. Assign to Smarty template

3. Display show.html template

3. showByCatId($catId)

Purpose: Shows specific category details

Parameters:

Database Operations:

4. executeOperation()

Purpose: Performs batch operations on multiple categories

Called By: POST request with do=executeOperation

Parameters:

Business Logic Flow:

1. Get operation type and selected items
   โ†“
2. Loop through each selected category
   โ†“
3. Perform operation (delete/restore)
   โ†“
4. Build result message string
   โ†“
5. Display results

5. tempdelete($productCatid)

Purpose: Temporarily deletes a category (soft delete)

Parameters:

Returns: string - "success" or error message

Business Logic Flow:

โ”‚ โ””โ”€ Call online sync

Validation Rules:

6. returndelete($productCatid)

Purpose: Restores a temporarily deleted category

Parameters:

Database Operations:

7. edit()

Purpose: Loads category data for editing

Called By: GET request with do=edit&id={categoryId}

Returns: object - Category data with modified opticServices

Special Processing:

8. update()

Purpose: Updates existing category with new data

Called By: POST request with do=update

Parameters: Same as add() plus:

Business Logic Flow:

1. Load existing category
   โ†“
2. Update category properties
   โ†“
3. Handle image upload/update
   โ†“
4. Delete existing category units
   โ†“
5. Insert new category units
   โ†“
6. Update database record

9. deleteFinaly($productCatid)

Purpose: Permanently deletes category and all child categories recursively

Parameters:

Business Logic Flow:

โ”‚ โ””โ”€ Delete products in category

โš ๏ธ Warning: This is a destructive operation that cannot be undone!

10. addCatByNameOnly($catName)

Purpose: Quickly creates a category with only a name (used by external apps)

Parameters:

Returns: int - New category ID

Use Case: Used by integrated applications (like obygy) to create basic categories

11. getUnits()

Purpose: Retrieves all available units for category assignment

Returns: array - All active units

12. getProductCatUnits($productCatId)

Purpose: Gets all units assigned to a specific category

Parameters:

Returns: array - Category-unit relationships

---

๐Ÿ”„ Business Logic Flow

Category Creation Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
User fills form
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Validate data
โ€ข Name required
โ€ข Parent valid
โ€ข Prices numeric
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Process image
โ€ข Upload to server
โ€ข Resize if needed
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Insert category
โ€ข Main record
โ€ข Unit assignments
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Online sync
โ€ข Update web store
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Category Deletion Safety Check

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Delete request
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Check products
in category
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Block
deletion
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Block
deletion
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

โš ๏ธ Common Issues

PHP 8.2 Compatibility

Issue: Object initialization before property assignment

Solution: Objects are properly initialized in constructor

Image Upload Handling

Issue: File upload errors not properly handled

Files: Uses uploadImages2() and updateImagesWithoutresiz() functions

Solution: Proper error handling in upload functions

Recursive Deletion

Issue: Stack overflow with deep category hierarchies

Solution: Function handles recursion safely but monitor for very deep trees

Online Sync Dependency

Function: onlineTempCategoryFunc()

Purpose: Syncs category changes with web store

Issue: Sync failures can cause inconsistency

---

๐Ÿ”— Dependencies

Required Files

include("../public/impOpreation.php");           // Core operations
include("../public/config.php");                // Configuration
include("dailyentryfun.php");                   // Daily entry functions
include("../library/uploadImages.php");         // Image upload functions

DAO Classes

ProductcatDAO.class.php                          // Category operations
ProductDAO.class.php                             // Product operations
ProductcatunitDAO.class.php                      // Category-unit relationships
UnitDAO.class.php                                // Unit operations
ProgramsettingsDAO.class.php                     // System settings
YoutubeLinkDAO.class.php                         // YouTube integration

Views

JavaScript Dependencies

---

๐Ÿ“Š Performance Considerations

Database Optimization

Caching Strategy

Memory Usage

---

๐ŸŽฏ Integration Points

Web Store Integration

Product Management

Inventory Management