<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to load cart from database? in CRM and CX Q&amp;A</title>
    <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047674#M402536</link>
    <description>&lt;P&gt;Good point - Thanks!
I dont know why I did it that way but I´ll do the refactoring and update the codesnippet tomorrow.&lt;/P&gt;
&lt;P&gt;In this shop the user is only supposed to have one cart so thats why the ct (0) should be just fine.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 15:14:05 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2018-06-27T15:14:05Z</dc:date>
    <item>
      <title>How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaq-p/12047668</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I´m overriding the DefaultSessionCartService and want to implement the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; // this is custom code -&amp;gt; returns sessionCart if there is one and null if not.
   final CartModel cart = getSessionCartWithoutCreatingOne();
 
         if (null != cart) {
             return cart;
         } else if(/*cart exists in database*/){
             //load cart from database
         }else{
            //create new cart
        }

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I check if the cart is inside the database and how can I load it then?&lt;/P&gt;
&lt;P&gt;Cheers! Raphael&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 10:17:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaq-p/12047668</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-06-26T10:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047669#M402531</link>
      <description>&lt;P&gt;retrieve the cart from database based on the cart id. 
&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 10:26:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047669#M402531</guid>
      <dc:creator>VinayKumarS</dc:creator>
      <dc:date>2018-06-26T10:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047670#M402532</link>
      <description>&lt;P&gt;Wich Classes/methods do I need for that?
&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 10:32:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047670#M402532</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-06-26T10:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047671#M402533</link>
      <description>&lt;P&gt;How do you know with cart to read? Cart code from cookie or from session? You could take a look in CartRestorationFilter how it is done.
&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 10:57:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047671#M402533</guid>
      <dc:creator>Marko_salonen</dc:creator>
      <dc:date>2018-06-26T10:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047672#M402534</link>
      <description>&lt;P&gt;All right.&lt;/P&gt;
&lt;P&gt;if someone is still interrested, here is how I got it done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;    final CartModel cart = getSessionCartWithoutCreatingOne();
         if (null != cart) return cart;
 
         final CustomerModel customer = (CustomerModel) userService.getCurrentUser();
         final BaseSiteModel paramBaseSiteModel = baseSiteService.getCurrentBaseSite();
         List&amp;lt;CartModel&amp;gt; cartsForSiteAndUser = commerceCartService.getCartsForSiteAndUser(paramBaseSiteModel, customer);
 
 return cartsForSiteAndUser.isEmpty() ? cartFactory.createCart() : cartsForSiteAndUser.get(0);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;hope this helps &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:02:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047672#M402534</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-06-27T14:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047673#M402535</link>
      <description>&lt;P&gt;Why would you call userService twice? Why not 
    final CustomerModel currentCustomer = (CustomerModel)userService.getCurrentUser();
And if you look at &lt;STRONG&gt;getCartsForSiteAndUser&lt;/STRONG&gt; method you see it takes a UserModel as argument so &lt;STRONG&gt;getCurrentUser&lt;/STRONG&gt; call is enough&lt;/P&gt;
&lt;P&gt;You should as well have the null check before you start to get the users because you then save some calls to database. And how do you handle if the user wants to have a specifc cart that it has saved? Be aware that for anonymous user this call can be heavy if the cart cleaning job has not been executed.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:17:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047673#M402535</guid>
      <dc:creator>Marko_salonen</dc:creator>
      <dc:date>2018-06-27T14:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047674#M402536</link>
      <description>&lt;P&gt;Good point - Thanks!
I dont know why I did it that way but I´ll do the refactoring and update the codesnippet tomorrow.&lt;/P&gt;
&lt;P&gt;In this shop the user is only supposed to have one cart so thats why the ct (0) should be just fine.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 15:14:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047674#M402536</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-06-27T15:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047675#M402537</link>
      <description>&lt;P&gt;Refactoring is always good :)
&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 15:22:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047675#M402537</guid>
      <dc:creator>Marko_salonen</dc:creator>
      <dc:date>2018-06-27T15:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to load cart from database?</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047676#M402538</link>
      <description>&lt;P&gt;I think you're looking for the method &lt;CODE&gt;hasSessionCart()&lt;/CODE&gt; method&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; if (cartService.hasSessionCart()) {
     return cartService.getSessionCart();
 }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 12:00:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/how-to-load-cart-from-database/qaa-p/12047676#M402538</guid>
      <dc:creator>andyfletcher</dc:creator>
      <dc:date>2018-06-29T12:00:34Z</dc:date>
    </item>
  </channel>
</rss>

