Skip to content

Commit

Permalink
Release V1.0.41
Browse files Browse the repository at this point in the history
  • Loading branch information
roerlemans committed May 16, 2023
1 parent d984953 commit 2f90f2f
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace DHLParcel\Shipping\Block\Adminhtml\Authentication;

class Test extends \Magento\Config\Block\System\Config\Form\Field
class TestAuthentication extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var string
*/
protected $_template = 'DHLParcel_Shipping::authentication/test.phtml';
protected $_template = 'DHLParcel_Shipping::authentication/test_authentication.phtml';

/**
* Return element html
Expand All @@ -30,7 +30,7 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
*/
public function getAjaxUrl()
{
return $this->getUrl('dhlparcel_shipping/authentication/test');
return $this->getUrl('dhlparcel_shipping/authentication/testAuthentication');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;

class Test extends \Magento\Backend\App\Action
class TestAuthentication extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
Expand Down
16 changes: 14 additions & 2 deletions Model/Api/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,17 @@ protected function authenticate($refresh = false)
$cacheKey = $this->apiCache->createKey(0, 'accessToken');
$accessToken = $this->apiCache->load($cacheKey);
if ($accessToken === false || $refresh === true) {
$apiUser = $this->helper->getConfigData('api/user');
$key = $this->helper->getConfigData('api/key');

if ($apiUser === null || $key === null) {
$this->failedAuthentication = true;
return;
}

$response = $this->post(self::AUTH_API, [
'userId' => trim($this->helper->getConfigData('api/user')),
'key' => trim($this->helper->getConfigData('api/key')),
'userId' => trim($apiUser),
'key' => trim($key),
]);
if (!empty($response['accessToken'])) {
$this->apiCache->save($response['accessToken'], $cacheKey, [], 720);
Expand All @@ -195,6 +203,10 @@ protected function authenticate($refresh = false)
*/
public function testAuthenticate($userId, $key)
{
if (!isset($userId, $key)) {
return false;
}

$response = $this->post(self::AUTH_API, [
'userId' => trim($userId),
'key' => trim($key),
Expand Down
2 changes: 1 addition & 1 deletion Model/Service/Logic/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected function getShipperAddress($storeId, $group = '')
],
'address' => [
'countryCode' => $this->helper->getConfigData('shipper/country_code', $storeId),
'postalCode' => strtoupper($this->helper->getConfigData('shipper/' . $group . 'postal_code', $storeId)),
'postalCode' => strtoupper($this->helper->getConfigData('shipper/' . $group . 'postal_code', $storeId) ?? ''),
'city' => $this->helper->getConfigData('shipper/' . $group . 'city', $storeId),
'street' => $this->helper->getConfigData('shipper/' . $group . 'street', $storeId),
'number' => $this->helper->getConfigData('shipper/' . $group . 'house_number', $storeId),
Expand Down
4 changes: 4 additions & 0 deletions Model/Service/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function getDefaultOptions($order, $requiredOnly = false)
*/
public function getMethodKey($order)
{
if ($order->getShippingMethod() === null) {
return null;
}

return str_replace('dhlparcel_', '', $order->getShippingMethod());
}

Expand Down
27 changes: 26 additions & 1 deletion Observer/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected function processGrid($order)
$defaultOptions = $this->additionalServices($defaultOptions);

$sizes = $this->capabilityService->getSizes($storeId, $toCountry, $toPostalCode, $toBusiness, array_keys($defaultOptions));
$sizes = $this->overwriteMailboxType($sizes);

if (empty($sizes) || !is_array($sizes)) {
$skippableOptions = $this->presetService->filterSkippableDefaults($defaultOptions, $storeId);
Expand All @@ -126,6 +127,7 @@ protected function processGrid($order)

$defaultOptions = array_merge($requiredOptions, $allowedOptions);
$sizes = $this->capabilityService->getSizes($storeId, $toCountry, $toPostalCode, $toBusiness, array_keys($defaultOptions));
$sizes = $this->overwriteMailboxType($sizes);

if (empty($sizes) || !is_array($sizes)) {
$translations = $this->presetService->getTranslations();
Expand All @@ -136,6 +138,7 @@ protected function processGrid($order)

$packageKey = '';
$packageWeight = 1000000;

foreach ($sizes as $key => $package) {
if (isset($package['minWeightKg']) && isset($package['maxWeightKg'])) {
$packageSum = intval($package['minWeightKg']) + intval($package['maxWeightKg']);
Expand All @@ -147,7 +150,6 @@ protected function processGrid($order)
$packageWeight = $packageSum;
}
}

$pieces = [$this->createPiece($packageKey)];

$options = [];
Expand Down Expand Up @@ -212,6 +214,29 @@ protected function processForm($orderId)
return $tracks;
}

protected function overwriteMailboxType($sizes)
{
if ($this->request->getParam('method_override') !== 'mailbox' || !$this->request->getParam('mailbox_type')) {
return $sizes;
}

$mailboxType = $this->request->getParam('mailbox_type');
return array_filter($sizes, function ($size) use ($mailboxType) {
if (!isset($size['key'])) {
return true;
}

if ($mailboxType === 'envelop' && strtolower($size['key']) !== 'envelope') {
return false;
}

if ($mailboxType === 'no_envelope' && strtolower($size['key']) === 'envelope') {
return false;
}

return true;
});
}
protected function checkMailboxOverride($options)
{
if ($this->request->getParam('method_override') == 'mailbox' && array_key_exists('DOOR', $options)) {
Expand Down
30 changes: 26 additions & 4 deletions Ui/Bulk/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,20 @@ public function jsonSerialize()
$this->addOptionStack(
$options,
'create_mailbox',
__('Create mailbox labels'),
__('Create mailbox labels (0.5-2kg)'),
$this->urlPath . 'create',
['method_override' => 'mailbox']
['method_override' => 'mailbox', 'mailbox_type' => 'no_envelope']
);
}

$enabled = $this->helper->getConfigData('usability/bulk/create_envelope');
if ($enabled && !$skipCreate) {
$this->addOptionStack(
$options,
'create_envelope',
__('Create envelope labels (50-500g)'),
$this->urlPath . 'create',
['method_override' => 'mailbox', 'mailbox_type' => 'envelope']
);
}

Expand All @@ -72,9 +83,20 @@ public function jsonSerialize()
$this->addOptionStack(
$options,
'create_mailbox_dhl_only',
__('Create mailbox labels (only for DHL shipping methods)'),
__('Create mailbox labels (0.5-2kg, only for DHL shipping methods)'),
$this->urlPath . 'create',
['method_override' => 'mailbox', 'dhlparcel_only' => 'true', 'mailbox_type' => 'no_envelope']
);
}

$enabled = $this->helper->getConfigData('usability/bulk/create_envelope_dhl_only');
if ($enabled && !$skipCreate) {
$this->addOptionStack(
$options,
'create_envelope_dhl_only',
__('Create envelope labels (50-500g, only for DHL shipping methods)'),
$this->urlPath . 'create',
['method_override' => 'mailbox', 'dhlparcel_only' => 'true']
['method_override' => 'envelope', 'dhlparcel_only' => 'true', 'mailbox_type' => 'envelope']
);
}

Expand Down
8 changes: 5 additions & 3 deletions Ui/Column/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ protected function getLabelLinks($shipment)
// Build service options text
$serviceOptions = [];
$serviceCounter = 0;
foreach (explode(',', $piece->getServiceOptions()) as $serviceOption) {
if ($this->presetService->getTranslation($serviceOption) !== null) {
$serviceOptions[] = sprintf('<span data-key="%s" class="dhlparcel-shipping-service-option-chip">%s</span>', strtoupper($serviceOption), $this->presetService->getTranslation($serviceOption)) . (++$serviceCounter % 4 ? '' : '<br/>');
if ($piece->getServiceOptions() !== null) {
foreach (explode(',', $piece->getServiceOptions()) as $serviceOption) {
if ($this->presetService->getTranslation($serviceOption) !== null) {
$serviceOptions[] = sprintf('<span data-key="%s" class="dhlparcel-shipping-service-option-chip">%s</span>', strtoupper($serviceOption), $this->presetService->getTranslation($serviceOption)) . (++$serviceCounter % 4 ? '' : '<br/>');
}
}
}
$serviceOptionsText = '';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dhlparcel/magento2-plugin",
"description": "DHL Parcel plugin for Magento 2",
"type": "magento2-module",
"version": "1.0.40",
"version": "1.0.41",
"license": [
"OSL-3.0"
],
Expand Down
18 changes: 14 additions & 4 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</field>
<field id="test_authentication" translate="label comment" type="button" sortOrder="300"
showInDefault="1" showInWebsite="1" showInStore="1">
<frontend_model>DHLParcel\Shipping\Block\Adminhtml\Authentication\Test</frontend_model>
<frontend_model>DHLParcel\Shipping\Block\Adminhtml\Authentication\TestAuthentication</frontend_model>
<comment>Make sure to test your filled credentials. We will search for your account ID and
Organization ID
</comment>
Expand Down Expand Up @@ -120,7 +120,7 @@
showInWebsite="1" showInStore="1">
<label>Auto-enable: Shipment insurance</label>
<source_model>DHLParcel\Shipping\Model\Config\Source\ShipmentInsurance</source_model>
<comment>Additional transport insurance.</comment>
<comment>Applicable to both consumer and business shipments, not available for mailbox delivery. When enabled, the selected insurance option is added to your shipments (when available).</comment>
</field>
<field id="default_shipment_insurance_custom" translate="label" type="text" sortOrder="312"
showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -1041,7 +1041,12 @@
</field>
<field id="create_mailbox" translate="label" sortOrder="200" type="select" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Create mailbox labels</label>
<label>Create mailbox labels (0.5-2kg)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="create_envelope" translate="label" sortOrder="210" type="select" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Create envelope labels (50-500g)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="create_dhl_only" translate="label" sortOrder="300" type="select" showInDefault="1"
Expand All @@ -1051,7 +1056,12 @@
</field>
<field id="create_mailbox_dhl_only" translate="label" sortOrder="400" type="select"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Create mailbox labels (only for DHL shipping methods)</label>
<label>Create mailbox labels (0.5-2kg, only for DHL shipping methods)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="create_envelope_dhl_only" translate="label" sortOrder="410" type="select"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Create envelope labels (50-500g, only for DHL shipping methods)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="create_service_saturday" translate="label" sortOrder="500" type="select"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="DHLParcel_Shipping" setup_version="1.0.40">
<module name="DHLParcel_Shipping" setup_version="1.0.41">
<sequence>
<module name="Magento_Shipping"/>
<module name="Magento_Checkout"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

?>

<?php /* @var $block \DHLParcel\Shipping\Block\Adminhtml\Authentication\Test */ ?>
<?php /* @var $block \DHLParcel\Shipping\Block\Adminhtml\Authentication\TestAuthentication */ ?>
<script type="text/javascript">
require([
'jquery',
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/template/servicepoint-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
data-bind="text: DHLParcel_Shipping_ServicePointName()"></span></strong>.</p>
<div id="dhlparcel-shipping-servicepoint-info-error" style="display: none;"
data-bind="i18n: 'Please choose a DHL ServicePoint.'"></div>
<button id="dhlparcel-shipping-servicepoint-button"
<button id="dhlparcel-shipping-servicepoint-button" type="button"
data-bind="text: DHLParcel_Shipping_HasServicePoint() ? $t('Choose a different DHL ServicePoint') : $t('Please choose a DHL ServicePoint')">
</button>
</div>

0 comments on commit 2f90f2f

Please sign in to comment.