Custom Labels Feature - Implementation Summary
Overview​
Added 8 new custom label columns to the mz_product table to extend product labeling capabilities.
Changes Made​
1. Database Schema Changes​
Added the following columns to mz_product table:
| Column Name | Type | Length | Nullable | Default |
|---|---|---|---|---|
custom_label2 | VARCHAR | 255 | YES | NULL |
custom_label3 | VARCHAR | 255 | YES | NULL |
custom_label4 | VARCHAR | 255 | YES | NULL |
manual_custom_label0 | VARCHAR | 255 | YES | NULL |
manual_custom_label1 | VARCHAR | 255 | YES | NULL |
manual_custom_label2 | VARCHAR | 255 | YES | NULL |
manual_custom_label3 | VARCHAR | 255 | YES | NULL |
manual_custom_label4 | VARCHAR | 255 | YES | NULL |
2. Entity Changes​
File: src/AppBundle/Entity/Product.php
Added Properties​
private $customLabel2;
private $customLabel3;
private $customLabel4;
private $manualCustomLabel0;
private $manualCustomLabel1;
private $manualCustomLabel2;
private $manualCustomLabel3;
private $manualCustomLabel4;
Added Methods​
For each new property, added:
getCustomLabel{N}(): ?string- Getter methodsetCustomLabel{N}(?string $value): Product- Setter methodgetManualCustomLabel{N}(): ?string- Getter methodsetManualCustomLabel{N}(?string $value): Product- Setter method
Additionally, added missing getters and setters for existing properties:
getCustomLabel0()/setCustomLabel0()getCustomLabel1()/setCustomLabel1()
3. Database Schema Update​
Use Doctrine's schema update command to apply the database changes:
# Generate SQL to preview changes
php bin/console doctrine:schema:update --dump-sql
# Apply changes to database
php bin/console doctrine:schema:update --force
This will automatically create the 8 new columns in the mz_product table based on the entity annotations.
Usage​
Using in Code​
// Get a product
$product = $productRepository->find($id);
// Set custom labels
$product->setCustomLabel2('Label 2 Value');
$product->setCustomLabel3('Label 3 Value');
$product->setManualCustomLabel0('Manual Label 0');
// Get custom labels
$label2 = $product->getCustomLabel2();
$manualLabel0 = $product->getManualCustomLabel0();
// Save changes
$entityManager->persist($product);
$entityManager->flush();
Design Decisions​
- Column Naming: Followed existing naming convention (
custom_label{N}) - Data Type: VARCHAR(255) matches existing columns
- Nullable: All columns are nullable to allow gradual adoption
- Method Names: Camel case for PHP, snake case for database columns
- Return Types: Using PHP 7.1+ nullable return types
Testing Checklist​
- PHP syntax validation passed
- No security vulnerabilities detected
- Code review completed
- Unit tests for new getters/setters (if test infrastructure exists)
- Integration test with database (requires DB setup)
- Verify existing custom_label0 and custom_label1 still work
Backward Compatibility​
✅ Fully backward compatible
- No breaking changes to existing code
- Existing columns untouched
- New columns are optional (nullable)
- Getters/setters follow existing patterns
Future Considerations​
- Consider adding validation rules for label content
- Consider adding indexes if labels are used in WHERE clauses
- Consider documenting the business purpose of each label type
- Consider adding form fields in admin interface for editing
Files Modified​
src/AppBundle/Entity/Product.php- Added properties and methodsdocs/CUSTOM_LABELS_FEATURE.md- This document
Support​
For questions or issues:
- Review this document
- Examine the existing
custom_label0andcustom_label1usage - Use
doctrine:schema:update --dump-sqlto preview database changes