Vue.js Redirect to Another Page


Vue.js Redirect to Another Page– In Vue.js vue-router is used to manage the routing. We can use router.go() to redirect to specified page alternatively we can use native window.location. Here in this article we are going to explain how you can redirect to another page in Vue.js.


Vue.js Redirect to Another Page Example

You can manage redirection in Vue.js simply as below-

Navigate to Route

If you want to navigate to particular route you can use vue-router.

Vue.js Redirect to Another Page Example:

router.go(yourPath);
// Where yourPath is route to navigate.
//in vue.js 2 use the below - 
router.push({ name: })

Redirect To Another Page

Alternatively you can use javascript native redirection.

Redirect To Another Page Vue.Js Example:

window.location = 'www.abc.com/mypage';

Magento 2 get Invoice from Order


Magento 2 get Invoice from Order– We can get invoice collection from order. Here in this tutorial, we are going to load order using order id then we will get invoice collection using order id.


Magento 2 get Invoice from Order Id | Invoice Collection Example

You can get Invoice Collection from order simply below-

Magento 2 get Invoice from Order Example:

$orderId = 9999;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')                           ->load($orderId);
$invoiceCollection = $order->getInvoiceCollection();
foreach($invoiceCollection as $invoice){
 $invoiceIncrementID = $invoice->getIncrementId();// invoice increment id
 // same way get other details of invoice
}

Magento 2 Create Customer Programmatically


Magento 2 Create Customer Programmatically Sometimes we need custom code to create customer such as creating custom regirstration page or creating some custom customer import functionality. Here in this article, we are going to explain how you can create customer using custom program.


Magento 2 Create Customer Programmatically Example

Magento 2 Create Customer Programmatically

You can create customer in Magento2 using custom code simply as below-

Magento 2 Create Customer Programmatically Example:

storeManager     = $storeManager;
        $this->customerFactory  = $customerFactory;

        parent::__construct($context);
    }

    public function execute()
    {
        // Get Current Website ID
        $websiteId  = $this->storeManager->getWebsite()->getWebsiteId();
        $customer   = $this->customerFactory->create();
        $customer->setWebsiteId($websiteId);
        $customer->setEmail("john@example.com"); 
        $customer->setFirstname("John");
        $customer->setLastname("Dee");
        $customer->setPassword("123XYZ");
        $customer->save();
        $customer->sendNewAccountEmail();
    }
}
?>

So you can create customer in Magento2 programmatically.

Magento 2 Redirect From Observer


Magento 2 Redirect From Observer We can use setRedirect($redirectUrl)->sendResponse(); to redirect to specified page from observer. Here in this article we are going to explain this with simple example.


Magento 2 Redirect From Observer Example

You can redirect from observer simply as below-

Observer-

Here is a simple observer which redirects to specified url in Magento2.

Magento 2 Redirect From Observer Example:

_responseFactory = $responseFactory;
        $this->_url = $url;
    }
    public function execute(Observer $observer) {
             $event = $observer->getEvent();
             $customUrl = 'customer/login';// your custom url
            $this->_responseFactory->create()->setRedirect($customUrl)->sendResponse();
             exit();
    }
}
?>

Magento 2 redirect Customer to Custom Page After Login


Magento 2 redirect Customer to Custom Page After Login– Sometimes we need to redirect customer to some specific page after login. It can be done in many ways like extending the core login functionality, using observers or using a plugin. Here in this article we are going to explain how you can implement this functionality.


Magento 2 redirect Customer to Custom Page After Login Plugin Example

The best way to implement this functionality is plugin Let us see how to do this using plugin.

Step 1 : Create di.xml

First create di.xml located at the below path-

/Vendor/Module/etc/frontend/di.xml

Magento 2 redirect Customer to Custom Page After Login Example:



  
    
  


Step 2 : Create Plugin

Now create plugin which will handle the redirect action.

/Vendor/Module/Plugin/LoginPostPlugin.php

Magento 2 redirect Customer to Custom Page After Login Example:

setPath($redirectPath);
        return $result;
    }

}

So you can do anything whatever you want after login action.

JavaScript Redirect to a page after few seconds on Button Click


JavaScript Redirect to a page after few seconds on Button Click We can use pure JavaScript function window.location and setTimeoout to redirect to particular page. Let us understand how we can redirect after 1 minutes on button click.


JavaScript Redirect to a page after few seconds on Button Click Example

Here is simple example to redirect after submit button to the specified page-

JavaScript Redirect to a page after few seconds on Button Click Example:









Try it »

Bootstrap Remove Modal Background


Bootstrap Remove Modal Background Overlay– Sometimes we need to hide bootatrap popup modal overlay background, it can be done in two ways Using – 1. Modal Option, 2. JavaScript/jQuery. Here in this tutorial we are going to cover the both methods with example & online demo.


Bootstrap Remove Modal Background Overlay | Hide Backdrop Example

You can hide bootstrap popup modal in following ways-

  • 1. Using Modal Option
  • 2. Using JavaScript

Using Modal Option

You can hide modal background color using modal option data-backdrop=”false” as below

| Example:



Try it »

If you run the above example it will produce output something like this-

Bootstrap Remove Modal Background

Using Modal JavaScript

Sometimes we use javascript to show the modal so we can also remove backdrop using jQuery simply as below-

| Example:



Try it »

Magento 2 get Payment Method from Quote


Magento 2 get Payment Method from Quote– We can get current Payment method that user selected on frontend from quote session. Let us understand how to get current payment method applied on cart in Magento2.


Magento 2 get Payment Method from Quote Session Example

You can get current payment method selected from quote using object manager simply as below-

Get Payment Method in Magento2 Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

$quote = $cart->getQuote();
$paymentMethod = $quote->getPayment()->getMethod();

The above example will give you Payment Method that user selected during checkout on frontend.

Magento 2 get shipping method from quote


We can get current shipping method selected from quote session in Magento2. We can use object manager or dependency injection to get access the current quote object from session. Let us understand how to get current shipping method applied on cart in Magento2.


Magento 2 get shipping method from quote Example

You can get shipping method from quote using object manager simply as below-

Get Shipping Method in Magento2 Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

$quote = $cart->getQuote();
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();

First get the object manager instance, then load magento checout model cart object to access the quote object. Now using the Quote object you can get the current shipping method from shipping Address object. On the same way you can get other shipping details.

The above example will give you shipping method that user selected during checkout.