bleroy / Nwazet.Commerce

Idiomatic commerce module for Orchard CMS.
BSD 3-Clause "New" or "Revised" License
26 stars 21 forks source link

CreateOrder Doesn't Fire Event After Created #31

Closed bleroy closed 8 years ago

bleroy commented 10 years ago

Originally reported by: Jeffrey Olmstead (Bitbucket: ems, GitHub: ems)


Without CreateOrder firing an event after the information is loaded into it, it makes it impossible to use a handler for doing stuff after the data is there. Here is my fix (or I welcome another approach):

#!c#
var order = _contentManager.Create("Order", VersionOptions.DraftRequired).As<OrderPart>();
order.Build(creditCardCharge, items, subTotal, total, taxes,
    shippingOption, shippingAddress, billingAddress, customerEmail,
    customerPhone, specialInstructions);
order.Status = status;
order.TrackingUrl = trackingUrl;
order.IsTestOrder = isTestOrder;
order.UserId = userId;

var random = new byte[8];
RngCsp.GetBytes(random);
order.Password = Convert.ToBase64String(random);

_contentManager.Publish(order.ContentItem);

The only important parts / changes are creating it as a draft:

#!c#
var order = _contentManager.Create("Order", VersionOptions.DraftRequired).As<OrderPart>();

Then publishing it once all the data is added:

#!c#
_contentManager.Publish(order.ContentItem);

This allows a handler I have to pick up the OnPublished event for a part that is attached to the Order.


bleroy commented 10 years ago

Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems):


Fixed in pull request #10

bleroy commented 10 years ago

Original comment by Bertrand Le Roy (Bitbucket: bleroy, GitHub: bleroy):


Always better to have an issue open to track things.

bleroy commented 10 years ago

Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems):


Will be able to once I get caught back up to your version and planning to do that in a couple days.

For future knowledge, what is the easiest for you when it is these "small" changes. Is it worth creating an Issue ticket or just throw them in the next pull request I do?

bleroy commented 10 years ago

Original comment by Bertrand Le Roy (Bitbucket: bleroy, GitHub: bleroy):


OK. Can you give me a pull request?