diff --git a/CHANGELOG.md b/CHANGELOG.md index dee5806b..46d5a5bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [3.7.7] - 1 February 2024 +### Fixed +- Fix DI compilation due to 3.7.6 + +## [3.7.6] - 1 February 2024 ### Fixed - Refactor loading performance of product data and category data in cart diff --git a/DataLayer/Tag/Product/ProductCategory.php b/DataLayer/Tag/Product/ProductCategory.php index 4484f935..c0460daf 100644 --- a/DataLayer/Tag/Product/ProductCategory.php +++ b/DataLayer/Tag/Product/ProductCategory.php @@ -3,24 +3,23 @@ namespace Yireo\GoogleTagManager2\DataLayer\Tag\Product; use Magento\Catalog\Api\Data\CategoryInterface; -use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Category; use Magento\Catalog\Model\Product; use Magento\Framework\Exception\NoSuchEntityException; -use Yireo\GoogleTagManager2\Util\GetCategoryFromProduct; +use Yireo\GoogleTagManager2\Util\CategoryProvider; class ProductCategory implements ProductTagInterface { private Product $product; - private GetCategoryFromProduct $getCategoryFromProduct; + private CategoryProvider $categoryProvider; /** - * @param GetCategoryFromProduct $getCategoryFromProduct + * @param CategoryProvider $categoryProvider */ public function __construct( - GetCategoryFromProduct $getCategoryFromProduct + CategoryProvider $categoryProvider ) { - $this->getCategoryFromProduct = $getCategoryFromProduct; + $this->categoryProvider = $categoryProvider; } /** @@ -45,7 +44,7 @@ public function get(): string } try { - return $this->getCategoryFromProduct->get($this->product)->getName(); + return $this->categoryProvider->getFirstByProduct($this->product)->getName(); } catch (NoSuchEntityException $e) { return ''; } diff --git a/Test/Integration/Util/GetCategoryFromProductTest.php b/Test/Integration/Util/GetCategoryFromProductTest.php deleted file mode 100644 index ef356512..00000000 --- a/Test/Integration/Util/GetCategoryFromProductTest.php +++ /dev/null @@ -1,83 +0,0 @@ -createCategory(3, 2, ['name' => 'Category 1', 'path' => '1/2/3']); - $this->createCategory(4, 3, ['name' => 'Category 2', 'path' => '1/2/3/4']); - $this->createCategory(5, 4, ['name' => 'Category 3', 'path' => '1/2/3/4/5']); - - $this->createProduct( - 1, - [ - 'name' => 'Product 1', - 'sku' => 'product1', - 'category_ids' => [3, 4, 5] - ] - ); - - $product = $this->getProduct(1); - $this->assertContains('3', $product->getCategoryIds()); - $this->assertContains('4', $product->getCategoryIds()); - $this->assertContains('5', $product->getCategoryIds()); - - $getCategoryFromProduct = ObjectManager::getInstance()->get(GetCategoryFromProduct::class); - $categories = $getCategoryFromProduct->getAll($product); - $this->assertTrue(count($categories) === 3, 'Actual count ' . count($categories)); - } - - /** - * @magentoAppIsolation enabled - * @magentoDbIsolation enabled - * @return void - */ - public function testGetAllWithProductInMultipleCategoriesAndOneDisabled() - { - $this->createCategory(3, 2, ['name' => 'Category A', 'path' => '1/2/3']); - $this->createCategory(4, 3, ['name' => 'Category B', 'path' => '1/2/3/4']); - $this->createCategory(5, 4, ['name' => 'Category C', 'path' => '1/2/3/4/5', 'is_active' => 0]); - - $this->createProduct( - 1, - [ - 'name' => 'Product 1', - 'sku' => 'product1', - 'category_ids' => [3, 4, 5] - ] - ); - - $product = $this->getProduct(1); - $this->assertContains('3', $product->getCategoryIds()); - $this->assertContains('4', $product->getCategoryIds()); - $this->assertContains('5', $product->getCategoryIds()); - - $getCategoryFromProduct = ObjectManager::getInstance()->get(GetCategoryFromProduct::class); - $categories = $getCategoryFromProduct->getAll($product); - $this->assertEquals(2, count($categories), 'Actual count ' . count($categories)); - } -} diff --git a/composer.json b/composer.json index 99ba3476..3313c247 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yireo/magento2-googletagmanager2", - "version": "3.7.6", + "version": "3.7.7", "license": "OSL-3.0", "type": "magento2-module", "homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2",