Inhalte aufrufen

Profilbild

Cart Item to Order Item


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
9 Antworten zu diesem Thema

#1 CompleteCoders

CompleteCoders

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 103 Beiträge

Geschrieben: 27 November 2017 - 04:47

I need to keep track of some extra information as a user adds an item to the cart.  I need that information also to be kept after the item is orders.  I could use SyncMap to keep track of it as it is added to the cart, but what would I do after it is orders?  I need to store it on a new EntityID I believe.  Is there a way I can catch this is happening and copy of the data?

 

Is there a better way to do this?

 

Thanks!

 

 



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 27 November 2017 - 11:20

Generally speaking, I would separate that. Shopping cart data are short-lived, volatile data. Orders are the opposite. 
 
Can you throw away the shopping cart extra information if it does not come to an order or do you have to save it in any case?

Marcus Gesing

Smartstore AG


#3 CompleteCoders

CompleteCoders

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 103 Beiträge

Geschrieben: 28 November 2017 - 02:47

If the shopping cart item does not become an order, I don't care about the data anymore.  But if the cart item becomes an order, I need the information saved with the order.

 

I understand the difference between orders being permanent and cart data is shorted lived.  I just need a way to move the SyncMap data over to the order when the order is created.  



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 28 November 2017 - 13:24

Then I would store the shopping cart data in a session object and, in case of an order, save it together with the order data.
You can use CheckoutState.CustomProperties for your session object if the scope meets your requirements (ends with ConfirmOrder) or create an own session object. See also GetCheckoutState extension method.
 
You can use the GenericAttribute entity to store the order data. The order edit page has a tab where this data can be viewed. I would create one object per order and store all data Json formatted into GenericAttribute.Value. Of course you can use SyncMapping for this too.

Marcus Gesing

Smartstore AG


#5 CompleteCoders

CompleteCoders

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 103 Beiträge

Geschrieben: 28 November 2017 - 19:39

Thanks for the reply. The only concern I would lose the data I would loose the data. 

 

This is what I am thinking of doing so far. I want to save a SyncMapping for the ShoppingCartItem when we add it to the cart. What is the best way to intercept the process of creating an order? How do I copy the SyncMapping over to the Order or move it into the Gerneric Attributes or another SyncMapping value attached to the order.

 

I assume I want to intercept that process as well as do some manipulation when that event occurs.



#6 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 28 November 2017 - 21:59

"What is the best way to intercept the process of creating an order?"
The OrderPlacedEvent. See Clickatell event consumer as an example.
 
"How do I copy the SyncMapping over to the Order or move it into the Generic Attributes or another SyncMapping value attached to the order."
SyncMapping by using SyncMappingService and GenericAttribute by using GenericAttributeService. But these Services have no copy methods. You have to do this yourself (insert a new record and delete the old one).

Marcus Gesing

Smartstore AG


#7 CompleteCoders

CompleteCoders

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 103 Beiträge

Geschrieben: 29 November 2017 - 04:00

Thanks!  I think I have a solution now.  Any insight as to how WishList items work and is there a WishListEvent I can hook into?



#8 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 29 November 2017 - 13:31

Wishlist items are very similar to shopping cart items. Both share the same entity "ShoppingCartItem" distinguished by ShoppingCartItem.ShoppingCartTypeId. For possible values see ShoppingCartType. Therefore both are processed via ShoppingCartService.
 
There is no wishlist event. Only a MigrateShoppingCartEvent fired when cart and wishlist items are copied from a guest to logged-in customer. You can use hooks to track changes of shopping cart items.

Marcus Gesing

Smartstore AG


#9 CompleteCoders

CompleteCoders

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 103 Beiträge

Geschrieben: 30 November 2017 - 18:50

When a user migrates from Guest to Logged-in does their shopping cart item get remapped?  

 

 

Also, if I understand what you are saying correctly, I don't need to care if an item is in wishlist or in shopping cart because it is the same shoppingcartitem just a flag flipped on it.  So if I link SyncMapping to the shopping cart item nothing will change for me when it move between the two states.



#10 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 30 November 2017 - 21:48

"When a user migrates from Guest to Logged-in does their shopping cart item get remapped?"
Yes, they are copied.
 
"I don't need to care if an item is in wishlist or in shopping cart because it is the same shoppingcartitem just a flag flipped on it."
No. Two entities are created, one for the wishlist and one for the shopping cart.

Marcus Gesing

Smartstore AG