• Magento 2

    Magento2 add a cms page link to menu

    Magento2 add a cms page link to menu . Magento2 add a cms page link to menu or add a link to the menu, Magento2 add a cms page link to the menu. Most of the times, need to add cms page links or static link to the menu.T So, today I am writing this blog for add a cms page link to the menu at magento2.In this case, i am using Magento plugins and use before method. We have used class Magento\Theme\Block\Html\Topmenu  as the menu is rendered from this class and use before plugin. and use before plugin on _getHtml() First, create a module. Second: create di.xml where we will define the…

  • Magento 2

    Magento 2 import email address to Newsletter from csv

    Magento 2 import email address to Newsletter from csv. I have a requirement to import email is from CSV and import the email ids to Newsletter Subscriber list from csv. Write a PHP script which will import Newsletter subscriber from CSV. In this script, first i have read the email ids  from Csv , Then  first  check an email is exits  as customer Using Magento\Customer\Api\AccountManagementInterface ‘s   function isEmailAvailable($emailId,$websiteId) and depends  on customer types Guest ( mean guest Not register) and register, i have added  the email  to  subscriber list. For add an email to the subscriber list, we need to call factory class Magento\Newsletter\Model\SubscriberFactory  and need to Customer.Guest customer  use $_subscriberFactory->create()->subscribe($Email);   and register customer ,use…

  • Magento 2

    Magento2 How to disabled free shipping method at frontend

    Magento2 How to disabled free shipping method at frontend. In this article, I am going to show Magento2 How to disabled free shipping method at frontend. At magento2, it difficult to disable a shipping method at frontend and Enable at admin area. At first, I target to override  Free shipping method class  Magento\OfflineShipping\Model\Carrier\Freeshipping ‘s method  collectRates() using Plugin around method [crayon-5bc5b24041863595694735/]   And defined under  di.xml  at app/code/Devamitbera/CoreRewrite/etc/  and try disable by using Area code [crayon-5bc5b24041869527848782/]   But this is not working at Magento checkout page. I was going strange as the condition as was not working as excepted. Then, I was started to debug and find that issue is this Magento area.At Checkout page, Magento is…

  • magento2 base url
    Magento 2

    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. [crayon-5bc5b24041dc9452014966/] at Model, Resource model, Block, Helper classes for getting base url using below code: [crayon-5bc5b24041dcf380925468/] But this…

  • Magento 2

    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. [crayon-5bc5b24042012122058781/]   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.

  • Magento 2

    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…

  • Magento 2

    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 [crayon-5bc5b240429cb572102703/] 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. [crayon-5bc5b240429d1397222442/] Where $storeManager is the instance of Magento\Store\Model\StoreManagerInterface. If you want to get Base Url without Index.php then click here. For Getting Media Url Use Below code: [crayon-5bc5b240429d3444380219/] Get Static content Url [crayon-5bc5b240429d5370398171/] But I…

  • Magento2 get cart and checkout link in block or phtml
    Magento 2

    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 [crayon-5bc5b2404306c873614677/] Cart Url [crayon-5bc5b24043074884426398/]   If you want to call at block class try with Checkout link: [crayon-5bc5b24043077107263071/]   and Cart link: [crayon-5bc5b2404307a360239735/] I hope this will help lots. More Import Blogs: Magento2…

  • Magento

    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 [crayon-5bc5b240437c4654067587/] Here <contacts> is frontend routers for Mage_Contacts, and In <customcontacts before=”Mage_Contacts”>Amit_Customcontacts</customcontacts>…

  • Magento

    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…