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.

    Magento bundle product price shows different on list page and product page

    By default Magento bundle product display min price on the listing page and full price on the product page.

    Today I’m sharing you the list page to show the same price as the product page because it’s confusing for customers when they see the different prices.

    You have to override below file in your appropriate theme:

    app/design/frontend/base/default/template/bundle/catalog/product/price.phtml

    Then put below code after:

    $_priceModel  = $_product->getPriceModel(); [around line no. 45]
    $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($_product->getId());
    $collection = $product->getTypeInstance(true)
        ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
     $totalPriceArray = [];
     foreach ($collection as $item) {
        $price = $_product->getPriceModel()->getSelectionPreFinalPrice($_product, $item, $item->getQty());
        $priceTax    = $_taxHelper->getPrice($item, $price);
        $formated = $priceTax;
        $totalPriceArray[] = $formated; 
     }
    $finalPrice = array_sum($totalPriceArray);

    Now replace the current price variable to $finalPrice [like $_minimalPriceTax its depend on tax settings you have to find excet condition which is a call for your list page]

    For example, I am replacing below line:

    Old Line : <?php echo $_coreHelper->currency($_minimalPriceTax) ?>
    Replace Line: <?php echo $_coreHelper->currency($finalPrice) ?>

    Now reload your list page and see price should be the same as like product page.

    Magento 2 execute the command using script

    Create the command file and put the command script into that file on the Magento root directory. Then execute that script using browser Url.

    Upgrade command script

    <?php
    use MagentoFrameworkAppBootstrap;
     
    require __DIR__ . '/app/bootstrap.php';
     
    $params = $_SERVER;
     
    $bootstrap = Bootstrap::create(BP, $params);
     
    $obj = $bootstrap->getObjectManager();
     
    $state = $obj->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    $logger = $obj->get('PsrLogLoggerInterface');
    try{
    	$logger->info("upgrade start");
    	echo passthru('php -d memory_limit=1G bin/magento setup:upgrade');
    	$logger->info("upgrade finished");
    }
    catch(Exception $e){
    	$logger->info("upgrade not working");
    }
    ?>

    di.comple command script

    <?php
    use MagentoFrameworkAppBootstrap;
     
    require __DIR__ . '/app/bootstrap.php';
     
    $params = $_SERVER;
     
    $bootstrap = Bootstrap::create(BP, $params);
     
    $obj = $bootstrap->getObjectManager();
     
    $state = $obj->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    
    $logger = $obj->get('PsrLogLoggerInterface');
    
    try{
    	$logger->info("compile start");
    	echo passthru('php -d memory_limit=1G bin/magento setup:di:compile');
    	$logger->info("compile finished");
    }
    catch(Exception $e){
    	$logger->info("compile not working");
    }
    ?>

    Deploy command script

    <?php
    use MagentoFrameworkAppBootstrap;
     
    require __DIR__ . '/app/bootstrap.php';
     
    $params = $_SERVER;
     
    $bootstrap = Bootstrap::create(BP, $params);
     
    $obj = $bootstrap->getObjectManager();
     
    $state = $obj->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    
    $logger = $obj->get('PsrLogLoggerInterface');
    
    try{
    	$logger->info("compile start");
    	echo passthru('php -d memory_limit=1G bin/magento setup:static-content:deploy');
    	$logger->info("deploy finished");
    }
    catch(Exception $e){
    	$logger->info("deploy not working");
    }
    ?>

    Indexer command script

    <?php
    use MagentoFrameworkAppBootstrap;
     
    require __DIR__ . '/app/bootstrap.php';
     
    $params = $_SERVER;
     
    $bootstrap = Bootstrap::create(BP, $params);
     
    $obj = $bootstrap->getObjectManager();
     
    $state = $obj->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    
    $logger = $obj->get('PsrLogLoggerInterface');
    
    try{
    	$logger->info("indexing start");
    	echo passthru('php -d memory_limit=1G bin/magento indexer:reindex');
    	$logger->info("indexing finished");
    }
    catch(Exception $e){
    	$logger->info("indexing not working");
    }
    ?>

    Cache Flush command script

    <?php
    use MagentoFrameworkAppBootstrap;
     
    require __DIR__ . '/app/bootstrap.php';
     
    $params = $_SERVER;
     
    $bootstrap = Bootstrap::create(BP, $params);
     
    $obj = $bootstrap->getObjectManager();
     
    $state = $obj->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    
    $logger = $obj->get('PsrLogLoggerInterface');
    try{
    	$logger->info("cache start");
    	echo passthru('php -d memory_limit=1G bin/magento cache:flush');
    	$logger->info("cache finished");
    }
    catch(Exception $e){
    	$logger->info("cache not working");
    }
    ?>

     

    How to Move Billing Address Before the Payment Method in checkout Magento2?

    By Default, In Magento2  Billing address is displayed with the Payment method, and the second option to display billing address is on the Payment page.

    If you have a custom requirement like, Display the Billing address before all the payment methods you need to do customization for that.

    Create a di.xml file at the location,
    app/code/Magemonkeys/BillingAddressBeforePayment/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">
        <!-- Set Billing address above the payment method plugin -->
        <type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
            <plugin name="move_billing_address_above_payment_method"
                    type="MagemonkeysBillingAddressBeforePaymentPluginBlockCheckoutLayoutProcessor"/>
        </type>
    </config>

    Based on the XML file, Create a Plugin Class, app/code/Magemonkeys/BillingAddressBeforePayment/Plugin/Block/Checkout/LayoutProcessor.php

    <?php declare(strict_types=1);
    
    namespace MagemonkeysBillingAddressBeforePaymentPluginBlockCheckout;
    
    use MagentoCheckoutBlockCheckoutLayoutProcessor as CheckoutLayoutProcessor;
    
    /**
     * Move Billing address to top
     */
    class LayoutProcessor
    {
        /**
         * @param CheckoutLayoutProcessor $subject
         * @param array $jsLayout
         * @return array
         */
        public function afterProcess(
            CheckoutLayoutProcessor $subject,
            array $jsLayout
        ): array {
            $paymentLayout = $jsLayout['components']['checkout']['children']['steps']
            ['children']['billing-step']['children']['payment']['children'];
    
            if (isset($paymentLayout['afterMethods']['children']['billing-address-form'])) {
                $jsLayout['components']['checkout']['children']['steps']
                ['children']['billing-step']['children']['payment']['children']
                ['beforeMethods']['children']['billing-address-form']
                    = $paymentLayout['afterMethods']['children']['billing-address-form'];
    
                unset($jsLayout['components']['checkout']['children']['steps']
                ['children']['billing-step']['children']['payment']
                ['children']['afterMethods']['children']['billing-address-form']);
            }
    
            return $jsLayout;
        }
    }

    before method is used to display content before the payment methods.

    Clear the cache and go to the checkout page to see the billing address. It will be at the top of the payment page.

    How to display CMS block below order summary section on checkout page?

    If you want to show some text or message using CMS block below Order Summary section on Checkout Page, then follow below steps.

    Step 1 : Create file like app/code/Magemonkeys/Belowordersummary/registration.php

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

    Step 2 : Create file like app/code/Magemonkeys/Belowordersummary/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="MagentoCheckoutModelCompositeConfigProvider">
            <arguments>
                <argument name="configProviders" xsi:type="array">
                    <item name="cms_block_config_provider" xsi:type="object">MagemonkeysBelowordersummaryModelCmsConfigProvider</item>
                </argument>
            </arguments>
        </type>
        <type name="MagemonkeysBelowordersummaryModelCmsConfigProvider">
            <arguments>
                <argument name="blockId" xsi:type="string">checkout-cms-block</argument>
            </arguments>
        </type>
    </config>

    Step 3 : Create file like app/code/Magemonkeys/Belowordersummary/etc/module.xml

    <?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="Magemonkeys_Belowordersummary" setup_version="1.0.0"></module>
    </config>

    Step 4 : Create file like app/code/Magemonkeys/Belowordersummary/Model/CmsConfigProvider.php

    <?php
        
        namespace MagemonkeysBelowordersummaryModel;
    
        use MagentoCheckoutModelConfigProviderInterface;
        use MagentoFrameworkViewLayoutInterface;
        use MagentoStoreModelStoreManagerInterface;
    
        /**
        * Class ConfigProvider
        * @codeCoverageIgnore
        */
        final class CmsConfigProvider implements ConfigProviderInterface
        {
    
            private $layout;
            private $storeManager;
            private $cmsBlock;
    
            public function __construct(LayoutInterface $layout, StoreManagerInterface $storeManager, $blockId)
            {
                $this->layout = $layout;
                $this->storeManager = $storeManager;
                $this->cmsBlock = $blockId;
            }
    
            public function getStoreId()
            {
                return $this->storeManager->getStore()->getId();
            }
    
            public function constructBlock($blockId)
            {
                $storeId = $this->getStoreId();
                $block = $this->layout->createBlock('MagentoCmsBlockBlock')->setBlockId($blockId)->setStoreId($storeId)->toHtml();
                return $block;
            }
    
            public function getConfig()
            {
                $cmsBlock = '';
                $blockId = $this->cmsBlock;
                if (isset($blockId) && $blockId != '') {
                    $cmsBlock = $this->constructBlock($blockId);
                }
                return ['cms_block' => $cmsBlock];
            }
        }

    Step 5 : Copy file sidebar.html in your theme from vendor/magento/module-checkout/view/frontend/web/template/sidebar.html

    Add this code in your sidebar.html

    <div class="opc-block-shipping-information">
        <div data-bind="html: window.checkoutConfig.cms_block"></div>
    </div>

    That’s it…

    Now, you can check your Checkout Page. It will show your text or message which is set in static block as displaying below Order Summery section.

    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.

    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];
    }
    

     

    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.