Skip to main content

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 NameTypeLengthNullableDefault
custom_label2VARCHAR255YESNULL
custom_label3VARCHAR255YESNULL
custom_label4VARCHAR255YESNULL
manual_custom_label0VARCHAR255YESNULL
manual_custom_label1VARCHAR255YESNULL
manual_custom_label2VARCHAR255YESNULL
manual_custom_label3VARCHAR255YESNULL
manual_custom_label4VARCHAR255YESNULL

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 method
  • setCustomLabel{N}(?string $value): Product - Setter method
  • getManualCustomLabel{N}(): ?string - Getter method
  • setManualCustomLabel{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​

  1. Column Naming: Followed existing naming convention (custom_label{N})
  2. Data Type: VARCHAR(255) matches existing columns
  3. Nullable: All columns are nullable to allow gradual adoption
  4. Method Names: Camel case for PHP, snake case for database columns
  5. 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​

  1. Consider adding validation rules for label content
  2. Consider adding indexes if labels are used in WHERE clauses
  3. Consider documenting the business purpose of each label type
  4. Consider adding form fields in admin interface for editing

Files Modified​

  1. src/AppBundle/Entity/Product.php - Added properties and methods
  2. docs/CUSTOM_LABELS_FEATURE.md - This document

Support​

For questions or issues:

  1. Review this document
  2. Examine the existing custom_label0 and custom_label1 usage
  3. Use doctrine:schema:update --dump-sql to preview database changes