From 4abee4570e91a64f54a010ba7e6be1cce80320e9 Mon Sep 17 00:00:00 2001 From: Sander Merks Date: Tue, 24 Jan 2023 13:38:54 +0100 Subject: [PATCH] Add set method in both CurrentCategory and CurrentProduct --- Service/CurrentCategory.php | 28 +++++++++++++++++++++++----- Service/CurrentProduct.php | 28 +++++++++++++++++++++++----- composer.json | 2 +- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Service/CurrentCategory.php b/Service/CurrentCategory.php index b655836..f37dfd7 100644 --- a/Service/CurrentCategory.php +++ b/Service/CurrentCategory.php @@ -4,11 +4,14 @@ namespace WeProvide\Core\Service; -use Magento\Catalog\Model\Category; +use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Framework\Registry; class CurrentCategory { + /** @var string */ + protected const CURRENT_CATEGORY = 'current_category'; + /** @var Registry */ protected $registry; @@ -22,10 +25,25 @@ public function __construct( } /** - * @return Category|null + * Gets the current category + * + * @return CategoryInterface|null */ - public function getCurrentCategory(): ?Category + public function getCurrentCategory(): ?CategoryInterface { - return $this->registry->registry('current_category'); + return $this->registry->registry(static::CURRENT_CATEGORY); + } + + /** + * Sets the current category + * + * @param CategoryInterface|null $category + * @return CurrentCategory + */ + public function setCurrentCategory(?CategoryInterface $category): CurrentCategory + { + $this->registry->register(static::CURRENT_CATEGORY, $category); + + return $this; } -} \ No newline at end of file +} diff --git a/Service/CurrentProduct.php b/Service/CurrentProduct.php index c9390fe..9de2c5b 100644 --- a/Service/CurrentProduct.php +++ b/Service/CurrentProduct.php @@ -4,11 +4,14 @@ namespace WeProvide\Core\Service; -use Magento\Catalog\Model\Product; +use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\Registry; class CurrentProduct { + /** @var string */ + protected const CURRENT_PRODUCT = 'current_product'; + /** @var Registry */ protected $registry; @@ -22,10 +25,25 @@ public function __construct( } /** - * @return Product|null + * Gets the current product + * + * @return ProductInterface|null */ - public function getCurrentProduct(): ?Product + public function getCurrentProduct(): ?ProductInterface { - return $this->registry->registry('current_product'); + return $this->registry->registry(static::CURRENT_PRODUCT); + } + + /** + * Sets the current product + * + * @param ProductInterface|null $product + * @return CurrentProduct + */ + public function setCurrentProduct(?ProductInterface $product): CurrentProduct + { + $this->registry->register(static::CURRENT_PRODUCT, $product); + + return $this; } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index d9d333f..39712e3 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "weprovide/magento2-core", "description": "", "type": "magento2-module", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "authors": [ {