Download the PHP package yireo/magento2-common-view-models without Composer
On this page you can find all versions of the php package yireo/magento2-common-view-models. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package magento2-common-view-models
Common ViewModels for usage in Magento 2
Gathering of common useful ViewModels for usage in the XML layout.
Installation
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
In Magento 2.2.1 or newer, create a XML layout instruction:
In your example.phtml
:
Yireo\CommonViewModels\ViewModel\Product
Initialize the product with the data you have:
And then use it:
Yireo\CommonViewModels\ViewModel\CurrentProduct
Only working when the page is catalog/product/view
and when the id
is set in the URL. Initialize it with the request first:
And then use it:
The CurrentProduct
ViewModel extends the Product
ViewModel through injection.
Yireo\CommonViewModels\ViewModel\Products
Use existing filters:
or build your own:
Yireo\CommonViewModels\ViewModel\FormKey
Usage:
All versions of magento2-common-view-models with dependencies
magento/framework Version ^102.0|^103.0
php Version >=7.2.0