How to apply SortOrder on Search Criteria Repositories Magento 2?

Magento apply sort order for the search criteria interface repository by using Magento\Framework\Api\SortOrderBuilder Class.

You can do sorting by ASC or DESC order by any field type for a given search criteria repository.

$sortOrder = $this->sortOrderBuilder
            ->setField('created_at')  //FIELD_NAME
            ->setDirection(SortOrder::SORT_DESC) // SORT_TYPE
            ->create();

You can check the given code snippet to fetch orders by created date with the search criteria builder order repository. Continue reading “How to apply SortOrder on Search Criteria Repositories Magento 2?”

How to generate auto invoice by payment_action for custom payment methods in magento 2?

You can Generate an auto invoice after the order is placed successfully in Magento with the simple configuration.

You can use <payment_action> configuration in the config.xml file to set auto invoice for your custom payment method.

You can check programmatically Convert Order to Invoice Programmatically in Magento 2.

Using payment_action, You don’t need to generate manual action to create an invoice for the order.

You have to just create a config.xml file under your module etc directory. Continue reading “How to generate auto invoice by payment_action for custom payment methods in magento 2?”

How to display newest to oldest customer orders in Graphql response Magento 2?

While you working with the Magento Customer Order GraphQl, You will fetch the order by GraphQl query customerOrders.

type Query {
    customerOrders: CustomerOrders @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Orders")
}

By Default, The Result of the customer orders will be displayed from the Older order to the newest order. Continue reading “How to display newest to oldest customer orders in Graphql response Magento 2?”