Author: Mage2 Developer

How to call Viewmodel in – Magento 2

Create Custom Js Component – Magento2

3 years ago
To create a custom Js component we need to create the below file as per folder structure. first, we create our test-component.js(view/web/js/test-component.js) file, define([ 'jquery', 'uiComponent', 'ko' ], function ($, Component, ko) { 'use strict'; let testComponent = Component.extend({ self: this, defaults: { template: 'Mage2_CustomRouter/test' }, initialize: function () { let self = this; this._super(); […]
Read More

Get cms block by identifier – Magento 2

3 years ago
For that, you can use Magento\Cms\Api\GetBlockByIdentifierInterface. No need to use Magento\Framework\Api\SearchCriteriaBuilder. /** * @var \Magento\Cms\Api\GetBlockByIdentifierInterface */ private $blockByIdentifier; public function __construct( GetBlockByIdentifierInterface $blockIdentifier ) { $this->blockByIdentifier = $blockIdentifier } Now you can get that page data passing blockIdentifier and storeId. $this->blockByIdentifier->execute($blockIdentifier, $storeId);  
Read More

Get cms page by identifier – Magento 2

3 years ago
For that, you can use Magento\Cms\Api\GetPageByIdentifierInterface. No need to use Magento\Framework\Api\SearchCriteriaBuilder. use Magento\Cms\Api\GetPageByIdentifierInterface. /** * @var \Magento\Cms\Api\GetPageByIdentifierInterface */ private $pageByIdentifier; public function __construct( GetPageByIdentifierInterface $pageByIdentifierInterface ) { $this->pageByIdentifier = $pageByIdentifier } Now you can get that page data passing pageIdentifier and storeId. $page = $this->pageByIdentifier->execute($pageIdentifier, $storeId);    
Read More

Create custom router in Magento 2

3 years ago
Custom routers provide a way to modify/replace existing route names with custom ones. For example, if you want to change the current route name learning to custompath you can achieve with it. Below is an example of it. To do that, we need to add code in frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\App\RouterList"> <arguments> […]
Read More

Create your account

chatsimple