Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Add set method in both CurrentCategory and CurrentProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Merks authored and mischabraam committed Jan 24, 2023
1 parent 99e6ba2 commit 4abee45
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
28 changes: 23 additions & 5 deletions Service/CurrentCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
}
28 changes: 23 additions & 5 deletions Service/CurrentProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "weprovide/magento2-core",
"description": "",
"type": "magento2-module",
"version": "1.3.0",
"version": "1.3.1",
"license": "MIT",
"authors": [
{
Expand Down

0 comments on commit 4abee45

Please sign in to comment.