根据您的问题,我假设您已经设置了扩展属性。我进行了类似的修改,希望我的回答会有所帮助。
在您的自定义模块中,创建一个requirejs-config文件以扩展默认的运送处理器/默认
命名空间/CustomModule/view/frontend/requirejs-config.js
var config = {
“地图”:{
“ *”:{
'Magento_Checkout / js / model / shipping-save-processor / default':'Namespace_CustomModule / js / model / shipping-save-processor / default'
}
}
};
将扩展属性添加到有效负载。
/ *全局定义,警报* /
限定(
[
'jquery',
'ko',
'Magento_Checkout / js / model / quote',
'Magento_Checkout / js / model / resource-url-manager',
“法师/存储”,
'Magento_Checkout / js / model / payment-service',
'Magento_Checkout / js / model / payment / method-converter',
'Magento_Checkout / js / model / error-processor',
'Magento_Checkout / js / model / full-screen-loader',
'Magento_Checkout / js / action / select-billing-address'
],
功能(
$,
,
引用,
resourceUrlManager,
存储,
PaymentService,
methodConverter,
errorProcessor,
fullScreenLoader,
selectBillingAddressAction
){
“使用严格”;
返回{
saveShippingInformation:function(){
var有效负载;
如果(!quote.billingAddress()){
selectBillingAddressAction(quote.shippingAddress());
}
//将扩展属性添加到您的收货地址
有效载荷= {
地址信息: {
送货地址:quote.shippingAddress(),
billing_address:quote.billingAddress(),
shipping_method_code:quote.shippingMethod()。method_code,
shipping_carrier_code:quote.shippingMethod()。carrier_code,
extension_attributes:{
custom_field:$('#custom_field')。val(),
}
}
};
fullScreenLoader.startLoader();
返回storage.post(
resourceUrlManager.getUrlForSetShippingInformation(quote),
JSON.stringify(有效载荷)
)。完成(
功能(响应){
quote.setTotals(response.totals);
paymentService.setPaymentMethods(methodConverter(response.payment_methods));
fullScreenLoader.stopLoader();
}
)。失败(
功能(响应){
errorProcessor.process(response);
fullScreenLoader.stopLoader();
}
);
}
};
}
);
使用插件将属性保存到您的报价中(不确定是否可以使用此处未查看的观察者)。
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="Magento\Checkout\Model\ShippingInformationManagement">
<plugin name="Namespace_CustomModule_save_delivery_date_in_quote" type="Namespace\CustomModule\Plugin\Checkout\SaveAddressInformation" />
</type>
</config>
SaveAddressInformation.php
SaveAddressInformation类
{
受保护的$ quoteRepository;
公共功能__construct(
\ Magento \ Quote \ Model \ QuoteRepository $ quoteRepository
){
$ this-> quoteRepository = $ quoteRepository;
}
/ **
* @param \ Magento \ Checkout \ Model \ ShippingInformationManagement $ subject
* @参数$ cartId
* @param \ Magento \ Checkout \ Api \ Data \ ShippingInformationInterface $ addressInformation
* /
公用函数beforeSaveAddressInformation(
\ Magento \ Checkout \ Model \ ShippingInformationManagement $ subject,
$ cartId,
\ Magento \ Checkout \ Api \ Data \ ShippingInformationInterface $ addressInformation
){
$ extensionAttributes = $ addressInformation-> getExtensionAttributes();
$ customField = $ extensionAttributes-> getCustomField();
$ quote = $ this-> quoteRepository-> getActive($ cartId);
$ quote-> setCustomField($ customField);
}
}
使用Observer events.xml将属性保存到您的订单中
<?xml version="1.0" encoding="UTF-8"?>
<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="unique_observer_name" instance="Namespace\CustomModule\Observer\SaveCustomFieldToOrder"/>
</event>
</config>
SaveCustomFieldToOrder.php
SaveCustomFieldToOrder类实现ObserverInterface
{
/ **
* @var \ Magento \ Framework \ ObjectManagerInterface
* /
受保护的$ _objectManager;
/ **
* @参数\ Magento \ Framework \ ObjectManagerInterface $ objectmanager
* /
公共函数__construct(\ Magento \ Framework \ ObjectManagerInterface $ objectmanager)
{
$ this-> _ objectManager = $ objectmanager;
}
公共函数execute(EventObserver $ observer)
{
$ order = $ observer-> getOrder();
$ quoteRepository = $ this-> _ objectManager-> create('Magento \ Quote \ Model \ QuoteRepository');
/ ** @var \ Magento \ Quote \ Model \ Quote $ quote * /
$ quote = $ quoteRepository-> get($ order-> getQuoteId());
$ order-> setCustomField($ quote-> getCustomField());
返回$ this;
}
}