# Disable Private Customers Plugin for Shopware 6

This plugin restricts customer registration to business customers only in Shopware 6. It enforces VAT ID validation and ensures that only business customers can create accounts.

## Features

- Restricts registration to business customers only
- Enforces VAT ID validation with proper format checking
- Automatically sets account type to "business"
- Hides account type selection from registration forms
- Validates VAT ID format (2 letter country code + numbers/letters)
- Shows proper validation messages and error handling

## Requirements

- Shopware 6.x
- PHP 7.4 or higher

## Installation

1. Copy the plugin files to `custom/plugins/DisablePrivateCustomers/`
2. Install the plugin through the Shopware Admin Panel or via CLI:
   ```bash
   bin/console plugin:install DisablePrivateCustomers
   bin/console plugin:activate DisablePrivateCustomers
   ```
3. Clear the cache:
   ```bash
   bin/console cache:clear
   ```
4. Rebuild the storefront:
   ```bash
   bin/build-storefront.sh
   ```

## Components

### Validators

#### VatIdValidator
- Validates VAT ID format and presence
- Ensures VAT ID follows the correct format (2 letter country code + numbers/letters)
- Provides clear error messages for validation failures

### Subscribers

#### CustomerRegistrationSubscriber
- Handles customer registration events
- Validates VAT ID and business customer requirements
- Prevents private customer registration
- Handles error responses and redirects

#### RegistrationPageSubscriber
- Configures the registration page
- Sets default values for business customer registration
- Hides account type selection
- Adds necessary template variables

#### LoginPageSubscriber
- Configures the registration form on the login page
- Ensures consistent business customer registration across all forms

### Templates

- `address-personal-vat-id.html.twig`: Customizes VAT ID input field
- `address-personal-vat-id-label.html.twig`: Customizes VAT ID label
- `register.html.twig`: Modifies registration form for business customers

## Configuration

The plugin is configured through the following services:

```xml
<services>
    <service id="DisablePrivateCustomers\Validation\VatIdValidator">
        <argument type="service" id="Shopware\Core\Framework\Validation\HappyPathValidator"/>
    </service>

    <service id="DisablePrivateCustomers\Subscriber\CustomerRegistrationSubscriber">
        <argument type="service" id="DisablePrivateCustomers\Validation\VatIdValidator"/>
        <tag name="kernel.event_subscriber"/>
    </service>

    <service id="DisablePrivateCustomers\Subscriber\RegistrationPageSubscriber">
        <argument type="service" id="request_stack"/>
        <tag name="kernel.event_subscriber"/>
    </service>

    <service id="DisablePrivateCustomers\Subscriber\LoginPageSubscriber">
        <tag name="kernel.event_subscriber"/>
    </service>
</services>
```

## Validation Rules

### VAT ID Format
- Must start with a 2-letter country code (uppercase)
- Followed by numbers and uppercase letters
- Example: DE123456789

### Business Customer Requirements
- Company name must be provided
- VAT ID must be provided and valid
- Account type is automatically set to "business"

## Error Messages

The plugin provides the following error messages:
- "VAT ID is required" (Die Umsatzsteuer-ID ist ein Pflichtfeld)
- "Invalid VAT ID format" (Ungültiges Format der Umsatzsteuer-ID)
- "VAT ID must start with a 2-letter country code followed by numbers and letters" (Die Umsatzsteuer-ID muss mit einem 2-stelligen Ländercode beginnen, gefolgt von Zahlen und Buchstaben)
- "Only business customers can register" (Nur gewerbliche Kunden können sich registrieren)