PHPackages                             yireo/magento2-common-view-models - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. yireo/magento2-common-view-models

ActiveMagento2-module[Templating &amp; Views](/categories/templating)

yireo/magento2-common-view-models
=================================

0.0.2(5y ago)6958↓50%3[1 PRs](https://github.com/yireo/Yireo_CommonViewModels/pulls)OSL-3.0PHPPHP &gt;=7.2.0

Since Aug 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/yireo/Yireo_CommonViewModels)[ Packagist](https://packagist.org/packages/yireo/magento2-common-view-models)[ RSS](/packages/yireo-magento2-common-view-models/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

Common ViewModels for usage in Magento 2
========================================

[](#common-viewmodels-for-usage-in-magento-2)

Gathering of common useful ViewModels for usage in the XML layout.

Installation
------------

[](#installation)

```
composer require yireo/magento2-common-view-models
bin/magento module:enable Yireo_CommonViewModels
```

Roadmap
-------

[](#roadmap)

There is no roadmap. Feel free to open an **Issue** to request creation of a new ViewModel or enhancement of an existing ViewModel. Feel free to submit PRs. I'll treat it respectfully once I drink my morning coffee.

Generic usage of ViewModels
---------------------------

[](#generic-usage-of-viewmodels)

In Magento 2.2.1 or newer, create a XML layout instruction:

```

        Yireo\CommonViewModels\ViewModel\Example

```

In your `example.phtml`:

```

```

`Yireo\CommonViewModels\ViewModel\Product`
------------------------------------------

[](#yireocommonviewmodelsviewmodelproduct)

Initialize the product with the data you have:

```
$productViewModel->setProduct($product);
$productViewModel->setProductById($productId);
$productViewModel->setProductBySku($productSku);
```

And then use it:

```
$productViewModel->getProduct();
$productViewModel->getSku();
```

`Yireo\CommonViewModels\ViewModel\CurrentProduct`
-------------------------------------------------

[](#yireocommonviewmodelsviewmodelcurrentproduct)

Only working when the page is `catalog/product/view` and when the `id` is set in the URL. Initialize it with the request first:

```
$currentProductViewModel->initialize();
```

And then use it:

```
$currentProductViewModel->getProduct();
$currentProductViewModel->getSku();
```

The `CurrentProduct` ViewModel extends the `Product` ViewModel through injection.

`Yireo\CommonViewModels\ViewModel\Products`
-------------------------------------------

[](#yireocommonviewmodelsviewmodelproducts)

Use existing filters:

```
$productsViewModel->getProductsByName('%hoodie%');
$productsViewModel->getProductsBySku('B01%');
```

or build your own:

```
$searchCriteriaBuilder = $productsViewModel->getSearchCriteriaBuilder();
$productsViewModel->getProducts($searchCriteriaBuilder->create());
```

`Yireo\CommonViewModels\ViewModel\FormKey`
------------------------------------------

[](#yireocommonviewmodelsviewmodelformkey)

Usage:

```
$formkeyViewModel->getToken();
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~333 days

Total

2

Last Release

2113d ago

PHP version history (2 changes)0.0.1PHP &gt;=7.0.0

0.0.2PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1373981?v=4)[Yireo](/maintainers/yireo)[@yireo](https://github.com/yireo)

---

Top Contributors

[![jissereitsma](https://avatars.githubusercontent.com/u/7670482?v=4)](https://github.com/jissereitsma "jissereitsma (20 commits)")

---

Tags

magento2-modulemagentocomposer-installer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yireo-magento2-common-view-models/health.svg)

```
[![Health](https://phpackages.com/badges/yireo-magento2-common-view-models/health.svg)](https://phpackages.com/packages/yireo-magento2-common-view-models)
```

###  Alternatives

[smile/elasticsuite

Magento 2 merchandising and search engine built on ElasticSearch

8044.5M33](/packages/smile-elasticsuite)[yireo/magento2-googletagmanager2

Add Google Tag Manager to Magento

167930.4k5](/packages/yireo-magento2-googletagmanager2)[yireo/magento2-webp2

Magento 2 module to add WebP support to the Magento frontend

2091.2M7](/packages/yireo-magento2-webp2)[yireo/magento2-extensionchecker

Scan the code of a Magento module

96151.6k3](/packages/yireo-magento2-extensionchecker)[yireo/magento2-whoops

Magento 2 module adding Whoops error handling

102703.5k](/packages/yireo-magento2-whoops)[yireo/magento2-checkouttester2

Checkout Tester for Magento 2

93477.4k1](/packages/yireo-magento2-checkouttester2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
