I tried to add an Upload file attribute to the Checkout form, I am now able to add a custom field, but still, I am unable to save values to the database -
I used add Plugin -
added Below code
Amit\Fileupload\etc\di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
<plugin name="file_upload" type="Amit\Fileupload\Model\Plugin\Checkout\LayoutProcessor" sortOrder="100"/>
</type>
</config>
Amit\Fileupload\Model\Plugin\Checkout\LayoutProcessor.php
<?php
namespace Amit\Fileupload\Model\Plugin\Checkout;
class LayoutProcessor
{
/**
* @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* @param array $jsLayout
* @return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
$fileupload = 'file_upload';
$datascope = 'shippingAddress.custom_attributes';
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children'][$fileupload] = [
'component' => 'Magento_Ui/js/form/element/media',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'customEntry' => null,
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/media',
'tooltip' => ['description' => 'Field to Upload File'],
'id' => $fileupload
],
'dataScope' => $datascope,
'label' => 'File Upload',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => ['required-entry' => true],
'options' => [],
'sortOrder' => 250,
'id' => $fileupload
];
return $jsLayout;
}
}
Now, further how to save the data of this field, looking for help on this thanks!
