Specialized Add Webpage page- how to access webpageId

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Specialized Add Webpage page- how to access webpageId

Post by jmestep » Fri Jan 16, 2009 4:18 pm

I'm building a special AddWebpage page in the admin because we want to add fields to another table at the same time that the webpage is created. I had the code on a separate page like the ProductTemplates, etc are in the Product edit page left menu. The client would like to have the normal webpage fields and their special fields combined into one page. I need to be able to capture the webpage id for the new page when the webpage original data and the supplemental data is saved. Is there a method that can tell me what the new webpage Id will be? That needs to be the foreign key in the supplemental table. I might need to do a response redirect back to the Add page? If so, how can I pick up the webpage id? Here is what I'm thinking I might have to do on the same page code:
Input fields for all the normal webpage data and the supplemental data.
On finish, save the normal webpage data
Redirect back to the same page with the newly created webpage id
Save the supplemental data.
Back to category listing as normal.

Thanks
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by mazhar » Sat Jan 17, 2009 1:57 am

The newly created webpage id is placed in the object after save call. so you can get the id as below

Code: Select all

Webpage webpage = new Webpage();
webpage.Save();
int id = webpage.WebpageId;

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by jmestep » Sat Jan 17, 2009 7:46 am

Thank you! I thought I was going to have to spend hours today digging to find that out. Is that how the OrderId can be retrieved from the OnePageCheckout?
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Specialized Add Webpage page- how to access webpageId

Post by AbleMods » Sat Jan 17, 2009 2:14 pm

jmestep wrote:Thank you! I thought I was going to have to spend hours today digging to find that out. Is that how the OrderId can be retrieved from the OnePageCheckout?
Yes, although it's a little confusing at first WHERE to find the OrderId.

OnePageCheckout primarily ensures shipping methods and address-related information is properly obtained. The actual "checkout" step is performed within the individual payment methods. You can find each of these listed at the top of the OnePageCheckout as included user controls.

For example's sake, let's look at the CreditCardPaymentForm user control. Here is the actual checkout code:

Code: Select all

if (checkOut)
            {
                //PROCESS A CHECKOUT
                CheckoutRequest checkoutRequest = new CheckoutRequest(payment);
                CheckoutResponse checkoutResponse = Token.Instance.User.Basket.Checkout(checkoutRequest);
                if (checkoutResponse.Success)
                {
                    if (CheckedOut != null) CheckedOut(this, new CheckedOutEventArgs(checkoutResponse.OrderId));
                    Response.Redirect(NavigationHelper.GetReceiptUrl(checkoutResponse.OrderId));
                }
                else
                {
                    List<string> warningMessages = checkoutResponse.WarningMessages;
                    warningMessages.Insert(0, "The order could not be completed because the basket contents changed during checkout.  Please review your basket contents and try again.");
                }
            }
Notice how the checkout is initiated via the basket instance, not the payment.

Once the checkout is confirmed, an OrderId value is then obtainable from the checkoutResponse object.

Code: Select all

(checkoutResponse.OrderId)
Only at THIS POINT is the order guaranteed to be stored.

So, it is only a half-truth that the Order object is available during OnePageCheckout. It is available, however only within a separate user control that immediately redirects to the receipt page upon successful checkout and creation of the order itself.

That's why I've always felt that post-checkout order manipulation is better left to the receipt page. 1) you don't risk blowing up your checkout process and 2) logically it fits better in your head since ReceiptPage cannot be reached until the order is created.

Just be careful in ReceiptPage - if you want to modify the order, be absolutely sure you do it BEFORE:

Code: Select all

BindOrder();
located in the Page_Init() event.

ReceiptPage is poorly designed as it modifies some of the dollar values within the order object AFTER the order is loaded into memory. If you're not aware of it, and you save your changes to the order object after BindOrder();, you'll corrupt the order. Trust me on that one.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by jmestep » Sat Jan 17, 2009 3:24 pm

OK, that makes more sense on the OrderId. I hadn't dug into the code, but I knew mazhar had said it was available on the one page checkout and I couldn't figure out how that would be so since the customer could stop and not finish a payment and I new the orderids were in sequence.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by mazhar » Mon Jan 19, 2009 9:41 am

In onepagecheckout page the order id is available when order is placed in checkedout event handler is called. You can put your custom code in the CheckedOut function or register you custom handler for CheckedOut event as well.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by jmestep » Mon Jan 19, 2009 12:00 pm

OK, phase two (three, four, whatever) of my original question. I've got everything working fine as far as saving the custom data related to the webpage into the new tables and have it all deleting fine.
Now I need to code a copy of the data when the webpage is copied in the admin catalog browse page.
case "Do_Copy":
CatalogDataSource.Copy(catalogNodeId, catalogNodeType, CurrentCategoryId);

I've put in an if (catalogNodeType == CatalogNodeType.Webpage) before that to load the supplemental object for the webpageid (catalogNodeId).
How can I pick up the new webpageId that is generated?
Here's the snippet from the source code:
/// <summary>
/// Creates a copy of the specified Webpage
/// </summary>
/// <param name="webpageId">Id of the Webpage to create copy of</param>
/// <returns>The copy object</returns>
public static Webpage Copy(int webpageId)
{
Webpage copy = WebpageDataSource.Load(webpageId, false);
if (copy != null)
{
copy.WebpageId = 0;
return copy;
}
return null;
}
Thanks.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: Specialized Add Webpage page- how to access webpageId

Post by heinscott » Mon Jan 19, 2009 12:41 pm

Judy, not sure if this is what you're looking for, but, this should give you a webpage object of the one created with the copy... Just use this line in place of the current copy.

Webpage newWP = WebpageDataSource.Load(CatalogDataSource.Copy(catalogNodeId, catalogNodeType, CurrentCategoryId));

the newWP object should be able to provide you with anything else you might need. Of course, no need to create a webpage if all you need is the id. The copy method already returns an int of the newly created object.

int theId = CatalogDataSouce.Copy...etc, etc.

Hope this helps.

Scott.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Specialized Add Webpage page- how to access webpageId

Post by jmestep » Mon Jan 19, 2009 1:49 pm

I think this will do it.
Thanks, Scott.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply