From db8d5177a69ad91b49f8c0a01786544f28150dda Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Mon, 19 Oct 2026 16:56:24 -0400 Subject: [PATCH 1/5] magento-integration: release 1.0.1 with optional inventory and widget fonts --- CHANGELOG.md | 7 +++- Model/StockManagement.php | 51 +++++++++++++++++++++---- README.md | 1 + Test/Unit/Model/StockManagementTest.php | 36 ++++++++++++++++- composer.json | 7 +++- etc/csp_whitelist.xml | 5 +++ etc/module.xml | 2 +- 7 files changed, 96 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 363f4eb..c7b55ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## Unreleased +## 1.0.1 - 2026-10-19 + +- Install on stores without Magento Inventory (MSI): stock checks use Magento's default stock when MSI is not enabled. +- Allow the fonts of Hellotext popups, webchat and forms in the Content Security Policy. + +## 1.0.0 - 2026-10-17 - Track page views, products, carts and checkout activity through Hellotext.js. - Display Hellotext popups, webchat, WhatsApp widgets and forms. diff --git a/Model/StockManagement.php b/Model/StockManagement.php index 2245401..290cf96 100644 --- a/Model/StockManagement.php +++ b/Model/StockManagement.php @@ -9,8 +9,12 @@ use Hellotext\Tracking\Model\Data\StockResult; use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Module\Manager as ModuleManager; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Webapi\Rest\Response; use Magento\InventorySalesApi\Api\AreProductsSalableInterface; use Magento\InventorySalesApi\Api\StockResolverInterface; @@ -19,13 +23,16 @@ class StockManagement implements StockManagementInterface { + // Magento Inventory (MSI) is optional: its services are resolved only when it is enabled, + // so stores that removed or disabled it can still install and compile the module. public function __construct( private CollectionFactory $collections, private ScopeConfigInterface $config, private StoreManagerInterface $stores, - private StockResolverInterface $stockResolver, - private AreProductsSalableInterface $salability, - private Response $response + private Response $response, + private ModuleManager $modules, + private ObjectManagerInterface $objects, + private StockRegistryInterface $legacyStock ) {} public function getStock(array $productIds): StockResultInterface @@ -66,11 +73,9 @@ public function getStock(array $productIds): StockResultInterface $salable = []; if ($skus !== []) { - $website = $this->stores->getWebsite((int) $store->getWebsiteId()); - $stock = $this->stockResolver->execute('website', (string) $website->getCode()); - foreach ($this->salability->execute(array_values($skus), (int) $stock->getStockId()) as $result) { - $salable[$result->getSku()] = $result->isSalable(); - } + $salable = $this->modules->isEnabled('Magento_InventorySalesApi') + ? $this->inventorySalability(array_values($skus), (int) $store->getWebsiteId()) + : $this->legacySalability(array_values($skus)); foreach ($skus as $sku) { if (!array_key_exists($sku, $salable)) { throw new LocalizedException(__('Inventory did not return a result for every product.')); @@ -85,4 +90,34 @@ public function getStock(array $productIds): StockResultInterface ); return new StockResult($installation, $storeId, $business, $items); } + + /** @return array */ + private function inventorySalability(array $skus, int $websiteId): array + { + $website = $this->stores->getWebsite($websiteId); + $stock = $this->objects->get(StockResolverInterface::class)->execute('website', (string) $website->getCode()); + $salable = []; + foreach ($this->objects->get(AreProductsSalableInterface::class)->execute($skus, (int) $stock->getStockId()) as $result) { + $salable[$result->getSku()] = $result->isSalable(); + } + return $salable; + } + + /** + * Without MSI, Magento keeps one global stock whose status already accounts for quantity and backorders. + * + * @return array + */ + private function legacySalability(array $skus): array + { + $salable = []; + foreach ($skus as $sku) { + try { + $salable[$sku] = (int) $this->legacyStock->getProductStockStatusBySku($sku) === 1; + } catch (NoSuchEntityException) { + $salable[$sku] = false; + } + } + return $salable; + } } diff --git a/README.md b/README.md index 1ffcede..8fe3a7d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Connect your Magento store to Hellotext to track storefront activity and orders, - Magento Open Source 2.4.7 - PHP 8.2 or 8.3 +- Magento Inventory (MSI) is optional; without it, stock checks use Magento's default stock - An HTTPS storefront and a Magento API reachable by Hellotext ## Install diff --git a/Test/Unit/Model/StockManagementTest.php b/Test/Unit/Model/StockManagementTest.php index 4c9fc5a..86462d2 100644 --- a/Test/Unit/Model/StockManagementTest.php +++ b/Test/Unit/Model/StockManagementTest.php @@ -8,8 +8,12 @@ use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Module\Manager as ModuleManager; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Webapi\Rest\Response; use Magento\InventoryApi\Api\Data\StockInterface; use Magento\InventorySalesApi\Api\AreProductsSalableInterface; @@ -29,6 +33,8 @@ class StockManagementTest extends TestCase private Collection $collection; private AreProductsSalableInterface $salability; private StockResolverInterface $resolver; + private StockRegistryInterface $legacyStock; + private bool $inventoryEnabled = true; protected function setUp(): void { @@ -61,7 +67,35 @@ protected function setUp(): void $response->expects(self::once())->method('setHeader')->with( 'Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store', true ); - $this->subject = new StockManagement($collections, $config, $stores, $this->resolver, $this->salability, $response); + $modules = $this->createMock(ModuleManager::class); + $modules->method('isEnabled')->with('Magento_InventorySalesApi')->willReturnCallback(fn (): bool => $this->inventoryEnabled); + $objects = $this->createMock(ObjectManagerInterface::class); + $objects->method('get')->willReturnMap([ + [StockResolverInterface::class, $this->resolver], + [AreProductsSalableInterface::class, $this->salability], + ]); + $this->legacyStock = $this->createMock(StockRegistryInterface::class); + $this->subject = new StockManagement($collections, $config, $stores, $response, $modules, $objects, $this->legacyStock); + } + + public function testFallsBackToTheGlobalStockWhenInventoryIsDisabled(): void + { + $this->inventoryEnabled = false; + $this->collection->method('getItems')->willReturn([ + $this->product(11, 'SIMPLE'), $this->product(12, 'GONE'), $this->product(13, 'SOLD-OUT') + ]); + $this->legacyStock->method('getProductStockStatusBySku')->willReturnCallback(static function (string $sku): int { + if ($sku === 'GONE') { + throw new NoSuchEntityException(__('Missing')); + } + return $sku === 'SIMPLE' ? 1 : 0; + }); + $this->resolver->expects(self::never())->method('execute'); + $this->salability->expects(self::never())->method('execute'); + + $result = $this->subject->getStock([11, 12, 13]); + + self::assertSame([true, false, false], array_map(static fn ($item) => $item->getSalable(), $result->getItems())); } public function testChecksSimpleProductsParentsAndExactChildrenTogetherInTheWebsiteStock(): void diff --git a/composer.json b/composer.json index 20b4bed..d274d61 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "hellotext/magento", "description": "Connect Magento Open Source stores to Hellotext: storefront activity, customer identity, orders and catalog/customer import.", "type": "magento2-module", - "version": "1.0.0", + "version": "1.0.1", "license": "proprietary", "keywords": [ "magento", @@ -24,6 +24,7 @@ "magento/framework": "^103.0", "magento/module-backend": "^102.0", "magento/module-catalog": "^104.0", + "magento/module-catalog-inventory": "^100.4", "magento/module-checkout": "^100.4", "magento/module-config": "^101.2", "magento/module-configurable-product": "^100.4", @@ -31,13 +32,15 @@ "magento/module-csp": "^100.4", "magento/module-customer": "^103.0", "magento/module-integration": "^100.4", - "magento/module-inventory-sales-api": "^1.2", "magento/module-newsletter": "^100.4", "magento/module-quote": "^101.2", "magento/module-sales": "^103.0", "magento/module-store": "^101.1", "magento/module-webapi": "^100.4" }, + "suggest": { + "magento/module-inventory-sales-api": "Checks product availability in each website's stock when Magento Inventory (MSI) is installed." + }, "autoload": { "files": [ "registration.php" diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 2eb2c77..74f611f 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -17,6 +17,11 @@ https://www.hellotext.com + + + https://www.hellotext.com + + https://api.hellotext.com diff --git a/etc/module.xml b/etc/module.xml index c194dd6..e1f2fc3 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -4,6 +4,7 @@ + @@ -11,7 +12,6 @@ - From 483c45cc6db75bdf3104fb2828bb63fedb50c821 Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Mon, 19 Oct 2026 17:16:47 -0400 Subject: [PATCH 2/5] magento-integration: require msi classes before using its stock services --- Model/StockManagement.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Model/StockManagement.php b/Model/StockManagement.php index 290cf96..dc0edc0 100644 --- a/Model/StockManagement.php +++ b/Model/StockManagement.php @@ -73,7 +73,7 @@ public function getStock(array $productIds): StockResultInterface $salable = []; if ($skus !== []) { - $salable = $this->modules->isEnabled('Magento_InventorySalesApi') + $salable = $this->inventoryAvailable() ? $this->inventorySalability(array_values($skus), (int) $store->getWebsiteId()) : $this->legacySalability(array_values($skus)); foreach ($skus as $sku) { @@ -91,6 +91,14 @@ public function getStock(array $productIds): StockResultInterface return new StockResult($installation, $storeId, $business, $items); } + // Removing the MSI packages can leave a stale enabled flag in app/etc/config.php, so its classes must exist too. + private function inventoryAvailable(): bool + { + return $this->modules->isEnabled('Magento_InventorySalesApi') + && interface_exists(StockResolverInterface::class) + && interface_exists(AreProductsSalableInterface::class); + } + /** @return array */ private function inventorySalability(array $skus, int $websiteId): array { From 6b11988dedc1bc44fb82ae62bf5e893548923e5c Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Mon, 19 Oct 2026 17:26:36 -0400 Subject: [PATCH 3/5] magento-integration: support php 8.4 and describe 2.4.7 as the tested version --- .github/workflows/test.yml | 7 ++++++- CHANGELOG.md | 1 + README.md | 4 ++-- Test/README.md | 2 +- composer.json | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 765c412..e998fe4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,17 +49,20 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] steps: - uses: actions/checkout@v4 with: path: module + # Magento 2.4.7 does not run on PHP 8.4; that version gets the lint and isolated checks only. - uses: actions/checkout@v4 + if: matrix.php-version != '8.4' with: repository: magento/magento2 ref: 2.4.7-p10 path: magento - uses: actions/checkout@v4 + if: matrix.php-version != '8.4' with: repository: magento/inventory ref: 1.2.7-p10 @@ -77,12 +80,14 @@ jobs: find Api Block Console Controller Model Observer Plugin Setup Test view registration.php \( -name '*.php' -o -name '*.phtml' \) -print0 | xargs -0 -n1 php -l for test in Test/*.test.php; do php "$test"; done - name: Install Magento unit test dependencies + if: matrix.php-version != '8.4' run: | cp -R ../inventory/InventoryApi ../inventory/InventorySalesApi ../magento/app/code/Magento/ mkdir -p ../magento/app/code/Hellotext ln -s "$GITHUB_WORKSPACE/module" ../magento/app/code/Hellotext/Tracking composer --working-dir=../magento install --no-interaction --prefer-dist --no-progress - name: Run PHPUnit against Magento 2.4.7-p10 + if: matrix.php-version != '8.4' working-directory: magento run: vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Hellotext/Tracking/Test/Unit diff --git a/CHANGELOG.md b/CHANGELOG.md index c7b55ba..25289b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Install on stores without Magento Inventory (MSI): stock checks use Magento's default stock when MSI is not enabled. - Allow the fonts of Hellotext popups, webchat and forms in the Content Security Policy. +- Allow PHP 8.4, used by Magento 2.4.8. ## 1.0.0 - 2026-10-17 diff --git a/README.md b/README.md index 8fe3a7d..6d60ad4 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Connect your Magento store to Hellotext to track storefront activity and orders, ## Requirements -- Magento Open Source 2.4.7 -- PHP 8.2 or 8.3 +- Magento Open Source 2.4 (tested on 2.4.7) +- PHP 8.2, 8.3 or 8.4 - Magento Inventory (MSI) is optional; without it, stock checks use Magento's default stock - An HTTPS storefront and a Magento API reachable by Hellotext diff --git a/Test/README.md b/Test/README.md index c13d1a8..1212429 100644 --- a/Test/README.md +++ b/Test/README.md @@ -1,6 +1,6 @@ # Running tests -Use Node.js 22 and PHP 8.2 or 8.3. From the module directory: +Use Node.js 22 and PHP 8.2, 8.3 or 8.4. From the module directory: ```sh composer validate diff --git a/composer.json b/composer.json index d274d61..afcd7bc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "docs": "https://github.com/hellotext/magento/blob/main/docs/getting-started.md" }, "require": { - "php": ">=8.2 <8.4", + "php": ">=8.2 <8.5", "magento/framework": "^103.0", "magento/module-backend": "^102.0", "magento/module-catalog": "^104.0", From b9af08a9a0a8edfe685e701f9f5a5084f4fdd492 Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Mon, 19 Oct 2026 17:30:47 -0400 Subject: [PATCH 4/5] magento-integration: pin hellotext.js to the latest 2.x release --- CHANGELOG.md | 1 + Model/VersionInformation.php | 4 ++-- Test/status-contract.test.mjs | 6 +++--- view/frontend/web/js/bridge.js | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25289b6..ea59b37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Install on stores without Magento Inventory (MSI): stock checks use Magento's default stock when MSI is not enabled. - Allow the fonts of Hellotext popups, webchat and forms in the Content Security Policy. - Allow PHP 8.4, used by Magento 2.4.8. +- Load Hellotext.js from its latest 2.x release instead of the latest release, so a new major version needs a module release. ## 1.0.0 - 2026-10-17 diff --git a/Model/VersionInformation.php b/Model/VersionInformation.php index 81340e6..e187db0 100644 --- a/Model/VersionInformation.php +++ b/Model/VersionInformation.php @@ -7,8 +7,8 @@ class VersionInformation { - // The storefront follows the latest release; the exact version is whatever jsDelivr serves. - public const SDK_VERSION = 'latest'; + // The storefront follows the latest 2.x release; the exact version is whatever jsDelivr serves for @2. + public const SDK_VERSION = '2.x'; public function __construct(private ProductMetadataInterface $magento) {} diff --git a/Test/status-contract.test.mjs b/Test/status-contract.test.mjs index 6db7168..1dab322 100644 --- a/Test/status-contract.test.mjs +++ b/Test/status-contract.test.mjs @@ -30,7 +30,7 @@ test('status is a signed, store-scoped, safe version handshake', () => { assert.match(data, /concrete DTO deliberately returns \?string/); assert.doesNotMatch(data, /get(?:ApiRoot|Token|Secret|Customer|Order|Session)/); const sdkVersion = version.match(/SDK_VERSION = '([^']+)'/)[1]; - // The reported SDK channel matches the unversioned CDN URL used by the bridge. - assert.equal(sdkVersion, 'latest'); - assert.match(bridge, /https:\/\/cdn\.jsdelivr\.net\/npm\/@hellotext\/hellotext\/dist\/hellotext\.min\.js/); + // The reported SDK channel matches the major version pinned in the bridge's CDN URL. + assert.equal(sdkVersion, '2.x'); + assert.match(bridge, /https:\/\/cdn\.jsdelivr\.net\/npm\/@hellotext\/hellotext@2\/dist\/hellotext\.min\.js/); }); diff --git a/view/frontend/web/js/bridge.js b/view/frontend/web/js/bridge.js index aca8915..8149935 100644 --- a/view/frontend/web/js/bridge.js +++ b/view/frontend/web/js/bridge.js @@ -1,7 +1,8 @@ define(['Magento_Customer/js/customer-data', 'Hellotext_Tracking/js/cart-tracker'], function (customerData, createCartTracker) { 'use strict'; - var sdkUrl = 'https://cdn.jsdelivr.net/npm/@hellotext/hellotext/dist/hellotext.min.js'; + // Pinned to the major version, like the VTEX integration: 2.x releases arrive without a module release. + var sdkUrl = 'https://cdn.jsdelivr.net/npm/@hellotext/hellotext@2/dist/hellotext.min.js'; return function (config) { if (!hasSafeConfig(config) || window.hellotextMagentoStarted) { From f1d6c8de51145f6d611768de1dbaca9679e2560d Mon Sep 17 00:00:00 2001 From: Anyelo Petit Date: Mon, 19 Oct 2026 17:32:26 -0400 Subject: [PATCH 5/5] magento-integration: keep hellotext.js on its latest release --- CHANGELOG.md | 1 - Model/VersionInformation.php | 4 ++-- Test/status-contract.test.mjs | 6 +++--- view/frontend/web/js/bridge.js | 3 +-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea59b37..25289b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ - Install on stores without Magento Inventory (MSI): stock checks use Magento's default stock when MSI is not enabled. - Allow the fonts of Hellotext popups, webchat and forms in the Content Security Policy. - Allow PHP 8.4, used by Magento 2.4.8. -- Load Hellotext.js from its latest 2.x release instead of the latest release, so a new major version needs a module release. ## 1.0.0 - 2026-10-17 diff --git a/Model/VersionInformation.php b/Model/VersionInformation.php index e187db0..81340e6 100644 --- a/Model/VersionInformation.php +++ b/Model/VersionInformation.php @@ -7,8 +7,8 @@ class VersionInformation { - // The storefront follows the latest 2.x release; the exact version is whatever jsDelivr serves for @2. - public const SDK_VERSION = '2.x'; + // The storefront follows the latest release; the exact version is whatever jsDelivr serves. + public const SDK_VERSION = 'latest'; public function __construct(private ProductMetadataInterface $magento) {} diff --git a/Test/status-contract.test.mjs b/Test/status-contract.test.mjs index 1dab322..6db7168 100644 --- a/Test/status-contract.test.mjs +++ b/Test/status-contract.test.mjs @@ -30,7 +30,7 @@ test('status is a signed, store-scoped, safe version handshake', () => { assert.match(data, /concrete DTO deliberately returns \?string/); assert.doesNotMatch(data, /get(?:ApiRoot|Token|Secret|Customer|Order|Session)/); const sdkVersion = version.match(/SDK_VERSION = '([^']+)'/)[1]; - // The reported SDK channel matches the major version pinned in the bridge's CDN URL. - assert.equal(sdkVersion, '2.x'); - assert.match(bridge, /https:\/\/cdn\.jsdelivr\.net\/npm\/@hellotext\/hellotext@2\/dist\/hellotext\.min\.js/); + // The reported SDK channel matches the unversioned CDN URL used by the bridge. + assert.equal(sdkVersion, 'latest'); + assert.match(bridge, /https:\/\/cdn\.jsdelivr\.net\/npm\/@hellotext\/hellotext\/dist\/hellotext\.min\.js/); }); diff --git a/view/frontend/web/js/bridge.js b/view/frontend/web/js/bridge.js index 8149935..aca8915 100644 --- a/view/frontend/web/js/bridge.js +++ b/view/frontend/web/js/bridge.js @@ -1,8 +1,7 @@ define(['Magento_Customer/js/customer-data', 'Hellotext_Tracking/js/cart-tracker'], function (customerData, createCartTracker) { 'use strict'; - // Pinned to the major version, like the VTEX integration: 2.x releases arrive without a module release. - var sdkUrl = 'https://cdn.jsdelivr.net/npm/@hellotext/hellotext@2/dist/hellotext.min.js'; + var sdkUrl = 'https://cdn.jsdelivr.net/npm/@hellotext/hellotext/dist/hellotext.min.js'; return function (config) { if (!hasSafeConfig(config) || window.hellotextMagentoStarted) {