-
How to get magento2 base url
How to get magento2 base url. You want to get magento2 base url for your current store then you can follow this post. During your daily work, several time, you need to current store base url and at Magento 1.x version you can get base url using Mage::getBaseUrl();As Magento2, do not used factory patterns, so the code like Mage::getBaseUrl(); is not exist by which you can base URL.But at Magento2, you should use StoreManager object and using $this->_storeManager->getStore()->getBaseUrl() you can get base url. Magento2, use interface, injection of class, that you should Inject. Magento\Store\Model\StoreManagerInterface at Model, Resource model, Block, Helper classes for getting base url using below code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance();…
-
Magento2 get admin url
Magento2 get admin URL Magento2 get admin url.If want to get admin URL to Magento 2 then you can try below Solution In order to get admin URL ,you need to inject the Magento_Backend ‘s helper class Magento\Backend\Helper\Data to __construct() function. /** * @var Magento\Backend\Helper\Data */ protected $HelperBackend; public function __construct( .... \Magento\Backend\Helper\Data $HelperBackend .... ) { ... $this->HelperBackend = $HelperBackend; ... } /** * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function getAdminUrl() { echo $this->HelperBackend->getHomePageUrl(); } Here you will get Magento 2 get admin url from getAdminUrl() which basically return Magento_Backend module’s getHomePageUrl() function, This function also given admin home page url.
-
Magento2 redirection from Observer
Magento2 redirection from Observer Magento2 redirection from Observer needs serval times.In Some events, you need to forcefully redirect to some pages basic your business logic. At magento 1.x,we can do using Mage::app()->getResponse()->setRedirect(‘YourRedirectUrl’)->sendResponse(); Something is required forMagent0 2.X version.This version uses modern technologies Namespace, interface, Factory class etc.So there not easy to do a redirection from an Observer. Most case, developer need to implement forceful redirection to Observer as per their client requirement =========================================== I have found a solution by myself by doing a research If you want to do that then you should below inject two classes. First, \Magento\Framework\App\ResponseFactory which responsible for redirection, Another class which\Magento\Framework\UrlInterface will make…
-
magento2 get base url and media url and static url
magento2 get base url and media url and static url magento2 get base url and media url and static url. Whenever you are working on magento2 then a lot of times you need to get base URL and media URL and static url. From this blog, you base url, media url, static content url in Magento2.Magento2 basically, use interface /* This is an interface Class */ Magento\Store\Model\StoreManagerInterface And this class have a function Store() which is provide store data. After that, using getBaseUrl() over Store() you can get base url and also get Media URL. /* Using Direct Object Manager */ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); /* Get store manager */ $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface'); // BASE URL $baseUrl = $storeManager->getStore()->getBaseUrl(); // MEDIA URL…
-
Magento2 get cart and checkout link in block or phtml
Magento2 get cart and checkout link in block or phtml In Magento2 get cart and checkout link in block or phtml then you need to call getUrl() method.It is every easy to get those url at Phtml or block class. Also, there is no need to write layout xml code for getting cart and checkout page url at magento 2. If want to get cart & checkout link at PHTML file then try below code: Checkout Url <?php echo $block->getUrl('checkout', ['_secure' => true]);?> Cart Url <?php echo $block->getUrl('checkout/cart', ['_secure' => true]);?> If you want to call at block class try with Checkout link: $this->getUrl('checkout', ['_secure' => true]); and…
-
How to override a controller in Magento
How to override a controller in Magento In several time ,we need to override a controlller.How to override a controller in Magento. There are two process available: 1.Basic Old process. 2.Upgrade Process from Magento CE 1.5.0. First have describe second process. It available from Magento CE 1.5.0.Where, i have Overriding controllers magento core controller .I have using before tag for use to override controller of a module- Here ,step to override a controllers: a)First check which module ,i want to override. Ex1: Suppose have override magento Magento Core Module Mage_Contacts and want override IndexController.php Write below code <frontend> <routers> <contacts> <args> <modules> <customcontacts before="Mage_Contacts">Amit_Customcontacts</customcontacts> </modules> </args> </contacts> </routers> </frontend>…
-
Programmatically create Shipment of a new order in magento
Programmatically create Shipment of a new order in magento Programmatically create Shipment of a new order in magento For some time need to create Shipment of an order.I have write code for how to create Shipment of an order pragmatically here First of all load an order by order id, Check all item of an order are already creating Shipment. if ,invoice is not created then create Shipment of all items Step1 ::load order by order id $order=Mage::getModel(‘sales/order’)->load($orderId); Or $order = Mage::getModel(‘sales/order’)->loadByIncrementId($orderIncrementId); Step2: check a item is available for shipment and set quantity for shipment $qty=array(); $Itemqty = $eachOrderItem->getQtyOrdered() – $eachOrderItem->getQtyShipped() – $eachOrderItem->getQtyRefunded() – $eachOrderItem->getQtyCanceled(); $qty[$eachOrderItem->getId()]=$Itemqty; Step3:create a shipment and…
-
Magento Security
Magento Security
-
Magento 2 Blogs
Magento 2 latest Blogs