Skip to content

About

Magento 2: the product of the current product page for view models, without the core registry. Free, OSL-3.0. Install from repo.webcode.bg/public.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Webcode_CurrentProduct

The product of the current product page, for view models and blocks — without the deprecated core registry (Magento\Framework\Registry, Magento\Catalog\Helper\Data::getProduct()).

How

An observer on catalog_controller_product_init_after (storefront) keeps the product that the product page controller has just loaded. Inject Webcode\CurrentProduct\Model\Catalog\CurrentProduct and call get():

public function __construct(
    private readonly \Webcode\CurrentProduct\Model\Catalog\CurrentProduct $currentProduct
) {
}

$product = $this->currentProduct->get();

Outside a product page get() returns an empty product (no id), never null.

Used by other Webcode modules, for example webcode/module-breadcrumbs.

Installation

Webcode's free modules are installed from our own Composer repository — they are not published on Packagist.

composer config repositories.webcode composer https://repo.webcode.bg/public
composer require webcode/module-current-product
bin/magento module:enable Webcode_CurrentProduct
bin/magento setup:upgrade

Compatibility

Magento Open Source and Mage-OS 2.4.7–2.4.9, PHP 8.3–8.5.

License

OSL-3.0 and AFL-3.0, like Magento itself.

About

Made by Webcode, a Magento development and support studio from Bulgaria.

About

Magento 2: the product of the current product page for view models, without the core registry. Free, OSL-3.0. Install from repo.webcode.bg/public.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages