Skip to content

Commit

Permalink
update getCustomer method in order class
Browse files Browse the repository at this point in the history
  • Loading branch information
sertlab committed Jan 16, 2020
1 parent 6b4a82b commit 92816ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/code/Magento/Sales/Api/Data/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Sales\Api\Data;

use Magento\Customer\Model\Customer;

/**
* Order interface.
*
Expand Down Expand Up @@ -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.
*
Expand Down
23 changes: 22 additions & 1 deletion app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 92816ab

Please sign in to comment.