0

I have task to get the repository item("its like shipping group and payment group details") for the particular order id you now i got all the repository item in one object..

But the thing is i don't know how to fetch the these repository item (shipping group and payment group ) from this object

This my code I have tried..

 Repository connection;
 connection=/atg/commerce/order/OrderRepository-->this i putted in my property file 
 Repository repository = (Repository)getConnection();
 RepositoryItem Item = (RepositoryItem)   
 Repository.getItem(getOrderId());

In this "repositoryItem" object I have all the repository item so I have to fetch all the shipping group and payment group from this object..

Pls hep me out..

Thanks in Advance..

Mani
  • 1
  • 1
  • 8
  • Welcome to SO. Your snippet above can't be your real code. Variable names can't be the same as Class names and you have your property file definitions in the middle of your code. You'll get better help with better examples. – radimpe Jun 05 '14 at 05:10
  • @radimpe ok generally tell me how to get repositoryitem from that object like shipping group and payment group... – Mani Jun 05 '14 at 05:24
  • hi @radimpe now i got all repository item for particular order id and one more task is i have to set these repository item to new order i tried but i am getting some cast exception pls help me out from this is issue...Thanks in advance – Mani Jun 06 '14 at 13:36

2 Answers2

0

For Orders there are two ways to get to the ShippingGroup and PaymentGroup when your starting point is an orderId

Let's start with the Repository way:

RepositoryItem order = getConnection().getItem(getOrderId(), "order"); //The getConnection().getItem(getOrderId()) method is deprecated. Make sure you pass the itemDescriptor in with your query
List<RepositoryItem> shippingGroups = (List<RepositoryItem>) order.getPropertyValue("shippingGroups");
List<RepositoryItem> paymentGroups = (List<RepositoryItem>) order.getPropertyValue("paymentGroups");

However, for certain objects, ATG provide some helper methods to make things easier. So using the out-of-the-box OrderManager, code is likely to make things easier for you:

Order order = getOrderManager().loadOrder(getOrderId());
List<ShippingGroup> shippingGroups = order.getShippingGroups();
List<PaymentGroup> paymentGroups = order.getPaymentGroups();

You will now have easier access to most things in the shipping groups and payment groups. Keep in mind though that your repository customisations will not automatically be exposed in these and you'll have to extend the Order and OrderImpl classes to do so (and similarly for the ShippingGroup and PaymentGroup.

radimpe
  • 3,197
  • 2
  • 27
  • 46
  • @Mani No Problem. Remember to accept answers to your questions that solves your query. It helps other people with the same/similar question to get to the correct solution quicker. – radimpe Jun 05 '14 at 09:24
  • hi @radimpe now i got all repository item for particular order id and one more task is i have to set these repository item to new order i tried but i am getting some cast exception pls help me out from this is issue...Thanks in advance – Mani Jun 06 '14 at 13:36
  • Mani please accept the answer if it solved your original question, it is the least you can do to the people who helped you by spending their time. And as @radimpe mentioned, it helps the community as well. The more questions you leave like this, less answers you will get in future. – Buddha Oct 12 '14 at 02:14
0

ATG represents orders at two different levels - as repository items (and hence in the database) and as order objects.

It is strongly recommended that you interact with an order at object level, not repository level.

The OrderManager component provides the API you need to load an order by id.

Order order = orderManager.loadOrder(orderId);

where orderManager is the variable that holds a reference to the /atg/commerce/order/OrderManager Nucleus component.

This API hides behind it all the code needed to load the order and its related data entities from the repository.

Vihung
  • 12,947
  • 16
  • 64
  • 90