Get the date of last purchase of product, by customerMagento - Expected Delivery date on Product PageMagento Customer Grid - Last Order DateProduct last modified date & who modified itCustomer last logged in - Weird Date plus duplicateCustomer grid “last logged in” column not showing online usersHow can we get the date of when product came in stock in Magento 2?show last updated date time field in address magento adminProgramatically get special price products that are active by checking the end date?Magento 2 - Last inserted customerhow to get customer last visited date in magento2?

Why are examinees often not allowed to leave during the start and end of an exam?

My mom helped me cosign a car and now she wants to take it

SQL Server Ignoring Instance name when using port number of different instance

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

Lenovo Legion PXI-E61 Media Test Failure, Check Cable. Exiting PXE ROM. Then restarts and works fine

usage of y" not just for locations?

Advantages of using bra-ket notation

What prevents a US state from colonizing a smaller state?

How do I tell my girlfriend she's been buying me books by the wrong author for the last nine months?

Why doesn't SpaceX land boosters in Africa?

What is the point of using the kunai?

Why should I allow multiple IP addresses on a website for a single session?

Could citing a database like libgen get one into trouble?

Avoiding repetition when using the "snprintf idiom" to write text

Why can't i use !(single pattern) in zsh even after i turn on kshglob?

GFCI versus circuit breaker

Does friction always oppose motion?

Sentences with no verb, but an ablative

Which are more efficient in putting out wildfires: planes or helicopters?

Does the Grothendieck group of finitely generated modules form a commutative ring where the multiplication structure is induced from tensor product?

Did the Shuttle payload bay have illumination?

Cannot overlay, because ListPlot does not draw same X range despite the same PlotRange

What is the meaning of "it" in "as luck would have it"?

2019 2-letters 33-length list



Get the date of last purchase of product, by customer


Magento - Expected Delivery date on Product PageMagento Customer Grid - Last Order DateProduct last modified date & who modified itCustomer last logged in - Weird Date plus duplicateCustomer grid “last logged in” column not showing online usersHow can we get the date of when product came in stock in Magento 2?show last updated date time field in address magento adminProgramatically get special price products that are active by checking the end date?Magento 2 - Last inserted customerhow to get customer last visited date in magento2?













1















How can I get the last date that a customer has purchased a product?



Thank you










