Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions Service/Label/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ class Create extends ShippingInformation
const GLS_PARCEL_MIN_WEIGHT = 0.2;
const GLS_PARCEL_MAX_WEIGHT = 31.9;

//custom Sender Address
const GLS_SENDER_ADDRESS_ENABLED = 'tig_gls/sender_address/sender_address_enabled';
const GLS_SENDER_ADDRESS_COMPANY = 'tig_gls/sender_address/company';
const GLS_SENDER_ADDRESS_STREET_NAME = 'tig_gls/sender_address/street_name';
const GLS_SENDER_ADDRESS_HOUSE_NUMBER = 'tig_gls/sender_address/house_number';
const GLS_SENDER_ADDRESS_HOUSE_NUMBER_ADDITION = 'tig_gls/sender_address/house_number_addition';
const GLS_SENDER_ADDRESS_POSTCODE = 'tig_gls/sender_address/postcode';
const GLS_SENDER_ADDRESS_CITY = 'tig_gls/sender_address/city';

/**
* @var Create $createLabel
*/
Expand Down Expand Up @@ -167,6 +176,7 @@ public function getRequestData($shipmentId, $controllerModule, $version)
private function mapLabelData($shipment, $controllerModule, $version)
{
$order = $shipment->getOrder();
$storeId = $order->getStoreId();
$deliveryOption = json_decode($order->getGlsDeliveryOption());
// If no delivery options are available, check if non-GLS shipments are allowed,
// or if delivery options are not enabled.
Expand Down Expand Up @@ -197,7 +207,7 @@ private function mapLabelData($shipment, $controllerModule, $version)
$data['returnRoutingData'] = false;
$data['addresses'] = [
'deliveryAddress' => $deliveryAddress,
'pickupAddress' => $this->preparePickupAddress()
'pickupAddress' => $this->preparePickupAddress($storeId)
];
$data['shippingDate'] = $this->shippingDate->calculate("Y-m-d", false);
$data['reference'] = $order->getIncrementId();
Expand Down Expand Up @@ -295,16 +305,32 @@ private function prepareNotificationEmail()
*
* @return array
*/
private function preparePickupAddress()
private function preparePickupAddress($storeId = null)
{
$address = [
"name1" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_NAME),
"street" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_STREET),
"houseNo" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_HOUSE_NO),
"zipCode" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_POSTCODE),
"city" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_CITY),
"countryCode" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_COUNTRY)
];
$customSenderAddressEnabled = $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);

if($customSenderAddressEnabled) {
$houseNumber = $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_HOUSE_NUMBER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
$houseNumberAddition = $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_HOUSE_NUMBER_ADDITION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
$houseNo = $houseNumber.$houseNumberAddition;
$address = [
"name1" => $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_COMPANY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId),
"street" => $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_STREET_NAME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId),
"houseNo" => trim($houseNo),
"zipCode" => $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId),
"city" => $this->scopeConfig->getValue(self::GLS_SENDER_ADDRESS_CITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId),
"countryCode" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
];
} else {
$address = [
"name1" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_NAME),
"street" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_STREET),
"houseNo" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_HOUSE_NO),
"zipCode" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_POSTCODE),
"city" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_CITY),
"countryCode" => $this->scopeConfig->getValue(self::XPATH_CONFIG_GENERAL_STORE_INFORMATION_COUNTRY)
];
}

$missing = $this->isDataMissing($address);
if ($missing) {
Expand Down Expand Up @@ -364,7 +390,7 @@ private function isDataMissing($data)
}

/**
* @param $shipment
* @param $shipment
*
* @return array
*/
Expand Down
36 changes: 36 additions & 0 deletions etc/adminhtml/system/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,40 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="sender_address" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use custom senders (return) address</label>
<field id="sender_address_enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[Please note: when enabled, you have to fill in all required fields (company, street name, house number, postcode and city).]]></comment>
</field>
<field id="company" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Company</label>
<config_path>tig_gls/sender_address/company</config_path>
</field>
<field id="street_name" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Street name</label>
<validate>required-entry</validate>
<config_path>tig_gls/sender_address/street_name</config_path>
</field>
<field id="house_number" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Housenumber</label>
<validate>required-entry</validate>
<config_path>tig_gls/sender_address/house_number</config_path>
</field>
<field id="house_number_addition" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>House number addition</label>
<config_path>tig_gls/sender_address/house_number_addition</config_path>
</field>
<field id="postcode" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Postcode</label>
<validate>required-entry</validate>
<config_path>tig_gls/sender_address/postcode</config_path>
</field>
<field id="city" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>City</label>
<validate>required-entry</validate>
<config_path>tig_gls/sender_address/city</config_path>
</field>
</group>
</include>