You can simple get a block from template phtml file in Magento 2. There are two examples I will give you here. If you need to call a template block helloworld.phtml of Magebay_HelloWorld, please use the below code: If you need to call template block in CMS static Block or CMS Page in Magento 2, please use the below code: Hope … Continue reading “Magento 2 how to get a block template file phtml”
How to Get Base URL, Store URL and Current URL for Magento 2
Using Dependency Injection Here is the example code to get the store URLls in Magento 2 using dependency injection. In this, we might need to inject the object of \Magento\Store\Model\StoreManagerInterface class in the constructor of our module’s class. Using template file We also can use the functions in our view (.phtml) file as follows. Using Object Manager … Continue reading “How to Get Base URL, Store URL and Current URL for Magento 2”
Magento 2 add product to cart with custom price
Magento 2 add product to cart with custom price is very necessary for developer when building Magento extensions or doing projects in magento 2 because some time you want to custom price for separate Products . In order to add product to cart with custom price, You have to do 3 tasks : – Create … Continue reading “Magento 2 add product to cart with custom price”
Magento 2 How to use plugin.
When building Magento extension, sometime you have to overwrite core function in magento to have custom function. You can use Rewrite function in magento but it is not good solution. If you don’t want to change core class directly, You can use Magento 2 Plugin because it allows editing the behavior of any public class … Continue reading “Magento 2 How to use plugin.”
Magento 2 Extension Tutorial
A Magento extension is a block of PHP code – a combine of functions, added into Magento to extend its functionality. Magento extensions allow you to add custom features and functionality to every area of your Magento store including the front and back end, integrations with other web services, marketing tools, themes and more. Extensions are developed … Continue reading “Magento 2 Extension Tutorial”
How To Use Magento 2 Events and Observers
Magento 2 Events Events are dispatched by Magento 2 Modules whenever specific actions are triggered. When an event dispatches, it passes data to the observer that is configured to watch (or monitor) that event. You can dispatch Magento 2 Events using the Magento\Framework\Event\Manager class. This class can be obtained through dependency injection by defining the dependency in the constructor method of … Continue reading “How To Use Magento 2 Events and Observers”