From 92816ab04db61666741ae9ab0986175068c46bee Mon Sep 17 00:00:00 2001 From: Fanis Strezos Date: Thu, 16 Jan 2020 15:38:32 +0000 Subject: [PATCH] update getCustomer method in order class --- .../Magento/Sales/Api/Data/OrderInterface.php | 8 +++++++ app/code/Magento/Sales/Model/Order.php | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Api/Data/OrderInterface.php b/app/code/Magento/Sales/Api/Data/OrderInterface.php index b45fddc7d7354..f699d24bd32cd 100644 --- a/app/code/Magento/Sales/Api/Data/OrderInterface.php +++ b/app/code/Magento/Sales/Api/Data/OrderInterface.php @@ -5,6 +5,8 @@ */ namespace Magento\Sales\Api\Data; +use Magento\Customer\Model\Customer; + /** * Order interface. * @@ -910,6 +912,12 @@ public function getCreatedAt(); */ public function setCreatedAt($createdAt); + /** + * Gets the customer from Order + * @return Customer + */ + public function getCustomer(); + /** * Gets the customer date-of-birth (DOB) for the order. * diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 89564f97ccf16..1d520574f21d7 100644 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -6,6 +6,7 @@ namespace Magento\Sales\Model; use Magento\Config\Model\Config\Source\Nooptreq; +use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Directory\Model\Currency; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\SearchCriteriaBuilder; @@ -51,7 +52,6 @@ * @method bool hasCustomerNoteNotify() * @method bool hasForcedCanCreditmemo() * @method bool getIsInProcess() - * @method \Magento\Customer\Model\Customer getCustomer() * @method \Magento\Sales\Model\Order setSendEmail(bool $value) * @SuppressWarnings(PHPMD.ExcessivePublicCount) * @SuppressWarnings(PHPMD.TooManyFields) @@ -307,6 +307,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface */ private $scopeConfig; + /** + * @var CustomerRepositoryInterface + */ + private $_customerRepositoryInterface; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -340,6 +345,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface * @param OrderItemRepositoryInterface $itemRepository * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param ScopeConfigInterface $scopeConfig + * @param CustomerRepositoryInterface $customerRepositoryInterface * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -366,6 +372,7 @@ public function __construct( \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory $trackCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollectionFactory, PriceCurrencyInterface $priceCurrency, + CustomerRepositoryInterface $customerRepositoryInterface, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, @@ -403,6 +410,7 @@ public function __construct( $this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance() ->get(SearchCriteriaBuilder::class); $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); + $this->_customerRepositoryInterface = $customerRepositoryInterface; parent::__construct( $context, @@ -562,6 +570,19 @@ public function getStore() return $this->_storeManager->getStore(); } + /** + * Returns Customer + * + * @return \Magento\Customer\Api\Data\CustomerInterface + * @throws LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getCustomer() + { + $customerId = $this->getData(OrderInterface::CUSTOMER_ID); + return $this->_customerRepositoryInterface->getById($customerId); + } + /** * Retrieve order cancel availability *