Skip to content

#9439 Save region details in order address edit. #9511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
*/
namespace Magento\Sales\Controller\Adminhtml\Order;

use Magento\Directory\Model\RegionFactory;
use Magento\Backend\App\Action;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\InputException;
use Psr\Log\LoggerInterface;

/**
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
{
/**
Expand All @@ -15,6 +27,58 @@ class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
*/
const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';

/** @var RegionFactory $regionFactory */
private $regionFactory;

/**
* @param Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Framework\Translate\InlineInterface $translateInline
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param OrderManagementInterface $orderManagement
* @param OrderRepositoryInterface $orderRepository
* @param LoggerInterface $logger
* @param RegionFactory $regionFactory
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
public function __construct(
Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Framework\Translate\InlineInterface $translateInline,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
OrderManagementInterface $orderManagement,
OrderRepositoryInterface $orderRepository,
LoggerInterface $logger,
RegionFactory $regionFactory = null
) {
parent::__construct(
$context,
$coreRegistry,
$fileFactory,
$translateInline,
$resultPageFactory,
$resultJsonFactory,
$resultLayoutFactory,
$resultRawFactory,
$orderManagement,
$orderRepository,
$logger
);
$this->regionFactory = $regionFactory ?:
\Magento\Framework\App\ObjectManager::getInstance()
->get('\Magento\Directory\Model\RegionFactory');
}

/**
* Save order address
*
Expand All @@ -32,6 +96,14 @@ public function execute()
if ($data && $address->getId()) {
$address->addData($data);
try {
if ($address->getRegion() == null) {
$regionId = $address->getRegionId();
/** @var \Magento\Directory\Model\Region $region */
$region = $this->regionFactory->create();
$region->getResource()->load($region, $regionId);
$address->setRegion($region->getName());
$address->setRegionCode($region->getCode());
}
$address->save();
$this->_eventManager->dispatch(
'admin_sales_order_address_update',
Expand Down