#StackBounty: #magento2 #module #custom-options #payment-methods Magento2 : Custom payment Module with Drop down list Is not working

Bounty: 50

Please check my Custom payment Module, I was able to display the list in drop down in Payment method, But when i select and place order it is not completing the process nor save the Details.

appcodeK2BPickPayviewfrontendlayoutcheckout_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn: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="component" xsi:type="string">uiComponent</item>
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="renders" xsi:type="array">
                                                            <!-- merge payment method renders here -->
                                                            <item name="children" xsi:type="array">
                                                                <item name="pickpay-payments" xsi:type="array">
                                                                    <item name="component" xsi:type="string">K2B_PickPay/js/view/payment/offline-payments</item>

                                                                    <item name="methods" xsi:type="array">
                                                                        <item name="pickpay" xsi:type="array">
                                                                            <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

appcodeK2BPickPayModelPickpay.php

namespace K2BPickPayModel;
use MagentoFrameworkDataObject;
use MagentoQuoteApiDataPaymentInterface;
/**
 * Pay In Store payment method model
 */
class Pickpay extends MagentoPaymentModelMethodAbstractMethod
{
    const PAYMENT_METHOD_PICKPAY_CODE = 'pickpay';
    /**
     * Payment code
     *
     * @var string
     */
    protected $_code = self::PAYMENT_METHOD_PICKPAY_CODE;
    /**
     * Availability option
     *
     * @var bool
     */
    protected $_isOffline = true;
     /**
     * @var string
     */
    protected $_formBlockType = 'K2BPickPayBlockFormPickpay';

    /**
     * @var string
     */
    protected $_infoBlockType = 'K2BPickPayBlockInfoPickpay';



    /**
     * Assign data to info model instance
     *
     * @param MagentoFrameworkDataObject|mixed $data
     * @return $this
     * @throws MagentoFrameworkExceptionLocalizedException
     */
    public function assignData(MagentoFrameworkDataObject $data)
    {
        $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
        if (!is_object($additionalData)) {
            $additionalData = new DataObject($additionalData ?: []);
        }       
        /*$myfile = fopen("./var/log/pickpay.txt", "a");    

        $txt = "getPickpayLocation:".$additionalData->getPickpayLocation();     
        fwrite($myfile, "n". $txt);
        fclose($myfile);*/
        $this->getInfoInstance()->setPickpayLocation($additionalData->getPickpayLocation());
        return $this;
    }

}

appcodeK2BPickPaySetupUpgradeSchema.php

<?php
namespace K2BPickPaySetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{   
    /**
     * {@inheritdoc}
     */
    public function upgrade(
        SchemaSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $installer = $setup;

        $installer->startSetup();       
        if (version_compare($context->getVersion(), '2.0.1', '<')) {            
          $installer->getConnection()->addColumn(
                $installer->getTable('quote_payment'),
                'pickpay_location',
                [
                    'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
                    'length' => 255,
                    'comment' => 'Pay and Pick Store Location'
                ]
            );
          $installer->getConnection()->addColumn(
                $installer->getTable('sales_order_payment'),
                'pickpay_location',
                [
                    'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
                    'length' => 255,
                    'comment' => 'Pay and Pick Store Location'
                ]
            );
        }

        $installer->endSetup();
    }
}

appcodeK2BPickPayviewfrontendtemplatesformpickpay.phtml

<?php
$methodCode = $block->escapeHtml($block->getMethodCode());
$location = $block->escapeHtml($block->getInfoData('pickpay_location'));
?>
<fieldset class="fieldset items <?php /* @noEscape */ echo $methodCode ?>" id="payment_form_<?php /* @noEscape */ echo $methodCode ?>" style="display: none">
    
>CENTRAL SUPER MARKET >ZAKHER BRANCH >MAZYED BRANCH >MARKHANIYA BRANCH >AL MAQAM BRANCH >AL MAQAM BRANCH >AL MANASIR BRANCH >AL HAYER BRANCH >AL YAHAR BRANCH >TAWAM BRANCH >TOWAYYA HABOI BRANCH >HILLI KHALEEF BRANCH >SHOIBA BRANCH >KHALIDIYA BRANCH >FALAJ HAZZA BRANCH >MASOUDI BRANCH >AL BATEEN BRANCH >NAHEL BRANCH >FAQAA BRANCH >UM GHAFA BRANCH >SALAMAT BRANCH >SUWIHAN BRANCH >SHUWAIB BRANCH >ALIAH MALL >AL NAYFA SUPERMARKET
</div> </fieldset>

appcodeK2BPickPayviewfrontendwebjsviewpaymentmethod-rendererpickpay.js

define(
    [
        'Magento_Checkout/js/view/payment/default',
        'jquery',
        "mage/validation"
    ],
    function (Component, $) {
        'use strict';
        return Component.extend({
            defaults: {
                template: 'K2B_PickPay/payment/pickpay-form',
                purchaseOrderNumber: ''
            },
            initObservable: function () {
                this._super()
                    .observe('pickpayLocation');
                return this;
            },
            getData: function () {
                return {
                    "method": this.item.method,
                    'pickpay_location': this.pickpayLocation(),
                    "additional_data": null
                };

            },
            validate: function () {
                var form = 'form[data-role=pickpay-form]';
                return $(form).validation() && $(form).validation('isValid');
            }
        });
    }
);

appcodeK2BPickPayviewfrontendwebjsviewpaymentoffline-payments.js

 define(
        [
            'uiComponent',
            'Magento_Checkout/js/model/payment/renderer-list'
        ],
        function (
            Component,
            rendererList
        ) {
            'use strict';
            rendererList.push(
                {
                    type: 'pickpay',
                    component: 'K2B_PickPay/js/view/payment/method-renderer/pickpay'
                }
            );
            return Component.extend({
                getData: function() {
                return {
                    'method': this.item.method,
                    'additional_data': {
                        'pickpay_location': this.pickPayLocation()
                    }
                };
            }
            });
        }
    );

appcodeK2BPickPayviewfrontendwebtemplatepaymentpickpay-form.html

CENTRAL SUPER MARKET ZAKHER BRANCH MAZYED BRANCH MARKHANIYA BRANCH AL MAQAM BRANCH AL MAQAM BRANCH AL MANASIR BRANCH AL HAYER BRANCH AL YAHAR BRANCH TAWAM BRANCH TOWAYYA HABOI BRANCH HILLI KHALEEF BRANCH SHOIBA BRANCH KHALIDIYA BRANCH FALAJ HAZZA BRANCH MASOUDI BRANCH AL BATEEN BRANCH NAHEL BRANCH FAQAA BRANCH UM GHAFA BRANCH SALAMAT BRANCH SUWIHAN BRANCH SHUWAIB BRANCH ALIAH MALL AL NAYFA SUPERMARKET
</div> </fieldset> </form>
</div> </div> </div>

please check the module here for more details.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.