init
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Stemcell\ChineseDirectory\Observer\Order\Address;
|
||||
|
||||
use Magento\Framework\DataObject\Copy\Config;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Sales\Model\Order;
|
||||
|
||||
class AttachExtensionAttributeObserver implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected Config $fieldsetConfig;
|
||||
|
||||
public function __construct(
|
||||
Config $config
|
||||
) {
|
||||
$this->fieldsetConfig = $config;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
/* @var $order Order */
|
||||
$order = $observer->getData('order');
|
||||
|
||||
/* @var $quote Quote */
|
||||
$quote = $observer->getData('quote');
|
||||
$aspect = 'to_order_address';
|
||||
$fields = $this->fieldsetConfig->getFieldset('sales_convert_quote_address');
|
||||
$extensionAttributes = $quote->getShippingAddress()->getExtensionAttributes();
|
||||
$orderAddress = $order->getShippingAddress();
|
||||
foreach ($fields as $code => $node) {
|
||||
if (empty($node[$aspect])) {
|
||||
continue;
|
||||
}
|
||||
$method = 'get' . str_replace('_', '', ucwords($code, '_'));
|
||||
if (method_exists($extensionAttributes, $method) && $extensionAttributes->$method()) {
|
||||
$orderAddress->setData($code, $extensionAttributes->$method());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user