share|improve this question


























    1















    How can I get the last date that a customer has purchased a product?



    Thank you










    share|improve this question
























      1












      1








      1








      How can I get the last date that a customer has purchased a product?



      Thank you










      share|improve this question














      How can I get the last date that a customer has purchased a product?



      Thank you







      magento2 product customer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 24 '18 at 9:31









      BawsiBawsi

      988 bronze badges




      988 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use this code to get customer's last order and then any order info:



          use MagentoSalesModelOrderRepository;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilder;
          use MagentoFrameworkApiSortOrderBuilder;

          public function __construct(
          OrderRepository $orderRepository,
          SearchCriteriaBuilder $searchCriteriaBuilder,
          FilterBuilder $filterBuilder,
          SortOrderBuilder $sortOrderBuilder
          )
          $this->orderRepository = $orderRepository;
          $this->searchCriteriaBuilder = $searchCriteriaBuilder;
          $this->filterBuilder = $filterBuilder;
          $this->sortOrderBuilder = $sortOrderBuilder;


          /**
          * @param int $customerId
          * @return OrderSearchResultInterface
          */
          public function getCustomerOrders(int $customerId): OrderSearchResultInterface

          $this->searchCriteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
          $this->searchCriteriaBuilder->addFilter(OrderInterface::STATUS, ['canceled', 'holded'], 'nin');
          $searchCriteria = $this->searchCriteriaBuilder->create();
          $searchCriteria->setSortOrders(
          [
          $this->sortOrderBuilder
          ->setField(OrderInterface::CREATED_AT)
          ->setDirection(SortOrder::SORT_DESC)
          ->create()
          ]
          );
          $searchResults = $this->orderRepository->getList($searchCriteria);

          return $searchResults;


          public function getLastOrder()

          $result = null;
          $searchResults = $this->getCustomerOrders(<customer_id_here>);

          if ($searchResults->getTotalCount() > 0)
          $orders = $searchResults->getList();
          /** @var MagentoSalesModelOrder $lastOrder */
          $lastOrder = reset($orders);
          $result = $lastOrder;

          return $result;






          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243484%2fget-the-date-of-last-purchase-of-product-by-customer%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Use this code to get customer's last order and then any order info:



            use MagentoSalesModelOrderRepository;
            use MagentoFrameworkApiFilterBuilder;
            use MagentoFrameworkApiSearchCriteriaBuilder;
            use MagentoFrameworkApiSortOrderBuilder;

            public function __construct(
            OrderRepository $orderRepository,
            SearchCriteriaBuilder $searchCriteriaBuilder,
            FilterBuilder $filterBuilder,
            SortOrderBuilder $sortOrderBuilder
            )
            $this->orderRepository = $orderRepository;
            $this->searchCriteriaBuilder = $searchCriteriaBuilder;
            $this->filterBuilder = $filterBuilder;
            $this->sortOrderBuilder = $sortOrderBuilder;


            /**
            * @param int $customerId
            * @return OrderSearchResultInterface
            */
            public function getCustomerOrders(int $customerId): OrderSearchResultInterface

            $this->searchCriteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
            $this->searchCriteriaBuilder->addFilter(OrderInterface::STATUS, ['canceled', 'holded'], 'nin');
            $searchCriteria = $this->searchCriteriaBuilder->create();
            $searchCriteria->setSortOrders(
            [
            $this->sortOrderBuilder
            ->setField(OrderInterface::CREATED_AT)
            ->setDirection(SortOrder::SORT_DESC)
            ->create()
            ]
            );
            $searchResults = $this->orderRepository->getList($searchCriteria);

            return $searchResults;


            public function getLastOrder()

            $result = null;
            $searchResults = $this->getCustomerOrders(<customer_id_here>);

            if ($searchResults->getTotalCount() > 0)
            $orders = $searchResults->getList();
            /** @var MagentoSalesModelOrder $lastOrder */
            $lastOrder = reset($orders);
            $result = $lastOrder;

            return $result;






            share|improve this answer



























              0














              Use this code to get customer's last order and then any order info:



              use MagentoSalesModelOrderRepository;
              use MagentoFrameworkApiFilterBuilder;
              use MagentoFrameworkApiSearchCriteriaBuilder;
              use MagentoFrameworkApiSortOrderBuilder;

              public function __construct(
              OrderRepository $orderRepository,
              SearchCriteriaBuilder $searchCriteriaBuilder,
              FilterBuilder $filterBuilder,
              SortOrderBuilder $sortOrderBuilder
              )
              $this->orderRepository = $orderRepository;
              $this->searchCriteriaBuilder = $searchCriteriaBuilder;
              $this->filterBuilder = $filterBuilder;
              $this->sortOrderBuilder = $sortOrderBuilder;


              /**
              * @param int $customerId
              * @return OrderSearchResultInterface
              */
              public function getCustomerOrders(int $customerId): OrderSearchResultInterface

              $this->searchCriteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
              $this->searchCriteriaBuilder->addFilter(OrderInterface::STATUS, ['canceled', 'holded'], 'nin');
              $searchCriteria = $this->searchCriteriaBuilder->create();
              $searchCriteria->setSortOrders(
              [
              $this->sortOrderBuilder
              ->setField(OrderInterface::CREATED_AT)
              ->setDirection(SortOrder::SORT_DESC)
              ->create()
              ]
              );
              $searchResults = $this->orderRepository->getList($searchCriteria);

              return $searchResults;


              public function getLastOrder()

              $result = null;
              $searchResults = $this->getCustomerOrders(<customer_id_here>);

              if ($searchResults->getTotalCount() > 0)
              $orders = $searchResults->getList();
              /** @var MagentoSalesModelOrder $lastOrder */
              $lastOrder = reset($orders);
              $result = $lastOrder;

              return $result;






              share|improve this answer

























                0












                0








                0







                Use this code to get customer's last order and then any order info:



                use MagentoSalesModelOrderRepository;
                use MagentoFrameworkApiFilterBuilder;
                use MagentoFrameworkApiSearchCriteriaBuilder;
                use MagentoFrameworkApiSortOrderBuilder;

                public function __construct(
                OrderRepository $orderRepository,
                SearchCriteriaBuilder $searchCriteriaBuilder,
                FilterBuilder $filterBuilder,
                SortOrderBuilder $sortOrderBuilder
                )
                $this->orderRepository = $orderRepository;
                $this->searchCriteriaBuilder = $searchCriteriaBuilder;
                $this->filterBuilder = $filterBuilder;
                $this->sortOrderBuilder = $sortOrderBuilder;


                /**
                * @param int $customerId
                * @return OrderSearchResultInterface
                */
                public function getCustomerOrders(int $customerId): OrderSearchResultInterface

                $this->searchCriteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
                $this->searchCriteriaBuilder->addFilter(OrderInterface::STATUS, ['canceled', 'holded'], 'nin');
                $searchCriteria = $this->searchCriteriaBuilder->create();
                $searchCriteria->setSortOrders(
                [
                $this->sortOrderBuilder
                ->setField(OrderInterface::CREATED_AT)
                ->setDirection(SortOrder::SORT_DESC)
                ->create()
                ]
                );
                $searchResults = $this->orderRepository->getList($searchCriteria);

                return $searchResults;


                public function getLastOrder()

                $result = null;
                $searchResults = $this->getCustomerOrders(<customer_id_here>);

                if ($searchResults->getTotalCount() > 0)
                $orders = $searchResults->getList();
                /** @var MagentoSalesModelOrder $lastOrder */
                $lastOrder = reset($orders);
                $result = $lastOrder;

                return $result;






                share|improve this answer













                Use this code to get customer's last order and then any order info:



                use MagentoSalesModelOrderRepository;
                use MagentoFrameworkApiFilterBuilder;
                use MagentoFrameworkApiSearchCriteriaBuilder;
                use MagentoFrameworkApiSortOrderBuilder;

                public function __construct(
                OrderRepository $orderRepository,
                SearchCriteriaBuilder $searchCriteriaBuilder,
                FilterBuilder $filterBuilder,
                SortOrderBuilder $sortOrderBuilder
                )
                $this->orderRepository = $orderRepository;
                $this->searchCriteriaBuilder = $searchCriteriaBuilder;
                $this->filterBuilder = $filterBuilder;
                $this->sortOrderBuilder = $sortOrderBuilder;


                /**
                * @param int $customerId
                * @return OrderSearchResultInterface
                */
                public function getCustomerOrders(int $customerId): OrderSearchResultInterface

                $this->searchCriteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
                $this->searchCriteriaBuilder->addFilter(OrderInterface::STATUS, ['canceled', 'holded'], 'nin');
                $searchCriteria = $this->searchCriteriaBuilder->create();
                $searchCriteria->setSortOrders(
                [
                $this->sortOrderBuilder
                ->setField(OrderInterface::CREATED_AT)
                ->setDirection(SortOrder::SORT_DESC)
                ->create()
                ]
                );
                $searchResults = $this->orderRepository->getList($searchCriteria);

                return $searchResults;


                public function getLastOrder()

                $result = null;
                $searchResults = $this->getCustomerOrders(<customer_id_here>);

                if ($searchResults->getTotalCount() > 0)
                $orders = $searchResults->getList();
                /** @var MagentoSalesModelOrder $lastOrder */
                $lastOrder = reset($orders);
                $result = $lastOrder;

                return $result;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 24 at 9:22









                Sergey UskovSergey Uskov

                713 bronze badges




                713 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243484%2fget-the-date-of-last-purchase-of-product-by-customer%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?