Zend certified PHP/Magento developer

Magento2: get values to databse

I’m trying to get values from the popup model of radio buttons into the database and I’m not getting that, what am I doing wrong?

BLOCK FILE

<?php

namespace vendorThreeYearOrdersBlock;

use MagentoFrameworkViewElementTemplateContext;
use MagentoCustomerModelSession;

class Popup extends MagentoFrameworkViewElementTemplate
{

     /**
     * @param MagentoFrameworkViewElementTemplateContext $context
     * @param array $data
     **/

    /**
     * @var customerSession
     */
    protected $_customerSession;

      /**
     * @var ThreeYearOrdersBlockId
     */
    const XML_THREE_YEAR_ORDERS_BLOCK_ID = 'ThreeYearOrders/general/block_id';

    /**
     * @var ScopeConfig
     */
    protected $_scopeConfig;

    /**
     * Popup constructor.
     *
     * @param ScopeConfigInterface $scopeConfig
     */
    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        Session $customerSession
    ) {
        parent::__construct($context);
        $this->_scopeConfig = $scopeConfig;
        $this->_customerSession = $customerSession;
    }

    /**
     * Get Popup Config
     *
     * @return array|mixed
     */
    public function getThreeYearOdersBlockId()
    {
        return $this->_scopeConfig->getValue(self::XML_THREE_YEAR_ORDERS_BLOCK_ID, MagentoStoreModelScopeInterface::SCOPE_STORE);
    }
    /**
     * Check if customer is logged in
     *
     * @return bool
     */

    public function isLoggedIn()
    {
        return $this->_customerSession->isLoggedIn();
    }
    public function getFormAction()
    {
        return $this->getUrl('vendor_threeyearorders/Index/Action', ['_secure' => true]);
    }

}

CONTROLLER FILE

<?php

namespace vendorThreeYearOrdersControllerIndex;

use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoCustomerModelSession;
use MagentoCustomerModelCustomerFactory;

class Action extends MagentoFrameworkAppActionAction
{
    /**
     * @var MagentoFrameworkViewResultPageFactory
     */
    protected $_pageFactory;

    /**
     * @var MagentoCustomerModelSession
     */
    protected $customerSession;

    /**
     * @var MagentoCustomerModelCustomerFactory
     */
    protected $customerFactory;

    /**
     * @param MagentoFrameworkAppActionContext $context
     * @param MagentoFrameworkViewResultPageFactory $pageFactory
     * @param MagentoCustomerModelSession $customerSession
     * @param MagentoCustomerModelCustomerFactory $customerFactory
     */
    public function __construct(
        Context $context,
        PageFactory $pageFactory,
        Session $customerSession,
        CustomerFactory $customerFactory
    ) {
        $this->_pageFactory = $pageFactory;
        $this->customerSession = $customerSession;
        $this->customerFactory = $customerFactory;
        parent::__construct($context);
    }

    /**
     * View page action
     *
     * @return MagentoFrameworkControllerResultInterface
     */
    public function execute()
    {
        $deleteOrder = $this->getRequest()->getParam('deleteOrder');
        if (in_array($deleteOrder, ['1', '0'])) {
            $customerId = $this->customerSession->getCustomerId();
            $customerData = $this->customerFactory->create()->load($customerId);

            if ($deleteOrder === '1') {
                $customerData->setData('deleteOrder', 1);
            } else {
                $customerData->setData('deleteOrder', 0);
            }

            $customerData->save();
        }
    }
}

SETUP [INSTALLSCHEMA] FILE

<?php

namespace vendorThreeYearOrdersSetup;

use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkDBDdlTable;

class InstallSchema implements InstallSchemaInterface
{
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        $table = $installer->getTable('customer_entity');

        $installer->getConnection()->addColumn(
            $table,
            'deleteOrder',
            [
                'type' => Table::TYPE_INTEGER,
                'nullable' => true,
                'default' => null,
                'comment' => 'Delete Order'
            ]
        );

        $installer->endSetup();
    }
}

TEMPLATES

<?php
    $block_id = $block->getThreeYearOdersBlockId();
?>

<?php if ($block->isLoggedIn()): ?>

<div id="three-year-orders" class="checkBox-delete-orders">
    <form id="selectedDelect" action="<?= $block->getFormAction() ?>" method="post">
        <?php
        echo $this->getLayout()
            ->createBlock('MagentoCmsBlockBlock')
            ->setBlockId($block_id)
            ->toHtml();
        ?>

        <label class="headingCheckbox">You have orders that are 3 years old. Do you want to delete them? </label> <br />
        <input type="radio" name="deleteOrder" id="deleteOrderYes" value="1">
        <label for="deleteOrderYes" class="deleteOrderYes">Yes</label> |
        <input type="radio" name="deleteOrder" id="deleteOrderNo" value="0">
        <label for="deleteOrderNo" class="deleteOrderNo">No</label>
    </form>
</div>

<?php endif; ?>

<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal',
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                // responsive: true,
                innerScroll: true,
                title: false,
                modalClass:'modal-pricepopup', // you can replace this class and use codazon class which is "cdz-alert-popup" or leave it as default. 
                buttons: [{
                    text: $.mage.__('Close'),
                    class: '',
                    click: function () {
                        this.closeModal();
                    }
                }, {
                    text: $.mage.__('Submit'),
                    class: '',
                    click: function () {
                        $('#selectedDelect').submit();
                    }
                }]
            };
            $(document).ready(function(){
                var popup = modal(options, $('#three-year-orders'));
                $('#three-year-orders').modal('openModal');
                $('#click-here').on('click', function(){
                    $('#three-year-orders').modal('openModal');
                });
            });
        }
    );
</script>