clickandmortar/oro-platform-generic-address-bundle
Installation:
composer require "clickandmortar/oro-platform-generic-address-bundle" "1.1.*"
Ensure compatibility with your OroPlatform version (e.g., 1.1.* for OroPlatform 4.1.*).
Enable JS Routing:
Update config/packages/fos_js_routing.yaml:
fos_js_routing:
routes_to_expose: [..., 'candm_*', ...]
Then regenerate routes:
php bin/console fos:js-routing:dump
Database & Config Update:
php bin/console doctrine:schema:update --force
php bin/console oro:entity-config:update --filter="ClickAndMortar*" --force
php bin/console oro:migration:data:load --bundles="ClickAndMortarGenericAddressBundle"
First Use Case:
Add an addressable field to an entity (e.g., Customer) via Oro’s Entity Configuration:
php bin/console oro:entity-config:add-field --entity=Customer --field=addresses --type=address
Verify the field appears in the admin UI under the entity’s form.
Entity Integration:
oro:entity-config:add-field to attach an addressable field to any entity (e.g., Order, Contact).
Example:
php bin/console oro:entity-config:add-field --entity=Order --field=shippingAddress --type=address
config/packages/clickandmortar_generic_address.yaml):
oro_entity_config:
entity_definitions:
Customer:
fields:
addresses:
form:
type: address
options:
label: "Customer Addresses"
required: false
Frontend Usage:
candm_address_save, candm_address_list).{{ form_row(form.addresses) }}
Data Migration:
php bin/console oro:migration:data:load --bundles="ClickAndMortarGenericAddressBundle"
ClickAndMortar\GenericAddressBundle\Migrations\Data\ORM\LoadGenericAddressData.API Exposure:
@ApiResource annotations or oro_api config.Route Conflicts:
fos_js_routing exposes only candm_* routes to avoid JS conflicts.php bin/console debug:router | grep candm_
Entity Config Caching:
php bin/console cache:clear
php bin/console oro:entity-config:update --filter="ClickAndMortar*" --force
Database Schema:
address table and a join table (entity_address) for many-to-many relationships.--force cautiously.Validation:
NotBlank for required fields).oro_entity_config under fields.{field}.validation_groups.php bin/console debug:config clickandmortar_generic_address
public/js/routing.js) and the address picker is loaded via require('candm-address') in your asset pipeline.Custom Address Types:
Extend the base Address entity by creating a subclass (e.g., BillingAddress) and override the bundle’s templates.
Field Customization:
Override Twig templates in templates/ClickAndMortarGenericAddressBundle/ to modify the address picker UI.
Event Listeners:
Hook into Oro’s lifecycle events (e.g., prePersist, preUpdate) to validate or modify addresses:
use ClickAndMortar\GenericAddressBundle\Event\AddressEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyAddressSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
AddressEvent::PRE_SAVE => 'onAddressPreSave',
];
}
}
API Customization:
Use Oro’s oro_api config to add/remove address fields from API responses:
oro_api:
rest:
Customer:
attributes:
addresses: ~
```markdown
### Pro Tips
- **Bulk Address Updates**:
Use Oro’s `oro:data-fixtures:load` to seed addresses for testing:
```bash
php bin/console oro:data-fixtures:load --fixtures="vendor/clickandmortar/oro-platform-generic-address-bundle/Migrations/Data/Fixtures/ORM/LoadAddressData"
Performance:
For large datasets, add indexes to the entity_address join table:
CREATE INDEX idx_entity_address_entity_id ON entity_address(entity_id);
Localization:
Address fields support Oro’s translation system. Extend translations in translations/messages.{locale}.yml:
candm:
address:
street: "Street Address"
city: "City"
How can I help you explore Laravel packages today?