Skip to content
Snippets Groups Projects
Commit e2c4e069 authored by Robert Kasza's avatar Robert Kasza Committed by Róbert Kasza
Browse files

Issue #3003348 by mirom, kaszarobert: Add delivery details to invoice

parent 8149f49b
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,4 @@ specific: ''
maturity: 14
environment: 'live'
order_file_field: '_none'
add_shipping_data: true
......@@ -29,3 +29,6 @@ superfaktura.settings:
order_file_field:
type: string
label: Save downloaded invoice to file field
add_shipping_data:
type: boolean
label: Indicates if shipping information will be sent to SF
......@@ -118,6 +118,13 @@ class SettingsForm extends ConfigFormBase {
'#empty_value' => '_none',
];
$form['add_shipping_data'] = [
'#type' => 'checkbox',
'#title' => $this->t('Send shipping information'),
'#description' => $this->t("Commerce Shipping module is required to be set for this functionality."),
'#default_value' => $config->get('add_shipping_data') ?? FALSE,
];
return parent::buildForm($form, $form_state);
}
......@@ -135,6 +142,7 @@ class SettingsForm extends ConfigFormBase {
->set('maturity', $form_state->getValue('maturity'))
->set('environment', $form_state->getValue('environment'))
->set('order_file_field', $form_state->getValue('order_file_field'))
->set('add_shipping_data', $form_state->getValue('add_shipping_data'))
->save();
parent::submitForm($form, $form_state);
}
......
......@@ -309,6 +309,37 @@ class InvoiceService {
'country_iso_id' => $customer_profile['country_code'],
];
// Add shipping information to client from the first Shipment's
// shipping profile if exists.
if (!empty($this->configFactory->get('add_shipping_data')) &&
$order->hasField('shipments')
) {
$shipments = $order->get('shipments')->referencedEntities();
if (!empty($shipments)) {
$shipment = reset($shipments);
$shippingProfile = $shipment->getShippingProfile();
if ($shippingProfile) {
$shippingAddress = $shippingProfile->get('address')->getValue();
$shippingAddress = reset($shippingAddress);
if ($shippingAddress) {
$shippingData = [
'delivery_address' => $shippingAddress['address_line1'],
'delivery_city' => $shippingAddress['locality'],
'delivery_country_iso_id' => $shippingAddress['country_code'],
'delivery_name' => $shippingAddress['given_name'] . ' ' . $shippingAddress['family_name'],
'delivery_zip' => $shippingAddress['postal_code'],
];
$client += $shippingData;
}
}
}
}
return $client;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment