• Magento2:如何保存在用户自定义字段值(客户)登记表


    InstallData.php

    <?php
    namespace PulsestormHelloWorldMVVMSetup;
    use MagentoFrameworkModuleSetupMigration;
    use MagentoFrameworkSetupInstallDataInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;
    class InstallData implements InstallDataInterface
    {
        /**
         * Customer setup factory
         *
         * @var MagentoCustomerSetupCustomerSetupFactory
         */
        private $customerSetupFactory;
        /**
         * Init
         *
         * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
         */
        public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
        {
            $this->customerSetupFactory = $customerSetupFactory;
        }
        /**
         * Installs DB schema for a module
         *
         * @param ModuleDataSetupInterface $setup
         * @param ModuleContextInterface $context
         * @return void
         */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
        $installer = $setup;
        $installer->startSetup();
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $entityTypeId = $customerSetup->getEntityTypeId(MagentoCustomerModelCustomer::ENTITY);
    
        $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, "regulation",  array(
            "type"     => "int",
            "backend"  => "",
            "label"    => "Regulation",
            "input"    => "text",
            "source"   => 'MagentoEavModelEntityAttributeSourceBoolean',
            "visible"  => true,
            "required" => true,
            "default" => "",
            "frontend" => "",
            "unique"     => false,
            "note"       => ""
    
        ));
    
        $regulation   = $customerSetup->getAttribute(MagentoCustomerModelCustomer::ENTITY, "regulation");
    
        $regulation = $customerSetup->getEavConfig()->getAttribute(MagentoCustomerModelCustomer::ENTITY, 'regulation');
        $used_in_forms[]="adminhtml_customer";
        $used_in_forms[]="checkout_register";
        $used_in_forms[]="customer_account_create";
        $used_in_forms[]="customer_account_edit";
        $used_in_forms[]="adminhtml_checkout";
        $regulation->setData("used_in_forms", $used_in_forms)
            ->setData("is_used_for_customer_segment", true)
            ->setData("is_system", 0)
            ->setData("is_user_defined", 1)
            ->setData("is_visible", 1)
            ->setData("sort_order", 100);
        $regulation->save();
    
        $installer->endSetup();
    }
    }
    

    customer_account_create.xml

    <?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="form.additional.info">
            <block class="MagentoFrameworkViewElementTemplate" name="my_form_additional_info_customer" template="Pulsestorm_HelloWorldMVVM::customer.phtml"/>
        </referenceContainer>
    </body></page>
    

    customer.phtml

    <fieldset class="fieldset create account" >
        <legend class="legend"><span><?php /* @escapeNotVerified */
                echo __('Additional Information') ?></span></legend>
    
    <p>
    <div class="field regulation required">
        <label for="regulation" class="label"><span><?php /* @escapeNotVerified */
                echo __('Regulation') ?></span></label>
        <div class="control">
            <input type="text" name="regulation" id="photo" title="<?php /* @escapeNotVerified */
            echo __('Regulation') ?>" class="input-text" data-validate="{required:false}">
        </div>
    </div>
    </p></fieldset>
    

    我需要知道我可以在数据库中插入调节价值?现场(监管)没有在数据库中保存。在该表中该领域将被保存?创建新的模块或标准的Magento登记表中加入1客户属性,是的,要创造新的模块。

  • 相关阅读:
    下载文件
    利用 js 获取地址栏参数
    子组件向父组件传值
    cordova 插件 调用iOS社交化分享(ShareSDK:微信QQ分享)
    cordova 企业应用打包Archive的时候报 "#import <Cordova file not found"
    企业应用打包的时候 修改ipa包的bundle identifier
    Mac下利用safari调试 Cordova的WebApp
    Mac下利用Cordova打包 iOS App以及出现的问题
    数据库设计流程
    Javascript 获取dom的宽度 随笔一
  • 原文地址:https://www.cnblogs.com/magento-maijindou/p/5889533.html
Copyright © 2020-2023  润新知