From 5bbb467e66ae3e4b3e94ff98993d5415175b5c75 Mon Sep 17 00:00:00 2001 From: Kapil Pandya Date: Fri, 8 May 2026 12:14:12 +0200 Subject: [PATCH 1/3] Add PHP latest version Added latest PHP 8 versions to make this module compatible with magento 2.4.6 => version. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 021163b..27fd17c 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/code4business/freeproduct2", "require": { "magento/module-sales-rule": "^101.2.3", - "php": "~7.1 || ~8.1" + "php": "~7.1 || ~8.1 || ~8.2 || ~8.3 || ~8.4 || ~8.5" }, "type": "magento2-module", "license": [ From 486685397693d2833f1a61a53bdac1aeb3950e78 Mon Sep 17 00:00:00 2001 From: Kapil Pandya Date: Fri, 8 May 2026 12:20:56 +0200 Subject: [PATCH 2/3] Update PHP version requirements in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 773ac68..127f0f1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The development and the function of the original Magento1 extension is described Requirements ------- -- PHP 7.4, 8.1 +- PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 - Magento >= 2.4.3-p1 Generally the last full release -1 version is tested and made to work. Older versions are not actively supported. @@ -54,4 +54,4 @@ Current localizations: License ------- -[Open Software Licence 3.0 (OSL-3.0)](http://opensource.org/licenses/osl-3.0.php) \ No newline at end of file +[Open Software Licence 3.0 (OSL-3.0)](http://opensource.org/licenses/osl-3.0.php) From 545287349adaf200bb3e0bdc41ba1add489c348d Mon Sep 17 00:00:00 2001 From: Kapil Pandya Date: Fri, 8 May 2026 13:04:57 +0200 Subject: [PATCH 3/3] Fix PHP 8+ compatibility: use strict comparisons and safe null checks Replace all loose null comparisons (==, !=) with strict (===, !==), replace == false/== true patterns with negation operators, add missing type hint and return type to updateExtensionAttributes, and fix unsafe count() on potentially non-Countable value in RemoveGiftItems. Co-Authored-By: Claude Sonnet 4.6 --- Observer/RemoveGiftItems.php | 5 +++-- Observer/ResetGiftItems.php | 12 ++++++------ SalesRule/Action/AbstractGiftAction.php | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Observer/RemoveGiftItems.php b/Observer/RemoveGiftItems.php index be155fc..9a85132 100644 --- a/Observer/RemoveGiftItems.php +++ b/Observer/RemoveGiftItems.php @@ -44,8 +44,9 @@ public function execute(\Magento\Framework\Event\Observer $observer) $quote = $this->checkoutSession->getQuote(); /** @var Quote\Item $quoteItem */ - if ($quote && (is_array($quote->getItems()) || is_object($quote->getItems())) && count($quote->getItems())) { - foreach ($quote->getItems() as $quoteItem) { + $quoteItems = $quote ? $quote->getItems() : null; + if (!empty($quoteItems)) { + foreach ($quoteItems as $quoteItem) { if ($quoteItem->getOptionByCode(GiftAction::ITEM_OPTION_UNIQUE_ID) instanceof Quote\Item\Option) { $quoteItem->isDeleted(true); diff --git a/Observer/ResetGiftItems.php b/Observer/ResetGiftItems.php index e5b33b4..909aaab 100644 --- a/Observer/ResetGiftItems.php +++ b/Observer/ResetGiftItems.php @@ -62,12 +62,12 @@ public function execute(Observer $observer) // In admin the quote items are empty although items exist if ($this->isAdminContext) { - if ((int)$quote->getItemsCount() > 0 && $quote->getItems() == null) { + if ((int)$quote->getItemsCount() > 0 && $quote->getItems() === null) { $quote->setItems($quote->getItemsCollection()->getItems()); } } - if ($quote->getItems() == null || $this->areGiftItemsReset) + if ($quote->getItems() === null || $this->areGiftItemsReset) { return; } @@ -161,13 +161,13 @@ protected function removeOldGiftQuoteItems(Quote $quote) * @param Quote $quote * @param ShippingAssignmentInterface $shippingAssignment */ - protected function updateExtensionAttributes(Quote $quote, $shippingAssignment) + protected function updateExtensionAttributes(Quote $quote, ShippingAssignmentInterface $shippingAssignment): void { - if ($quote->getExtensionAttributes() != null) + if ($quote->getExtensionAttributes() !== null) { $shippingAssignmentsExtension = $quote->getExtensionAttributes()->getShippingAssignments(); - if ($shippingAssignmentsExtension != null) + if ($shippingAssignmentsExtension !== null) { $shippingAssignmentsExtension[0] = $shippingAssignment; } @@ -231,7 +231,7 @@ private function filterItemsNotInList(array $items, array $itemsToRemove): array foreach ($items as $quoteItem) { - if (isset($itemsToRemove[$quoteItem->getItemId()]) == false) + if (!isset($itemsToRemove[$quoteItem->getItemId()])) { $filteredItems[] = $quoteItem; } diff --git a/SalesRule/Action/AbstractGiftAction.php b/SalesRule/Action/AbstractGiftAction.php index ff3bb19..ec7e21e 100644 --- a/SalesRule/Action/AbstractGiftAction.php +++ b/SalesRule/Action/AbstractGiftAction.php @@ -78,7 +78,7 @@ public function calculate($rule, $item, $qty) { $stateObject = $this->getAppliedRuleStorage($item); - if ($this->canApplyRule($item, $rule, $stateObject) == false) + if (!$this->canApplyRule($item, $rule, $stateObject)) { return $this->getDiscountData($item); } @@ -149,7 +149,7 @@ protected function canApplyRule(Quote\Item $item, Rule $rule, DataObject $stateO return ( $this->isValidAddressType($item) && - isset($appliedRuleIds[$rule->getId()]) == false + !isset($appliedRuleIds[$rule->getId()]) ); } @@ -186,7 +186,7 @@ protected function addAppliedRuleId(DataObject $stateObject, Rule $rule): void { $appliedRules = $stateObject->getData(static::APPLIED_FREEPRODUCT_RULE_IDS); - if ($appliedRules == null) + if ($appliedRules === null) { $appliedRules = []; }