Skip to content

Commit a791992

Browse files
committed
Luma Plugin - v1.0.52
1 parent 7694b8d commit a791992

10 files changed

Lines changed: 166 additions & 39 deletions

File tree

CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

Controller/Adminhtml/Log/Debug.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace DHLParcel\Shipping\Controller\Adminhtml\Log;
4+
5+
class Debug extends \Magento\Backend\App\Action
6+
{
7+
protected $dir;
8+
9+
public function __construct(
10+
\Magento\Backend\App\Action\Context $context,
11+
\Magento\Framework\Filesystem\DirectoryList $dir
12+
) {
13+
$this->dir = $dir;
14+
parent::__construct($context);
15+
}
16+
17+
public function execute()
18+
{
19+
$result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
20+
$result->setHeader('Content-Type', 'text/html');
21+
$logFile = $this->_request->getParam('log');
22+
if ($logFile === null) {
23+
$fileList = [];
24+
foreach (scandir($this->dir->getRoot() . '/var/log/') as $file) {
25+
if ($file !== '.' && $file !== '..') {
26+
$url = $this->getUrl('dhlparcel_shipping/log/debug', ['log' => $file]);
27+
$fileList[] = '<li><a href="' . $url . '" target="_blank">' . $file . '</a></li>';
28+
}
29+
}
30+
$output = implode('', $fileList);
31+
32+
$output .= "<h3>Vendors:</h3>";
33+
34+
foreach (scandir($this->dir->getRoot() . '/vendor/') as $file) {
35+
if ($file !== '.' && $file !== '..') {
36+
$fileList[] = '<li>' . $file . '</li>';
37+
}
38+
}
39+
40+
41+
$output .= implode('', $fileList);
42+
43+
return $result->setContents("<html><head><style>body{background-color: #222;color: #CCC} a{color: #CCC}</style></head><body><ul>$output</ul></body></html>");
44+
} else {
45+
$logFile = $this->dir->getRoot() . '/var/log/' . $logFile;
46+
47+
if (file_exists($logFile)) {
48+
$output = file_get_contents($logFile);
49+
if (empty($output)) {
50+
$output = __('Log file is empty');
51+
}
52+
} else {
53+
$output = __('Log file not found');
54+
}
55+
return $result->setContents("<html><head><style>body{background-color: #222;color: #CCC}</style></head><body><pre>$output</pre></body></html>");
56+
}
57+
}
58+
}

Model/Carrier.php

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ public function __construct(
105105
$this->storeManager = $storeManager;
106106
}
107107

108+
/**
109+
* Ensure that the RateRequest always has store and website IDs set. Hyvä is way stricter compared to Luma in this
110+
* regard.
111+
* @param \Magento\Quote\Model\Quote\Address\RateRequest $request
112+
* @return \Magento\Quote\Model\Quote\Address\RateRequest
113+
*/
114+
protected function ensureRequestScope(\Magento\Quote\Model\Quote\Address\RateRequest $request)
115+
{
116+
$storeId = (int) $request->getStoreId();
117+
$websiteId = (int) $request->getWebsiteId();
118+
if ($storeId === 0 || $websiteId === 0) {
119+
$store = $this->storeManager->getStore();
120+
$request->setStoreId((int) $store->getId());
121+
$request->setWebsiteId((int) $store->getWebsiteId());
122+
}
123+
return $request;
124+
}
125+
108126
/**
109127
* The DHL Shipping shipping carrier does not calculate rates.
110128
* @param \Magento\Quote\Model\Quote\Address\RateRequest $request
@@ -113,6 +131,9 @@ public function __construct(
113131
*/
114132
public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request)
115133
{
134+
135+
$this->ensureRequestScope($request);
136+
116137
$this->debugLogger->info('CARRIER ### initiating collect rates', $request->toArray());
117138
/** @var \Magento\Shipping\Model\Rate\Result $result */
118139
$result = $this->_rateFactory->create();
@@ -223,17 +244,50 @@ protected function getShippingMethod(
223244
return null;
224245
}
225246

226-
$method->setPrice($rate['price'] + $serviceCost);
247+
$finalPrice = $rate['price'] + $serviceCost;
248+
$method->setPrice($finalPrice);
227249
$method->setCost($rate['cost']);
250+
$this->debugLogger->info("CARRIER method $methodKey variable rate price set", [
251+
'ratePrice' => $rate['price'],
252+
'serviceCost' => $serviceCost,
253+
'finalPrice' => $finalPrice,
254+
]);
228255
} else {
229-
$method->setPrice($this->getConfigData('shipping_methods/' . $methodKey . '/price') + $serviceCost);
256+
$configPrice = $this->getConfigData('shipping_methods/' . $methodKey . '/price');
257+
$finalPrice = $configPrice + $serviceCost;
258+
$method->setPrice($finalPrice);
259+
$this->debugLogger->info("CARRIER method $methodKey fixed price set", [
260+
'configPrice' => $configPrice,
261+
'serviceCost' => $serviceCost,
262+
'finalPrice' => $finalPrice,
263+
]);
230264
}
231265

