Skip to content

Add AbstractType::with(array $data) for creating new instances by appending data to existing ones #350

@mjaschen

Description

@mjaschen

The first name that comes to mind for such a method is with, though it may not be the optimal choice (TBD).

This method saves the repeated use of array_merge() when creating multiple line items for orders, invoices, etc.

Example:

$baseOrder = new CustomerOrder([
    'client_id' => '1',
    'customer_salutation' => 'Herr',
    'customer_firstname' => 'Charly',
    'customer_lastname' => 'Cash',
    'customer_street' => 'Hauptstraße 12',
    'customer_zipcode' => '12222',
    'customer_city' => 'Berlin',
    'customer_country' => 'DE',
    'customer_phone' => '+49300000000',
    'customer_email' => 'cash@example.org',
    'order_date' => '01.01.1970',
    'status' => CustomerOrder::STATUS_CONFIRMED,
]);

$lineItem1 = $baseOrder->with([
    'product_description' => 'erster Artikel',
    'quantity' => '1',
    'price' => '10,50',
    'tax_rate' => CustomerOrder::TAX_RATE_FULL,
]);

$lineItem2 = $baseOrder->with([
    'product_description' => 'zweiter Artikel',
    'quantity' => '2',
    'price' => '11,99',
    'tax_rate' => CustomerOrder::TAX_RATE_FULL,
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions