Model/Sync/Order.php
public function sync()
    {
        $response = ['success' => true, 'message' => 'Done.'];

        // Initialise a return hash containing results of our sync attempt
        $this->searchWebsiteAccounts();

        foreach ($this->accounts as $account) {
            $orders = $account->getOrders();
            $ordersForSingleSync = $account->getOrdersForSingleSync();
            $numOrders = count($orders);
            $numOrdersForSingleSync = count($ordersForSingleSync);
            $website = $account->getWebsites();
            $this->countOrders += $numOrders;
            $this->countOrders += $numOrdersForSingleSync;
            //create bulk
            if ($numOrders) {
                $this->helper->log('--------- Order sync ---------- : ' . $numOrders);
                //queue order into importer
                $this->importerFactory->create()
                    ->registerQueue(
                        \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS,
                        $orders,
                        \Dotdigitalgroup\Email\Model\Importer::MODE_BULK,
                        $website[0]
                    );
            }
            //create single
            if ($numOrdersForSingleSync) {
                $this->createSingleImports($ordersForSingleSync, $website);
            }

            //mark the orders as imported
            $this->orderResource->setImported($this->orderIds);

            unset($this->accounts[$account->getApiUsername()]);
        }

        /**
         * Add guests to contact table.
         */
        if (! empty($this->guests)) {
            $orderEmails = array_keys($this->guests);
            $guestsEmailFound = $this->contactCollectionFactory->create()
                ->addFieldToFilter('email', ['in' => $orderEmails])
                ->getColumnValues('email');
            //remove the contacts that already exists
            foreach ($guestsEmailFound as $email) {
                unset($this->guests[strtolower($email)]);
            }

            //insert new guests contacts
            $this->contactResource->insertGuests($this->guests);
            //mark the existing contacts with is guest in bulk
            $this->contactResource->updateContactsAsGuests($guestsEmailFound);
        }

        if ($this->countOrders) {
            $response['message'] = 'Orders updated ' . $this->countOrders;
        }

        return $response;
    }
public function sync()
    {
        $response = ['success' => true, 'message' => 'Done.'];

        // Initialise a return hash containing results of our sync attempt
        $this->searchWebsiteAccounts();

        foreach ($this->accounts as $account) {
            $orders = $account->getOrders();
            $ordersForSingleSync = $account->getOrdersForSingleSync();
            $numOrders = count($orders);
            $numOrdersForSingleSync = count($ordersForSingleSync);
            $website = $account->getWebsites();
            $this->countOrders += $numOrders;
            $this->countOrders += $numOrdersForSingleSync;
            //create bulk
            if ($numOrders) {
                $this->helper->log('--------- Order sync ---------- : ' . $numOrders);
                //queue order into importer
                $this->importerFactory->create()
                    ->registerQueue(
                        \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS,
                        $orders,
                        \Dotdigitalgroup\Email\Model\Importer::MODE_BULK,
                        $website[0]
                    );
            }
            //create single
            if ($numOrdersForSingleSync) {
                $this->createSingleImports($ordersForSingleSync, $website);
            }

            //mark the orders as imported
            $this->orderResource->setImported($this->orderIds);

            unset($this->accounts[$account->getApiUsername()]);
        }

        /**
         * Add guests to contact table.
         */
        if (! empty($this->guests)) {
            $orderEmails = array_keys($this->guests);
            $guestsEmailFound = $this->contactCollectionFactory->create()
                ->addFieldToFilter('email', ['in' => $orderEmails])
                ->getColumnValues('email');
            //remove the contacts that already exists
            foreach ($guestsEmailFound as $email) {
                unset($this->guests[strtolower($email)]);
            }

            //insert new guests contacts
            $this->contactResource->insertGuests($this->guests);
            //mark the existing contacts with is guest in bulk
            $this->contactResource->updateContactsAsGuests($guestsEmailFound);
        }

        if ($this->countOrders) {
            $response['message'] = 'Orders updated ' . $this->countOrders;
        }

        return $response;
    }
public function sync ( ) { $ response = [ 'success' => true , 'message' => 'Done.' ] ; // Initialise a return hash containing results of our sync attempt $ this -> searchWebsiteAccounts ( ) ; foreach ( $ this -> accounts as $ account ) { $ orders = $ account -> getOrders ( ) ; $ ordersForSingleSync = $ account -> getOrdersForSingleSync ( ) ; $ numOrders = count ( $ orders ) ; $ numOrdersForSingleSync = count ( $ ordersForSingleSync ) ; $ website = $ account -> getWebsites ( ) ; $ this -> countOrders += $ numOrders ; $ this -> countOrders += $ numOrdersForSingleSync ; //create bulk if ( $ numOrders ) { $ this -> helper -> log ( '--------- Order sync ---------- : ' . $ numOrders ) ; //queue order into importer $ this -> importerFactory -> create ( ) -> registerQueue ( \ Dotdigitalgroup \ Email \ Model \ Importer :: IMPORT_TYPE_ORDERS , $ orders , \ Dotdigitalgroup \ Email \ Model \ Importer :: MODE_BULK , $ website [ 0 ] ) ; } //create single if ( $ numOrdersForSingleSync ) { $ this -> createSingleImports ( $ ordersForSingleSync , $ website ) ; } //mark the orders as imported $ this -> orderResource -> setImported ( $ this -> orderIds ) ; unset ( $ this -> accounts [ $ account -> getApiUsername ( ) ] ) ; } /**
         * Add guests to contact table.
         */ if ( ! empty ( $ this -> guests ) ) { $ orderEmails = array_keys ( $ this -> guests ) ; $ guestsEmailFound = $ this -> contactCollectionFactory -> create ( ) -> addFieldToFilter ( 'email' , [ 'in' => $ orderEmails ] ) -> getColumnValues ( 'email' ) ; //remove the contacts that already exists foreach ( $ guestsEmailFound as $ email ) { unset ( $ this -> guests [ strtolower ( $ email ) ] ) ; } //insert new guests contacts $ this -> contactResource -> insertGuests ( $ this -> guests ) ; //mark the existing contacts with is guest in bulk $ this -> contactResource -> updateContactsAsGuests ( $ guestsEmailFound ) ; } if ( $ this -> countOrders ) { $ response [ 'message' ] = 'Orders updated ' . $ this -> countOrders ; } return $ response ; }
Initial sync the transactional data.

@return array

@throws \Magento\Framework\Exception\LocalizedException
Initial sync the transactional data .