Magento2 添加到Magento 2.4签出的字段未保存

Magento2 添加到Magento 2.4签出的字段未保存,magento2,magento2-extensions,Magento2,Magento2 Extensions,我正在经营的网店需要在收银台上增加一个下拉列表。此下拉列表是存储在模块添加的表中的商店/零售商列表(可互换使用)。它应该按顺序保存所选存储的ID,以便可以通过主键查找存储的数据 到目前为止,我已经能够做到以下几点: 使用InstallSchemaInterface将字段(作为整数)添加到quote、sales\u order、sales\u order\u网格中 在签出中显示下拉列表,并填充相应的值 我一直坚持的是正确地保存所选的值。它当前以0的形式写入数据库。我试着跟随,但这对我来说不起作

我正在经营的网店需要在收银台上增加一个下拉列表。此下拉列表是存储在模块添加的表中的商店/零售商列表(可互换使用)。它应该按顺序保存所选存储的ID,以便可以通过主键查找存储的数据

到目前为止,我已经能够做到以下几点:

  • 使用InstallSchemaInterface将字段(作为整数)添加到quote、sales\u order、sales\u order\u网格中
  • 在签出中显示下拉列表,并填充相应的值
我一直坚持的是正确地保存所选的值。它当前以0的形式写入数据库。我试着跟随,但这对我来说不起作用。搜索这类内容会返回其他几个指南,它们与我链接的指南非常相似,但我也无法使它们正常工作

我的代码如下:(将公司名称替换为“company”;省略了LayoutProcessor和InstallSchema,因为它们工作正常,以避免问题过于混乱。)

app/code/Company/InhouseCheckout/etc/config.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
    </default>
</config>
最后,app/code/Company/InhouseCheckout/view/frontend/web/js是default.js文件的一个副本,其
有效负载
块修改如下:

payload = {
    addressInformation: {
        shipping_address: quote.shippingAddress(),
        billing_address: quote.billingAddress(),
        shipping_method_code: quote.shippingMethod().method_code,
        shipping_carrier_code: quote.shippingMethod().carrier_code,
        extension_attributes: {
            retailer: jQuery('[name="retailer"]').val()
        }
    }
};
我希望我提供了足够的信息

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_before">
        <observer name="custom_fields_sales_address_save" instance="Company\InhouseCheckout\Observer\SaveCustomFieldsInOrder" />
    </event>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
        <attribute code="retailer" type="int"/>
    </extension_attributes>
    <extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
        <attribute code="retailer" type="int"/>
    </extension_attributes>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
    <scope id="global">
        <fieldset id="sales_convert_quote">
            <field name="retailer">
                <aspect name="to_order"/>
            </field>
        </fieldset>
    </scope>
</config>
<?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="Company_InhouseCheckout" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Store"/>
        </sequence>
    </module>
</config>
<?php
namespace Company\InhouseCheckout\Observer;

/**
* Class SaveCustomFieldsInOrder
*/
class SaveCustomFieldsInOrder implements \Magento\Framework\Event\ObserverInterface {
   /**
    * @param \Magento\Framework\Event\Observer $observer
    * @return $this
    */
    public function execute(\Magento\Framework\Event\Observer $observer){

        $order = $observer->getEvent()->getOrder();
        $quote = $observer->getEvent()->getQuote();

        $order->setData("retailer", $quote->getRetailer());

        return $this;
    }
}
<?php
namespace Company\InhouseCheckout\Plugin\Checkout;

class ShippingInformationManagementPlugin
{
    protected $quoteRepository;

    public function __construct(\Magento\Quote\Model\QuoteRepository $quoteRepository)
    {
        $this->quoteRepository = $quoteRepository;
    }

    /**
     * @param SIMModel $subject
     * @param $cartId
     * @param ShippingInformationInterface $addressInformation
     */
    public function beforeSaveAddressInformation(
        \Magento\Checkout\Model\ShippingInformationManagement $subject,
        $cartId,
        \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
    ): void {
        
        $extAttributes = $addressInformation->getExtensionAttributes();
        
        $retailer = $extAttributes->getRetailer();
        $quote = $this->quoteRepository->getActive($cartId);
        
        $quote->setRetailer($retailer);
    }
}
var config = {
    "map": {
        "*": {
            "Magento_Checkout/js/model/shipping-save-processor/default" : "Company_InhouseCheckout/js/shipping-save-processor-default-override",
            "Rokanthemes_OpCheckout/js/model/shipping-save-processor/default" : "Company_InhouseCheckout/js/shipping-save-processor-default-override"
        }
    }
};
payload = {
    addressInformation: {
        shipping_address: quote.shippingAddress(),
        billing_address: quote.billingAddress(),
        shipping_method_code: quote.shippingMethod().method_code,
        shipping_carrier_code: quote.shippingMethod().carrier_code,
        extension_attributes: {
            retailer: jQuery('[name="retailer"]').val()
        }
    }
};