Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
CustomerOrders Class Reference

Public Member Functions

 __construct (SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder, OrderRepositoryInterface $orderRepository, CurrencyFactory $currencyFactory, LoggerInterface $logger)
 
 getAggregatedOrdersInfo ($customerId)
 

Detailed Description

Provides information about customer orders.

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 22 of file CustomerOrders.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( SearchCriteriaBuilder  $searchCriteriaBuilder,
FilterBuilder  $filterBuilder,
OrderRepositoryInterface  $orderRepository,
CurrencyFactory  $currencyFactory,
LoggerInterface  $logger 
)
Parameters
SearchCriteriaBuilder$searchCriteriaBuilder
FilterBuilder$filterBuilder
OrderRepositoryInterface$orderRepository
CurrencyFactory$currencyFactory
LoggerInterface$logger

Definition at line 66 of file CustomerOrders.php.

72  {
73  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
74  $this->filterBuilder = $filterBuilder;
75  $this->orderRepository = $orderRepository;
76  $this->currencyFactory = $currencyFactory;
77  $this->logger = $logger;
78  }

Member Function Documentation

◆ getAggregatedOrdersInfo()

getAggregatedOrdersInfo (   $customerId)

Returns aggregated customer orders count and total amount in USD.

Returned array contains next keys: aggregateOrderCount - total count of orders placed by this account since it was created, including the current aggregateOrderDollars - total amount spent by this account since it was created, including the current order

Parameters
int$customerId
Returns
array

Definition at line 90 of file CustomerOrders.php.

91  {
92  $result = [
93  'aggregateOrderCount' => null,
94  'aggregateOrderDollars' => null
95  ];
96 
97  $customerOrders = $this->getCustomerOrders($customerId);
98  if (!empty($customerOrders)) {
99  try {
100  $orderTotalDollars = 0.0;
101  foreach ($customerOrders as $order) {
102  $orderTotalDollars += $this->getUsdOrderTotal(
103  $order->getBaseGrandTotal(),
104  $order->getBaseCurrencyCode()
105  );
106  }
107  $result = [
108  'aggregateOrderCount' => count($customerOrders),
109  'aggregateOrderDollars' => $orderTotalDollars
110  ];
111  } catch (Exception $e) {
112  $this->logger->error($e->getMessage());
113  }
114  }
115 
116  return $result;
117  }
$order
Definition: order.php:55

The documentation for this class was generated from the following file: