How to set page title in Magento 2?

In Magento 2, We can set page titles using Controller as well as Using XML.

I have given examples for setting page titles using Controller and XML Way.

Using Controller,

public function execute() {
    $title = __('Page Title Name');
    $this->_view->getPage()->getConfig()->getTitle()->prepend($title);
}

Using Controller, You can set the title by just calling line  $this->_view->getPage()->getConfig()->getTitle()->prepend(‘title name’)

Using XML,

<head>
    <title>title name of page</title>
</head>

Using XML you can set your page title by <title> tag in <head> section.

Magento 2 display out of stock products at the end of the list page.

You can display out of stock product at end of catalog page in Magento 2 using just simple way. All the Out of stock product will be displayed at end of listing page.

You need to create module for display out of stock product at end of the page.

Create registration.php and module.xml file for creating a module. I hope you have created both file for define module,

For Collection of product generate from Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection file. We need to create a plugin for load() function. we need to set our custom condition for out of stock product to beforeLoad() function.

Create a di.xml file,

Path, app/code/Rbj/OutOfStock/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!--  out of stock product at end of list -->
    <type name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection">
        <plugin name="Rbj_OutOfStock::OutofstockEnd" type="Rbj\OutOfStock\Plugin\Product\ProductList\Toolbar"/>
    </type>
</config>

Need to override Stock.php file from Magento\CatalogInventory\Helper\Stock class.

Create Toolbar.php file, File Path, app/code/Rbj/OutOfStock/Plugin/Product/ProductList/Toolbar.php

<?php
/**
 * @author Rakesh Jesadiya
 * @package Rbj_OutOfStock
 */

namespace Rbj\OutOfStock\Plugin\Product\ProductList;

class Toolbar
{
    /**
     * @param \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $subject
     * @param bool $printQuery
     * @param bool $logQuery
     * @return array
     */
    public function beforeLoad(\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $subject, $printQuery = false, $logQuery = false)
    {
        $orderBy = $subject->getSelect()->getPart(\Zend_Db_Select::ORDER);
        $outOfStockOrderBy = array('is_salable DESC');
        /* reset default product collection filter */
        $subject->getSelect()->reset(\Zend_Db_Select::ORDER);
        $subject->getSelect()->order($outOfStockOrderBy);

        return [$printQuery, $logQuery];
    }
}

Clear Cache and Check in front. All the Out of stock product will display at end of listing page.

How to update order status using Rest API Magento 2?

We can update Order status using REST api in Magento 2 by just simple payload. For Create Order, Create order using rest api in Magento 2
We required the order_id, order status, and order_incrementid for update order status.
Request:{YOUR_URL}/rest/V1/orders

Type: POST

Body:

POST
{
  "entity":{
    "entity_id":10,
    "status":"processing",
    "increment_id":"000000010"
  }
}

Response:

{
    "base_grand_total": null,
    "base_total_due": 0,
    "billing_address_id": 204,
    "created_at": "2018-09-16 18:12:42",
    "customer_email": null,
    "entity_id": 10,
    "grand_total": null,
    "increment_id": "000000010",
    "protect_code": "352f3f47cd42aa50f0e7e328ffd53040",
    "status": "processing",
    "total_due": 0,
    "updated_at": "2018-09-16 18:44:57",
    "items": [
        {
            "amount_refunded": 0,
            "base_amount_refunded": 0,
            "base_cost": 0,
            "base_discount_amount": 4.5,
            "base_discount_invoiced": 0,
            "base_original_price": 45,
            "base_price": 45,
            "base_price_incl_tax": 45,
            "base_row_invoiced": 0,
            "base_row_total": 45,
            "base_tax_amount": 0,
            "base_tax_invoiced": 0,
            "created_at": "2018-09-16 18:12:42",
            "discount_amount": 4.5,
            "discount_invoiced": 0,
            "discount_percent": 10,
            "free_shipping": 0,
            "is_virtual": 0,
            "item_id": 124,
            "name": "Push It Messenger Bag",
            "no_discount": 0,
            "order_id": 103,
            "original_price": 45,
            "price": 45,
            "price_incl_tax": 45,
            "product_id": 14,
            "product_type": "simple",
            "qty_backordered": 0,
            "qty_canceled": 0,
            "qty_invoiced": 0,
            "qty_ordered": 1,
            "qty_refunded": 0,
            "qty_returned": 0,
            "qty_shipped": 0,
            "row_invoiced": 0,
            "row_total": 45,
            "row_total_incl_tax": 45,
            "row_weight": 0,
            "sku": "24-WB04",
            "store_id": 1,
            "tax_amount": 0,
            "tax_invoiced": 0,
            "tax_percent": 0,
            "updated_at": "2018-09-16 18:12:42",
            "weight": 0
        }
    ],
    "billing_address": {
        "address_type": "billing",
        "city": "Ahmedabad",
        "company": "Rbj",
        "country_id": "US",
        "email": "rakesh@rakeshjesadiya.com",
        "entity_id": 204,
        "firstname": "rakesh",
        "lastname": "jesadiya",
        "parent_id": 103,
        "postcode": "30332",
        "region": "Georgia",
        "region_code": "GA",
        "region_id": 19,
        "street": [
            "Street 1",
            "Street 2"
        ],
        "telephone": "123456"
    },
    "payment": {
        "account_status": null,
        "additional_information": [
            ""
        ],
        "cc_last4": null,
        "entity_id": 103,
        "method": "cashondelivery",
        "parent_id": 103
    },
    "status_histories": []
}