Model/ResourceModel/Contact.php
public function getSalesDataForSubscribersWithOrderStatusesAndBrand($emails, $websiteId)
    {
        $orderStatuses = $this->config->getWebsiteConfig(
            Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS,
            $websiteId
        );
        $orderStatuses = explode(',', $orderStatuses);

        $orderCollection = $this->orderCollectionFactory->create()
            ->addFieldToSelect(['customer_email'])
            ->addExpressionFieldToSelect('total_spend', 'SUM({{grand_total}})', 'grand_total')
            ->addExpressionFieldToSelect('number_of_orders', 'COUNT({{*}})', '*')
            ->addExpressionFieldToSelect('average_order_value', 'AVG({{grand_total}})', 'grand_total')
            ->addFieldToFilter('customer_email', ['in' => $emails]);

        $columns = $this->buildCollectionColumns();
        $orderCollection->getSelect()
            ->columns($columns)
            ->group('customer_email');

        if (! empty($orderStatuses)) {
            $orderCollection->getSelect()->where('status in (?)', $orderStatuses);
        }

        $orderArray = [];
        foreach ($orderCollection as $item) {
            $orderArray[$item->getCustomerEmail()] = $item->toArray(
                [
                    'total_spend',
                    'number_of_orders',
                    'average_order_value',
                    'last_order_date',
                    'first_order_id',
                    'last_order_id',
                    'last_increment_id',
                    'product_id_for_first_brand',
                    'product_id_for_last_brand',
                    'week_day',
                    'month_day',
                    'product_id_for_most_sold_product'
                ]
            );
        }

        return $orderArray;
    }
public function getSalesDataForSubscribersWithOrderStatusesAndBrand($emails, $websiteId)
    {
        $orderStatuses = $this->config->getWebsiteConfig(
            Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS,
            $websiteId
        );
        $orderStatuses = explode(',', $orderStatuses);

        $orderCollection = $this->orderCollectionFactory->create()
            ->addFieldToSelect(['customer_email'])
            ->addExpressionFieldToSelect('total_spend', 'SUM({{grand_total}})', 'grand_total')
            ->addExpressionFieldToSelect('number_of_orders', 'COUNT({{*}})', '*')
            ->addExpressionFieldToSelect('average_order_value', 'AVG({{grand_total}})', 'grand_total')
            ->addFieldToFilter('customer_email', ['in' => $emails]);

        $columns = $this->buildCollectionColumns();
        $orderCollection->getSelect()
            ->columns($columns)
            ->group('customer_email');

        if (! empty($orderStatuses)) {
            $orderCollection->getSelect()->where('status in (?)', $orderStatuses);
        }

        $orderArray = [];
        foreach ($orderCollection as $item) {
            $orderArray[$item->getCustomerEmail()] = $item->toArray(
                [
                    'total_spend',
                    'number_of_orders',
                    'average_order_value',
                    'last_order_date',
                    'first_order_id',
                    'last_order_id',
                    'last_increment_id',
                    'product_id_for_first_brand',
                    'product_id_for_last_brand',
                    'week_day',
                    'month_day',
                    'product_id_for_most_sold_product'
                ]
            );
        }

        return $orderArray;
    }
public function getSalesDataForSubscribersWithOrderStatusesAndBrand ( $ emails , $ websiteId ) { $ orderStatuses = $ this -> config -> getWebsiteConfig ( Config :: XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS , $ websiteId ) ; $ orderStatuses = explode ( ',' , $ orderStatuses ) ; $ orderCollection = $ this -> orderCollectionFactory -> create ( ) -> addFieldToSelect ( [ 'customer_email' ] ) -> addExpressionFieldToSelect ( 'total_spend' , 'SUM({{grand_total}})' , 'grand_total' ) -> addExpressionFieldToSelect ( 'number_of_orders' , 'COUNT({{*}})' , '*' ) -> addExpressionFieldToSelect ( 'average_order_value' , 'AVG({{grand_total}})' , 'grand_total' ) -> addFieldToFilter ( 'customer_email' , [ 'in' => $ emails ] ) ; $ columns = $ this -> buildCollectionColumns ( ) ; $ orderCollection -> getSelect ( ) -> columns ( $ columns ) -> group ( 'customer_email' ) ; if ( ! empty ( $ orderStatuses ) ) { $ orderCollection -> getSelect ( ) -> where ( 'status in (?)' , $ orderStatuses ) ; } $ orderArray = [ ] ; foreach ( $ orderCollection as $ item ) { $ orderArray [ $ item -> getCustomerEmail ( ) ] = $ item -> toArray ( [ 'total_spend' , 'number_of_orders' , 'average_order_value' , 'last_order_date' , 'first_order_id' , 'last_order_id' , 'last_increment_id' , 'product_id_for_first_brand' , 'product_id_for_last_brand' , 'week_day' , 'month_day' , 'product_id_for_most_sold_product' ] ) ; } return $ orderArray ; }
Get collection for subscribers by emails.

@param array $emails
@param int $websiteId

@return array
Get collection for subscribers by emails .