Skip to content

Commit 92816ab

Browse files
committed
update getCustomer method in order class
1 parent 6b4a82b commit 92816ab

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/code/Magento/Sales/Api/Data/OrderInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sales\Api\Data;
77

8+
use Magento\Customer\Model\Customer;
9+
810
/**
911
* Order interface.
1012
*
@@ -910,6 +912,12 @@ public function getCreatedAt();
910912
*/
911913
public function setCreatedAt($createdAt);
912914

915+
/**
916+
* Gets the customer from Order
917+
* @return Customer
918+
*/
919+
public function getCustomer();
920+
913921
/**
914922
* Gets the customer date-of-birth (DOB) for the order.
915923
*

app/code/Magento/Sales/Model/Order.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Sales\Model;
77

88
use Magento\Config\Model\Config\Source\Nooptreq;
9+
use Magento\Customer\Api\CustomerRepositoryInterface;
910
use Magento\Directory\Model\Currency;
1011
use Magento\Framework\Api\AttributeValueFactory;
1112
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -51,7 +52,6 @@
5152
* @method bool hasCustomerNoteNotify()
5253
* @method bool hasForcedCanCreditmemo()
5354
* @method bool getIsInProcess()
54-
* @method \Magento\Customer\Model\Customer getCustomer()
5555
* @method \Magento\Sales\Model\Order setSendEmail(bool $value)
5656
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
5757
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -307,6 +307,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
307307
*/
308308
private $scopeConfig;
309309

310+
/**
311+
* @var CustomerRepositoryInterface
312+
*/
313+
private $_customerRepositoryInterface;
314+
310315
/**
311316
* @param \Magento\Framework\Model\Context $context
312317
* @param \Magento\Framework\Registry $registry
@@ -340,6 +345,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
340345
* @param OrderItemRepositoryInterface $itemRepository
341346
* @param SearchCriteriaBuilder $searchCriteriaBuilder
342347
* @param ScopeConfigInterface $scopeConfig
348+
* @param CustomerRepositoryInterface $customerRepositoryInterface
343349
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
344350
*/
345351
public function __construct(
@@ -366,6 +372,7 @@ public function __construct(
366372
\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory $trackCollectionFactory,
367373
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollectionFactory,
368374
PriceCurrencyInterface $priceCurrency,
375+
CustomerRepositoryInterface $customerRepositoryInterface,
369376
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory,
370377
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
371378
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -403,6 +410,7 @@ public function __construct(
403410
$this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance()
404411
->get(SearchCriteriaBuilder::class);
405412
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
413+
$this->_customerRepositoryInterface = $customerRepositoryInterface;
406414

407415
parent::__construct(
408416
$context,
@@ -562,6 +570,19 @@ public function getStore()
562570
return $this->_storeManager->getStore();
563571
}
564572

573+
/**
574+
* Returns Customer
575+
*
576+
* @return \Magento\Customer\Api\Data\CustomerInterface
577+
* @throws LocalizedException
578+
* @throws \Magento\Framework\Exception\NoSuchEntityException
579+
*/
580+
public function getCustomer()
581+
{
582+
$customerId = $this->getData(OrderInterface::CUSTOMER_ID);
583+
return $this->_customerRepositoryInterface->getById($customerId);
584+
}
585+
565586
/**
566587
* Retrieve order cancel availability
567588
*

0 commit comments

Comments
 (0)