We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    How to Create Custom Admin Menu in Magento 2?

    In this guide, we are going to show you how to create a custom admin menu in Magento 2.

    The first step is to create a module.

    Let’s give the module a name. Call it: Magemonkey_Newadminmenu

    Then, create registration.php file

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Magemonkey_Newadminmenu',
        __DIR__
    );

    create module.xml file in etc/

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
                <module name="Magemonkey_Newadminmenu" setup_version="1.0.0"></module>
    </config>

    create menu.xml file in etc/adminhtml/

    <?xml version="1.0"?>
    
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    
        <menu>
            <add id="Magemonkey_Newadminmenu::first_menu"
                 title="My Main Menu"
                 module="Magemonkey_Newadminmenu"
                 sortOrder="20"
                 resource="Magento_Backend::content" />
    
            <add id="Magemonkey_Newadminmenu::second_menu"
                 title="My Sub Menu"
                 module="Magemonkey_Newadminmenu"
                 sortOrder="1"
                 action="newadminmenu/index/index"
                 parent="Magemonkey_Newadminmenu::first_menu"
                 resource="Magento_Backend::content" />
    
        </menu>
    </config>

    Know the description for element variables in code:

    id: The unique identifier for the custom admin menu
    title: The title will be shown as a menu name
    Module: Magemonkey_Newadminmenu (name of the current module)
    sortOrder: Set custom admin menu order
    resource: The rule for admin users can access the custom admin menu
    Action: Link for admin controller URL
    parent: Name of the parent menu which custom menu depends on sub menu

    After running this command for install that module

    php bin/magento setup:upgrade
    php bin/magento cache:clean

    Now It will be shown in admin menu as seen in the below image.

     

    How to Show Catalog Product List widget’s product in given order?

    If you want to show product listing in a given order by its category in the Catalog Product List Widget? Then follow the below steps.

    Step 1: Create a file like ProductOrder/CatalogProList/etc/frontend/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">
        <type name="MagentoCatalogWidgetBlockProductProductsList">
            <plugin name="custom_widgets_product_list" type="ProductOrderCatalogProListPluginBlockProductProductsOrderList"/>
        </type>
    </config>

    Step 2: Create another file like ProductOrder/CatalogProList/Plugin/Block/Product/ProductsOrderList.php

    <?php    
    	namespace ProductOrderCatalogProListPluginBlockProduct;
    
    	use MagentoCatalogModelResourceModelProductCollection;
    	use MagentoCatalogWidgetBlockProductProductsList;
    
    	/**
    	 * Class ProductsOrderList
    	 */
    	class ProductsOrderList
    	{
    
    	    /**
    	     * @param ProductsList $subject
    	     * @param Collection $result
    	     * @return Collection
    	     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
    	     */
    	    public function afterCreateCollection(ProductsList $subject, Collection $result)
    	    {
    	        $result->getSelect()->order('cat_index_position asc');
    
    	        return $result;
    	    }
    	}

    That’s it…

    Now, you can check your widget’s products. It will be displayed as per the given order.

    Magento 2 add custom menu after all top menu in navigation

    We have two choices for achieving this functionality.

    One option is to directly add in topmenu.phtml by overriding a file in your theme. There are chances that it won’t work if you have a third party mega menu extension.

    Another way is by using the plugin, Here we are going to talk about the same.

    We can achieve our requirement by executing two steps:

    First, you need to create di.xml in your custom module.

    [Vendor Name]/[Module Name]/etc/di.xml
    <!-- Add custom menu in navigation -->
    <type name="MagentoThemeBlockHtmlTopmenu">
        <plugin name="add_registry_inmenu" type="[Vendor Name][Module Name]PluginCustommenu" sortOrder="10" disabled="false"/>
    </type>
    

    Now you have to create a plugin file in your custom module

    [Vendor Name]/[Module Name]/Plugin/Custommenu.php
    <?php
    
    namespace [Vendor Name][Module Name]Plugin;
    
    class Custommenu
    {
        public function afterGetHtml(MagentoThemeBlockHtmlTopmenu $menu, $html)
        {
            $giftTopUrl = $menu->getUrl('giftr/search/result'); /* Here is the menu link which are redirect after click */
            $baseUrl = $menu->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
            if (strpos($baseUrl,'giftr/search/result') !== false) {
                $html .= "<li class="level0 nav-5 active level-top parent ui-menu-item">";
            } else {
                $html .= "<li class="level0 nav-4 level-top parent ui-menu-item">";
            }
            $html .= "<a href="" . $giftTopUrl . "" class="level-top ui-corner-all"><span>" . __("Gift Registry") . "</span></a>";
            $html .= "</li>";
            return $html;
        }
    }

    After executing both steps, run below command:

    php bin/magento cache:flush

    Now you can check your navigation menu. Your custom menu is added after all top menus.

    How to download pdf file magento2?

    Magento2 has a built-in script for any kind of file download, we can use the below code for file downloads:

    <?php
    /**
     * Magemonkeys.
     *
     * @category  Magemonkeys
     *
     * @author    Magemonkeys
     * @copyright Copyright (c) 2020 Magemonkeys (https://magemonkeys.com/)
     */
    
    namespace MagemonkeysDownloadControllerDownload;
    
    use MagentoFrameworkAppActionContext;
    
    /**
     * file download controller.
     */
    class Index extends MagentoFrameworkAppActionAction
    {
        /**
         * @var MagentoFrameworkAppResponseHttpFileFactory
         */
        protected $_downloader;
    
        /**
         * @var MagentoFrameworkFilesystemDirectoryList
         */
        protected $directory;
    
        /**
         * @param Context     $context
         * @param PageFactory $resultPageFactory
         */
        public function __construct(
            Context $context,
            MagentoFrameworkAppResponseHttpFileFactory $fileFactory,
            MagentoFrameworkFilesystemDirectoryList $directory
        ) {
            $this->_downloader =  $fileFactory;
            $this->directory = $directory;
            parent::__construct($context);
        }
    
        public function execute()
        {
            $fileName = $this->getRequest()->getParam('fileName');
            $file = $this->directory->getPath("media")."/FilePath/".$fileName;
            // do your validations
    
            /**
             * do file download
             */
            return $this->_downloader->create(
                $fileName,
                @file_get_contents($file)
            );
        }
    }

     

    Make clickable Value of Grid (UI Column)

    If you want to set clickable value in the Magento 2 Grid then please follow the below steps. I have made this type of functionality for my custom module.

    Step 1: Please add this code to your UI Listing XML. We have added bodyTmpl to make value clickable in the UI column.

    <column name="holiday_id" class="MagemonkeysHolidaylistingUiComponentListingColumnHolidayId">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">ID #</item>
                <item name="sortOrder" xsi:type="number">10</item>
                <item name="filter" xsi:type="string">text</item>
                <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
            </item>
        </argument>
    </column>

    Step 2: We have to paste the below code for Class which is defined in the <column> tag.
    Path : appcodeMagemonkeysHolidaylistingUiComponentListingColumnHolidayId.php

    <?php
    
    namespace MagemonkeysHolidaylistingUiComponentListingColumn;
    
    use MagentoFrameworkUrlInterface;
    use MagentoUiComponentListingColumnsColumn;
    use MagentoFrameworkViewElementUiComponentFactory;
    use MagentoFrameworkViewElementUiComponentContextInterface;
    
    
    class HolidayId extends Column
    {
        private $urlBuilder;
    
        public function __construct(
            ContextInterface $context,
            UiComponentFactory $uiComponentFactory,
            UrlInterface $urlBuilder,
            array $components = [],
            array $data = []
        ) {
            $this->urlBuilder = $urlBuilder;
            parent::__construct($context, $uiComponentFactory, $components, $data);
        }
    
        public function prepareDataSource(array $dataSource)
        {
            if (isset($dataSource['data']['items'])) {
                foreach ($dataSource['data']['items'] as & $item) {
                    if (isset($item['holiday_id'])) {
                        $url = $this->urlBuilder->getUrl('holiday/view', ['holiday_id' => $item['holiday_id']]);
                		$link = '<a href="' . $url . '"">' . $item['holiday_id'] . '</a>';
                        $item['holiday_id'] = $link;
                    }
                }
            }
            return $dataSource;
        }
    }

    Now you can see the Id column values are clickable.

    Get category data by using category id in Magento 2

    Create the block file in your module.

    <?php
    namespace MagemonkeyCategoryBlock;
     
    class Category extends MagentoFrameworkViewElementTemplate
    {
        public function __construct(
            MagentoFrameworkViewElementTemplateContext $context,
            MagentoCatalogApiCategoryRepositoryInterface $categoryRepository,
            array $data = []
        ) {
            $this->categoryRepository = $categoryRepository;
            parent::__construct($context, $data);
        }
     
        /* $categoryId as category id */
        public function getCategoryById($categoryId){
            try {
                return $category = $this->categoryRepository->get($categoryId);
            } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
                return ['response' => 'Category Not Found'];
            }
        }
    }
    ?>

    Put this code in your template file and pass the category id in getCategoryById function.

    <?php  
    $categoryId = 10; // category id
    $getCategory = $block->getCategoryById($categoryId);
    echo $getCategory->getName();echo "<br>";
    echo $getCategory->getUrlKey();echo "<br>";
    echo $getCategory->getIsActive();echo "<br>";
    echo "<pre>";print_r($getCategory->getData()); ?>

     

    How to get request post params from rest webapi in Magento 2?

    While you’re working with the REST API in Magento you can retrieve the Rest Webapi Request Parameters.

    Magento has its own OOTB Webapi module that is dealing with Rest API functionality.

    Required Class, MagentoFrameworkWebapiRestRequest

    <?php
    namespace MagemonkeysRestParamsModel;
    
    use MagentoFrameworkWebapiRestRequest;
    
    class GetRestParam
    {
        /**
         * @var Request
         */
        protected $request;
    
        public function __construct(
            Request $request
        ) {
            $this->request = $request;
        }
    
        public function getParamValue()
        {
            $filter = $this->request->getParam('paramerer_name');
        }
    }

    In the above example, ‘paramerer_name’ is your actual parameter name to retrieve the value from the request.

    If you want to get all the parameters for the Rest API,
    $this->request->getParams();  print the all list of key & value for the request parameter.

    Add credit card form in checkout page in Magento 2

    Before following the below steps you need to create the custom payment method module.

    Step 1) Create a template file – Magemonkey/Chargeanywhere/view/frontend/web/template/payment/chargeanywhere.html

    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
        <div class="payment-method-title field choice">
            <input type="radio"
                   name="payment[method]"
                   class="radio"
                   data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
            <label data-bind="attr: {'for': getCode()}" class="label"><span data-bind="text: getTitle()"></span></label>
        </div>
        <div class="payment-method-content">
            <!-- ko foreach: getRegion('messages') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
            <div class="payment-method-billing-address">
                <!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
                <!-- ko template: getTemplate() --><!-- /ko -->
                <!--/ko-->
            </div>
            <form class="form" data-bind="attr: {'id': getCode() + '-form'}">
                 <!-- ko template: 'Magento_Payment/payment/cc-form' --><!-- /ko -->         
                 
    
            </form>
            <div class="checkout-agreements-block">
                <!-- ko foreach: $parent.getRegion('before-place-order') -->
                    <!-- ko template: getTemplate() --><!-- /ko -->
                <!--/ko-->
            </div>
            <div class="actions-toolbar">
                <div class="primary">
                    <button class="action primary checkout"
                            type="submit"
                            data-bind="
                            click: placeOrder,
                            attr: {title: $t('Place Order')},
                            css: {disabled: !isPlaceOrderActionAllowed()},
                            enable: (getCode() == isChecked())
                            "
                            disabled>
                        <span data-bind="i18n: 'Place Order'"></span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    Step 2) Magemonkey/Chargeanywhere/view/frontend/web/js/view/payment/method-renderer/chargeanywhere-method.js

    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    /*browser:true*/
    /*global define*/
    define(
        [
            'jquery',
            'Magento_Payment/js/view/payment/cc-form'
        ],
        function (
            $,
            Component
            )  {
            'use strict';
    
            return Component.extend({
                defaults: {
                    template: 'Magemonkey_Chargeanywhere/payment/chargeanywhere'
                },
                context: function() {
                    return this;
                },
    
                getCode: function() {
                    return 'chargeanywhere';
                },
    
                isActive: function() {
                    return true;
                }
    
               
            });
        }
    );
    

    Step 3) create the di.xml file Magemonkey/Chargeanywhere/etc/frontend/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">
    	<type name="MagentoPaymentModelCcGenericConfigProvider">
            <arguments>
                <argument name="methodCodes" xsi:type="array">
                    <item name="chargeanywhere" xsi:type="const">MagemonkeyChargeanywhereModelChargeanywhere::CODE</item>
                </argument>
            </arguments>
        </type>
    </config>

    Step 4) create the config provider file Magemonkey/Chargeanywhere/Model/Chargeanywhere.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModel;
    use MagentoFrameworkSimplexmlElement;
    use MagentoSalesModelOrderPaymentTransaction;
    
    
    /**
     * Pay In Store payment method model
     */
    class Chargeanywhere extends MagentoPaymentModelMethodCc
    {
        const CODE = 'chargeanywhere';
        /**
         * Payment code
         *
         * @var string
         */
        protected $_code = self::CODE;
    
        /**
         * Availability option
         *
         * @var bool
         */
        // protected $_isOffline = true;
    
        protected $_canAuthorize = true;
        protected $_canCapture = true;
    
        public function __construct(
            MagentoFrameworkModelContext $context,
            MagentoFrameworkRegistry $registry,
            MagentoFrameworkApiExtensionAttributesFactory $extensionFactory,
            MagentoFrameworkApiAttributeValueFactory $customAttributeFactory,
            MagentoPaymentHelperData $paymentData,
            MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
            MagentoPaymentModelMethodLogger $logger,
            MagentoFrameworkModuleModuleListInterface $moduleList,
            MagentoFrameworkStdlibDateTimeTimezoneInterface $localeDate,
            MagentoDirectoryModelCountryFactory $countryFactory,
            MagentoCheckoutModelCart $cart,
            MagentoQuoteModelQuoteFactory $quote,
            MagentoBackendModelSessionQuote $quoteSession,
            MagentoFrameworkAppResourceConnection $resource,
            MagentoFrameworkAppState $state,
            MagentoCustomerModelSession $customerSession,
            MagentoFrameworkSessionSessionManager $sessionManager,
            MagentoDirectoryModelRegion $regionList,
            MagentoFrameworkAppRequestHttp $request,
            MagentoSalesModelOrderPaymentTransactionBuilderInterface $transactionBuilder,
            MagemonkeyChargeanywhereHelperData $helperData,
            MagentoCheckoutModelSession $checkoutSession,
            array $data = array()
        ) {
            $this->quote = $quote;
            $this->_session = $quoteSession;
            $this->_appState = $state;
            $this->_customerSession = $customerSession;
            $this->_regionList = $regionList;
            $this->request = $request;
            $this->_sessionId = $sessionManager->getSessionId();
            $this->_sessionManager = $sessionManager;
            $this->transactionBuilder = $transactionBuilder;
            $this->helper = $helperData;
            $this->_checkoutSession = $checkoutSession;
            parent::__construct(
                $context,
                $registry,
                $extensionFactory,
                $customAttributeFactory,
                $paymentData,
                $scopeConfig,
                $logger,
                $moduleList,
                $localeDate,
                null,
                null,
                $data
                
            );
            
            $this->cart = $cart;
            $this->_countryFactory = $countryFactory;
            $this->_scopeConfig = $scopeConfig;
        }
    
        /**
         * Validate payment method information object
         *
         * @return $this
         * @throws MagentoFrameworkExceptionLocalizedException
         * @SuppressWarnings(PHPMD.CyclomaticComplexity)
         * @SuppressWarnings(PHPMD.NPathComplexity)
         */
        public function validate() {
             parent::validate();
            return true;
        }
        public function authorize(MagentoPaymentModelInfoInterface $payment, $amount) {
            $chargedata = $this->_checkoutSession->getChargeData();
            $payment->setTransactionId($chargedata['ReferenceNumber']);
            $payment->setParentTransactionId($chargedata['ReferenceNumber']);
            $payment->setIsTransactionClosed(0);
            return $this;
        }
        public function capture(MagentoPaymentModelInfoInterface $payment, $amount)
        {   $chargedata = $this->_checkoutSession->getChargeData();
            $payment->setLastTransId($chargedata['ReferenceNumber']);
            $payment->setTransactionId($chargedata['ReferenceNumber']);
            return $this;
        }
    
        public function getConfigPaymentAction()
        {
           return $this->getConfigData('payment_action');
        }   
    }

     

    Step 5) override checkout index file Magemonkey/Chargeanywhere/view/frontend/layout/checkout_index_index.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
        <body>
            <referenceBlock name="checkout.root">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="checkout" xsi:type="array">
                                <item name="children" xsi:type="array">
                                    <item name="steps" xsi:type="array">
                                        <item name="children" xsi:type="array">
                                            <item name="billing-step" xsi:type="array">
                                                <item name="children" xsi:type="array">
                                                    <item name="payment" xsi:type="array">
                                                        <item name="children" xsi:type="array">
                                                            <item name="renders" xsi:type="array">
                                                                <item name="children" xsi:type="array">
                                                                <!-- merge payment method renders here -->
                                                                    <item name="chargeanywhere-chargeanywhere" xsi:type="array">
                                                                        <item name="component" xsi:type="string">Magemonkey_Chargeanywhere/js/view/payment/chargeanywhere</item>
                                                                        <item name="methods" xsi:type="array">
                                                                      
    																		 <item name="chargeanywhere" xsi:type="array">
                                                                                <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                            </item>
                                                                        </item>
                                                                    </item>
                                                                <!-- item-renderer -->
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </referenceBlock>
        </body>
    </page>

    Step 6) Create system.xml file Magemonkey/Chargeanywhere/etc/adminhtml/system.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
        <system>
            <section id="payment">
                <group id="chargeanywhere" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Charge Anywhere</label>
                    <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Enabled</label>
                        <source_model>MagentoConfigModelConfigSourceYesno</source_model>
                    </field>
                    <field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Title</label>
                    </field>
                    <field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>New Order Status</label>
                        <source_model>MagemonkeyChargeanywhereModelConfigSourceOrderStatusPendingpayment</source_model>
                    </field>
                    <field id="api_key" translate="label" type="obscure" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>API Secret Key</label>
                        <!-- <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model> -->
                        <comment>Test/Live Secret Key</comment>
                    </field>
                    <field id="marchant_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Marchant Id</label>
                    </field>
                    <field id="terminal_id" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Terminal Id</label>
                    </field>
                    <field id="mode_type" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Test/Live</label>
                        <source_model>MagemonkeyChargeanywhereModelSourceModetype</source_model>
                    </field>
                     <field id="payment_action" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Payment Action</label>
                        <source_model>MagemonkeyChargeanywhereModelConfigSourceOrderActionPaymentaction</source_model>
                    </field>
                    <field id="cctypes" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                        <label>Credit Card Types</label>
                        <source_model>MagentoPaymentModelSourceCctype</source_model>
                    </field>
                    <field id="instructions" translate="label" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Instructions</label>
                    </field>
                </group>
                <!-- payment-group -->
            </section>
        </system>
    </config>
    

     

    Step 7) Create config.xml file Magemonkey/Chargeanywhere/etc/config.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
        <default>
            <payment>
                <chargeanywhere>
                    <active>1</active>
                    <title>Chargeanywhere</title>
                    <order_status>pending_payment</order_status>
                    <instructions>Instruction.</instructions>
                    <payment_action>authorize</payment_action>
                    <model>MagemonkeyChargeanywhereModelChargeanywhere</model>
                    <group>offline</group>
                </chargeanywhere>
                <!-- payment-config -->
            </payment>
        </default>
    </config>
    

     

    Step 8) Create payment action file Magemonkey/Chargeanywhere/Model/Config/Source/Order/Action/Paymentaction.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModelConfigSourceOrderAction;
    /**
     * Order Status source model
     */
    class Paymentaction  
    {
        /**
         * @var string[]
         */
        public function toOptionArray(){
            return [
                ['value' => 'authorize', 'label' => __('Authorize Only')],
                ['value' => 'authorize_capture', 'label' => __('Sale')],
            ];
        }
    }
    

    Step 9) Create order status file Magemonkey/Chargeanywhere/Model/Config/Source/Order/Status/Pendingpayment.php

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace MagemonkeyChargeanywhereModelConfigSourceOrderStatus;
    
    use MagentoSalesModelOrder;
    use MagentoSalesModelConfigSourceOrderStatus;
    
    /**
     * Order Status source model
     */
    class Pendingpayment extends Status
    {
        /**
         * @var string[]
         */
        protected $_stateStatuses = [Order::STATE_PENDING_PAYMENT];
    }
    

     

    Magento 2 add custom price in summary section on checkout page

    Step 1) Create di.xml

    <?xml version="1.0"?>
     <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    
    	<type name="MagentoCheckoutModelDefaultConfigProvider">
    	    <plugin name="AddAttPlug" type="[vendor][module]ModelPluginDefaultConfigProvider" />
    	</type>
    </config>

    Step 2) create plugin file DefaultConfigProvider.php

    class DefaultConfigProvider 
    {
    
      /**
        *@var checkoutSession
        */
        protected $checkoutSession;
    
        /**
        *Constructor
        * @param CheckoutSession $checkoutSession
        */
        public function __construct(CheckoutSession $checkoutSession)
        {
            $this->checkoutSession = $checkoutSession;
        }
        public function afterGetConfig(MagentoCheckoutModelDefaultConfigProvider $subject, $config)
        {
        	$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
            foreach ($config['quoteItemData'] as &$item) {
                $priceHelper = $objectManager->create('MagentoFrameworkPricingHelperData');
                $quoteItem = $this->checkoutSession->getQuote()->getItemById($item['item_id']);
                $price =  $quoteItem->getProduct()->getPrice();
                $formattedPrice = $priceHelper->currency($price, true, false);
                $item['originalprice'] = $formattedPrice;
            }
           return $config;
        }
    }

    Step 3) Override the /vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js to your module

    **
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    define([
        'uiComponent',
        'Magento_Checkout/js/model/quote'
    ], function (Component) {
        'use strict';
    
        return Component.extend({
            defaults: {
                template: 'Magento_Checkout/summary/item/details'
            },
    
            /**
             * @param {Object} quoteItem
             * @return {String}
             */
            getValue: function (quoteItem) {
                return quoteItem.name;
            },
            getItemBaseprice: function (quoteItem) {
                    return this.getPropertyDataFromItem(quoteItem, 'originalprice');
            },
            getPropertyDataFromItem: function (quoteItem, propertyName) {
                    var property,
                        itemDetails;
                    if (quoteItem.hasOwnProperty(propertyName)) {
                        property = quoteItem[propertyName];
                    }
                    var quoteItem = this.getItemFromQuote(quoteItem);
                    if (quoteItem.hasOwnProperty(propertyName)) {
                        property = quoteItem[propertyName];
                    }
                    if (property) {
                        this.storage().set('item_details' + quoteItem.item_id + propertyName, property);
                        return property;
                    }
                    itemDetails = this.storage().get('item_details' + quoteItem.item_id + propertyName);
                    return itemDetails ? itemDetails : false;
                },
                getItemFromQuote: function (item) {
                    var items = quote.getItems();
                    var quoteItems = items.filter(function (quoteItem) {
                        return quoteItem.item_id == item.item_id;
                    });
                    if (quoteItems.length == 0) {
                        return false;
                    }
                    return quoteItems[0];
                }
        });
    });
    

    Step 4) Override the vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html to your module add the below line.

    <span class="originalprice" data-bind="text: getItemBaseprice($parent)"></span>