232-
if ($request->getFreeShipping() || $request->getPackageQty() == $this->cartService->getFreeBoxesCount($request)) {
266+
$freeShippingFlag = $request->getFreeShipping();
267+
$packageQty = $request->getPackageQty();
268+
$freeBoxesCount = $this->cartService->getFreeBoxesCount($request);
269+
270+
// Only consider it free shipping if:
271+
// 1. The free shipping flag is explicitly set, OR
272+
// 2. packageQty equals freeBoxesCount AND both are greater than 0
273+
// (prevents false positive when both are 0 due to empty/stale request data)
274+
$isFreeShipping = $freeShippingFlag || ($packageQty > 0 && $packageQty == $freeBoxesCount);
275+
276+
$this->debugLogger->info("CARRIER method $methodKey free shipping check", [
277+
'freeShippingFlag' => $freeShippingFlag,
278+
'packageQty' => $packageQty,
279+
'freeBoxesCount' => $freeBoxesCount,
280+
'isFreeShipping' => $isFreeShipping,
281+
'priceBeforeFreeShippingCheck' => $method->getPrice(),
282+
]);
283+
284+
if ($isFreeShipping) {
233285
if (boolval($this->getConfigData('usability/discount_after_coupon/always_charge_servicecosts'))) {
234286
$method->setPrice($serviceCost);
287+
$this->debugLogger->info("CARRIER method $methodKey set to service cost only due to free shipping", ['serviceCost' => $serviceCost]);
235288
} else {
236289
$method->setPrice('0.00');
290+
$this->debugLogger->info("CARRIER method $methodKey set to 0.00 due to free shipping");
237291
}
238292
}
239293

@@ -283,6 +337,8 @@ public function getTracking($tracking)
283337

284338
protected function getMethodTitle(\Magento\Quote\Model\Quote\Address\RateRequest $request, $key, $titleKey = 'title')
285339
{
340+
$this->ensureRequestScope($request);
341+
286342
// Default
287343
$title = $this->getConfigData('shipping_methods/' . $key . '/' . $titleKey);
288344
if ($titleKey !== 'title' && empty($title)) {

Model/ResourceModel/Carrier/RateManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ protected function _construct()
9696
/**
9797
* @param \Magento\Quote\Model\Quote\Address\RateRequest $request
9898
* @param $method
99-
* @return array
99+
* @return array|false
100100
* @throws \Magento\Framework\Exception\LocalizedException
101101
*/
102102
public function getRate(\Magento\Quote\Model\Quote\Address\RateRequest $request, $method)
103103
{
104+
// Validate that the request has items to prevent stale session data issues
105+
if (!$request->getAllItems() || count($request->getAllItems()) === 0) {
106+
return false;
107+
}
108+
104109
$connection = $this->getConnection();
105110

106111
$websiteId = 0;

Model/Service/DeliveryServices.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DHLParcel\Shipping\Helper\Data;
66
use DHLParcel\Shipping\Model\Data\DeliveryServicesAvailabilityFactory;
77
use DHLParcel\Shipping\Model\Data\Capability\OptionFactory;
8+
use Psr\Log\LoggerInterface;
89

910
class DeliveryServices
1011
{
@@ -19,6 +20,7 @@ class DeliveryServices
1920
protected $helper;
2021
protected $availabilityFactory;
2122
protected $optionFactory;
23+
protected LoggerInterface $logger;
2224

2325
protected $availableOptions = [
2426
self::NO_NEIGHBOUR,
@@ -29,18 +31,20 @@ class DeliveryServices
2931

3032
public function __construct(
3133
\Magento\Framework\View\Asset\Repository $assetRepository,
32-
\Magento\Framework\Pricing\Helper\Data $priceHelper,
33-
\Magento\Tax\Helper\Data $taxHelper,
34-
Data $helper,
35-
DeliveryServicesAvailabilityFactory $availabilityFactory,
36-
OptionFactory $optionFactory
34+
\Magento\Framework\Pricing\Helper\Data $priceHelper,
35+
\Magento\Tax\Helper\Data $taxHelper,
36+
Data $helper,
37+
DeliveryServicesAvailabilityFactory $availabilityFactory,
38+
OptionFactory $optionFactory,
39+
LoggerInterface $logger
3740
) {
3841
$this->assetRepository = $assetRepository;
3942
$this->priceHelper = $priceHelper;
4043
$this->taxHelper = $taxHelper;
4144
$this->helper = $helper;
4245
$this->availabilityFactory = $availabilityFactory;
4346
$this->optionFactory = $optionFactory;
47+
$this->logger = $logger;
4448
}
4549

4650
public function getToBusiness()
@@ -106,7 +110,17 @@ public function getAvailability($options, $subtotal = 0, $selections = [], $stor
106110
$availability->enabled = boolval(count($availability->serviceData) > 0);
107111

108112
// Selections
109-
$availability->selectedServices = $this->sanitizeData($selections);
113+
$selectableServices = array_column($availability->serviceData, 'value');
114+
$selectedServicesSanitized = $this->sanitizeData($selections);
115+
$availability->selectedServices = array_values(
116+
array_intersect($selectedServicesSanitized, $selectableServices)
117+
);
118+
119+
$this->logger->info('DeliveryServices getAvailability', [
120+
'selectableServices' => $selectableServices,
121+
'selectedServicesSanitized' => $selectedServicesSanitized,
122+
'selectedServices' => $availability->selectedServices,
123+
]);
110124

111125
// Exclusions
112126
$exclusions = [];
@@ -277,20 +291,10 @@ protected function getServiceData($code, $title, $description, $subtotal, $store
277291
protected function getTaxPrice($serviceCost, $store = null)
278292
{
279293
if ($this->taxHelper->getShippingPriceDisplayType($store) === \Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX) {
280-
return '+ ' . $this->priceHelper->currencyByStore(
281-
$serviceCost,
282-
$store,
283-
true,
284-
false
285-
);
294+
return '+ ' . $this->priceHelper->currencyByStore($serviceCost, $store, true, false);
286295
}
287296

288-
return '+ ' . $this->priceHelper->currencyByStore(
289-
$this->taxHelper->getShippingPrice($serviceCost, true, null, null, $store),
290-
$store,
291-
true,
292-
false
293-
);
297+
return '+ ' . $this->priceHelper->currencyByStore($this->taxHelper->getShippingPrice($serviceCost, true, null, null, $store), $store, true, false);
294298
}
295299

296300
protected function sanitizeData($array)

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@ DHL offers a convenient plug-in for Magento 2 online stores. This plug-in allows
77
- If you've installed a previous version with zip extraction, please remove the files found in `app/code/DHLParcel/Shipping` and proceed with the installation instructions (can be either composer or zip extraction).
88

99
- If you're installed a previous version with composer with the recommended version range, just run the following commands to complete the update
10-
`composer update dhlparcel/magento2-plugin:~1.0.0`
11-
`php bin/magento setup:upgrade`
12-
`php bin/magento setup:di:compile (only for production environments)`
10+
`composer update dhlparcel/magento2-plugin:~1.0.0`
11+
`php bin/magento setup:upgrade`
12+
`php bin/magento setup:di:compile (only for production environments)`
1313

1414
## Installation with composer
1515
- Add the plugin to your composer with the command (recommended version range)
16-
`composer require dhlparcel/magento2-plugin:~1.0.0`
16+
`composer require dhlparcel/magento2-plugin:~1.0.0`
1717

1818
- Enable the DHL module by executing the following from the Magento root:
19-
`php bin/magento module:enable DHLParcel_Shipping`
19+
`php bin/magento module:enable DHLParcel_Shipping`
2020

2121
- Upgrade the database
22-
`php bin/magento setup:upgrade`
22+
`php bin/magento setup:upgrade`
2323

2424
- When running in production, complete the installation by recompiling
25-
`php bin/magento setup:di:compile`
25+
`php bin/magento setup:di:compile`
2626

2727
## Installation with zip extraction
2828
- Go to the Magento 2 directory
2929

3030
- Extract the contents of the `magento2.zip` file in a new directory: `app/code/DHLParcel/Shipping`
31-
(If you're upgrading, remove the old files first)
31+
(If you're upgrading, remove the old files first)
3232

3333
- De plugin uses de Guzzle package to communicate with the API. Add Guzzle to the Magento root `composer.json`.
34-
`composer require guzzlehttp/guzzle`
34+
`composer require guzzlehttp/guzzle`
3535

3636
- De plugin uses fpdi-fpdf for merging pdf's. Add fpdi-fpdf to the Magento root `composer.json`.
37-
`composer require setasign/fpdi-fpdf`
37+
`composer require setasign/fpdi-fpdf`
3838

3939
- Enable the DHL module by executing the following from the Magento root:
40-
`php bin/magento module:enable DHLParcel_Shipping`
40+
`php bin/magento module:enable DHLParcel_Shipping`
4141

4242
- Upgrade the database
43-
`php bin/magento setup:upgrade`
43+
`php bin/magento setup:upgrade`
4444

4545
- When running in production, complete the installation by recompiling
46-
`php bin/magento setup:di:compile`
46+
`php bin/magento setup:di:compile`
4747

4848
## When updating with zip with a version before 1.0.10 to current
4949

5050
- De plugin uses fpdi-fpdf for merging pdf's. Add fpdi-fpdf to the Magento root `composer.json`.
51-
`composer require setasign/fpdi-fpdf`
51+
`composer require setasign/fpdi-fpdf`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "dhlparcel/magento2-plugin",
33
"description": "DHL Parcel plugin for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.0.51",
5+
"version": "1.0.52",
66
"license": [
77
"OSL-3.0"
88
],

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2020
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
21-
<module name="DHLParcel_Shipping" setup_version="1.0.51">
21+
<module name="DHLParcel_Shipping" setup_version="1.0.52">
2222
<sequence>
2323
<module name="Magento_Shipping"/>
2424
<module name="Magento_Checkout"/>

i18n/en_US.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ Email,Email
241241
"You have selected","You have selected"
242242
"Please choose a DHL ServicePoint.","Please choose a DHL ServicePoint."
243243
"Please choose a DHL ServicePoint","Please choose a DHL ServicePoint"
244+
"Please select at least one delivery service.","Please select at least one delivery service."
245+
"Please check your DHL selections.","Please check your DHL selections."
244246
"Choose a different DHL ServicePoint","Choose a different DHL ServicePoint"
245247
"Field ","Field "
246248
" is required."," is required."

i18n/nl_NL.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ Phonenumber,Telefoonnummer
194194
Placed from IP,Geplaatst vanaf IP
195195
"Please choose a DHL ServicePoint.","Kies een DHL punt."
196196
"Please choose a DHL ServicePoint","Kies een DHL punt"
197+
Please select at least one delivery service.,Selecteer minimaal een extra dienst.
198+
Please check your DHL selections.,Controleer je DHL keuzes.
197199
Please choose the moment of delivery,Kies bezorgmoment
198200
Please correct Table Rates File Format.,Corrigeer het Table Rates bestandformaat
199201
Please correct Table Rates format in the Row #%1.,Corrigeer het Table Rates format in rij #%1
@@ -219,6 +221,7 @@ Same-day delivery,DHL Vandaag
219221
Same-day delivery,Vandaag bezorgen
220222
Saturday delivery (9 AM to 3 PM),Zaterdagbezorging (tussen 9u en 15u)
221223
Saturday delivery,Zaterdagbezorging
224+
Select a different DHL point,Selecteer een ander DHL punt
222225
Select this ServicePoint,Kies dit DHL punt
223226
Selected date has passed,Gekozen datum ligt in het verleden
224227
Send in\n%s days,Verzend\n%s dagen

0 commit comments

Comments
 (0)