Expand my Community achievements bar.

SOLVED

How can I store and retrieve the custom data in AEM and then show on page?

Avatar

Level 2

Hi All,

I've self learned about AEM 6.0 for a month and did some exercises, but they are mostly related to design/manage/author a page and how to make it look "nice", and I still feeling some obstacles to solve the actual requirement (the training material and video did not introduce the interactions between frontend and backend).

Suppose I've two pages: 1) Product page; 2) MyCart page.

In Product.html, after I select the interested products in Product page and click "go to my cart" link, it should show MyCart.html, and there are all products information (product name, price, etc) that I selected showed on that page.

The problem is, 1) Where and how should I store the product information? 2) How do I retrieve these information when I need?

If the backend is SQL database, I will design a table and write SQL statement to store/retrieve, but in AEM, I really did not know how to start this kind of design (that is, store the product info into a product object and store somewhere, and retrieve them when I need)... the backend is a content repository...

 

I know there are existing components available in AEM (commerce components) but they are too complex to me, here I just would like to try creating such kind of logic myself.

So... can someone give me a few hints, or useful articles for me to read/refer? Thanks a lot.

1 Accepted Solution

Avatar

Correct answer by
Level 10

When a user select product(s) and click on mycart, you can call a service (OSGi bundle). In the bundle you can write logic to fetch the details required to display from the node using Sling API or query builder and add to an object. Then pass that list of object to JSP which can be read and displayed.

You can refer this [1]

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

http://helpx.adobe.com/experience-manager/using/using-sling-apis.html

View solution in original post

6 Replies

Avatar

Level 4

When you click on "go to my cart" call

jQuery.ajax(

                type: "POST",
                url: url, // path: MyCart/jcr:content
                data: {prodectname : prodectnamevalue }, //prodectname and all other info need
                success: function(data) {
                },
                error: function(xhr, textStatus, errorThrown) {
                });

and setTimeout for 2 to 5 seconds to complete the ajax call.

In my cart component:

get the properties using currentPage to get the stored properties

Thanks.

Avatar

Level 10

I would have done this way.

Under <mywebsite>, create 'Products' page which can be used as an index page for all the products

Under this products page. create a page for each product which takes all the details of that particular product. This page also acts as a 'product details page'

Now, when you create this product page, it would have stored in JCR node and have all the details for each product.

Now, in my cart page, based on the selection of a product by the user, get the details of that product from the products node that are created.

 

Hope, I was clear in explaining my thoughts !

 

Regards,

bsloki

Avatar

Level 8

So the response you have gotten so far are technical correct - the approaches do represent how you'd store data in the JCR and read from it, however there are higher level architectural concerns you need to keep in mind when considering designing a solution like this, especially when considering production operational concerns:

  • Synchronization across publish servers - if you have a typical AEM architecture there are at least 2 publish servers in your production environment. Typically traffic is load balanced across each of these and each has it's own copy of the repository. These means that you typically have implement sticky sessions to keep the user coming back to the same publish servers so that the cart data is always accurate. You also have to set up reverse replication for the cart data between publish instances in case there is a fail over between the the two instances. 
  • You need to to build maintenance procedures that will handle purging old and abandoned carts from the repository in order to avoid unsustainable repository growth. 

You can also check out the out of the box shopping cart as a potential example - http://docs.adobe.com/docs/en/aem/6-0/administer/ecommerce.html

Avatar

Level 2

Hi Bsloki,

Thank you for your reply, yes I understand your words but the difficulty of mine is, the actual web page content is stored in the /content/mywebsite/..., how can I write the "SQL" likely or "Property.get()" likely code in the my-cart page component JSP (apps/mysite/component/mycartpage/mycartpage.jsp) so that I can retrieve the desired information from the "/content/mywebsite/..."?

I try to use javax.jcr.* API to directly define an node object but seems alway failed...

Avatar

Correct answer by
Level 10

When a user select product(s) and click on mycart, you can call a service (OSGi bundle). In the bundle you can write logic to fetch the details required to display from the node using Sling API or query builder and add to an object. Then pass that list of object to JSP which can be read and displayed.

You can refer this [1]

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

http://helpx.adobe.com/experience-manager/using/using-sling-apis.html