Posts

Showing posts from June, 2019

Magento 2 How to Identify Payment method is offline or online after place order

Offline Payment methods are Cash on delivery, Check/Money order, Bank transfer. Online Payment methods are Amazon,Braintree,Paypal, Authorize.net and many more online payments available. You can check payment method is offline or online using programmatically by $order->getPayment()->getMethodInstance()->isOffline() result will offline payment method with 0 or 1. please check with below code for Observer. event name is sales_order_place_after public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getOrder(); $isOffline = $order->getPayment()->getMethodInstance()->isOffline(); if ($isOffline) { echo __('offline'); } else { echo __('online'); } }

How to delete cookies in Magento 2?

In magento you can delete cookies via Magento\Framework\Stdlib\CookieManagerInterface interface class. You can delete cookie using cookiesdelete() function from CookieManagerInterface Interface. If you have set the cookie using cookie’s $metadata property, You need to inject Magento\Framework\Stdlib\Cookie\CookieMetadataFactory factory in your class to delete the cookie. <?php namespace Itsmage\DeleteCookie\Model; class Cookie { /** * @var \Magento\Framework\Stdlib\CookieManagerInterface CookieManagerInterface */ private $cookieManager; /** * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory CookieMetadataFactory */ private $cookieMetadataFactory; public function __construct( \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory ) { $this->cookieManager = $cookieManager; $this->cookieMetadataFa

Magento 2 Events Observer lists

Check with below lists of all the events dispatched that you can observe in your Magento2 web store. Magento 2 Events Observer lists: 'adminhtml_cache_flush_all' 'adminhtml_cache_flush_system' 'backend_auth_user_login_success', ['user' => $this->getCredentialStorage()] 'backend_auth_user_login_failed', ['user_name' => $username, 'exception' => $e] 'backend_auth_user_login_failed', ['user_name' => $username, 'exception' => $e] 'adminhtml_store_edit_form_prepare_form', ['block' => $this] 'adminhtml_block_html_before', ['block' => $this] 'backend_block_widget_grid_prepare_grid_before', ['grid' => $this, 'collection' => $this->getCollection()] 'theme_save_after' 'store_group_save', ['group' => $groupModel] 'store_delete', ['store' => $model] 'adminhtml_cache_flush_syst

Redirect request with POST data using .htaccess

RewriteEngine on RewriteCond %{SERVER_PORT} !443 RewriteCond %{REQUEST_URI} string_to_match_in_url RewriteCond %{REQUEST_METHOD} POST RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=307] The first RewriteCond checks if the request is NOT coming as HTTPS, otherwise it will go in endless loop. If yes, the second RewriteCond checks if the URL contains a string we are looking for. Then if that URL is being submitted as POST method. If everything matches, then we redirect the request using HTTPS secure protocol retaining the POST method and the associated data.