😕 Lots of repeating & duplicate code
public function process($jsLayout): array
{
$attributeCode = 'address_classification';
$jsLayout['components']['checkout']['children']
['steps']['children']
['shipping-step']['children']
['shippingAddress']['children']
['shipping-address-fieldset']['children']
[$attributeCode]['config']['customScope'] = 'shippingAddress.custom_attributes';
$jsLayout['components']['checkout']['children']
['steps']['children']
['shipping-step']['children']
['shippingAddress']['children']
['shipping-address-fieldset']['children']
[$attributeCode]['dataScope'] = "shippingAddress.custom_attributes.$attributeCode";
return $jsLayout;
}
🐕 More DRY, much WOW
public function process($jsLayout): array
{
$attributeCode = 'address_classification';
$attributeData = &$jsLayout['components']['checkout']['children']
['steps']['children']
['shipping-step']['children']
['shippingAddress']['children']
['shipping-address-fieldset']['children']
[$attributeCode];
$attributeData['config']['customScope'] = 'shippingAddress.custom_attributes';
$attributeData['dataScope'] = "shippingAddress.custom_attributes.$attributeCode";
return $jsLayout;
}
Visit M.academy to learn much more about Magento, Laravel, PHP, Javascript, & Docker.