How to selectively mark as printed based on a certain status

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

How to selectively mark as printed based on a certain status

Post by compunerdy » Wed Oct 28, 2015 4:14 pm

I got the orders to be marked as printed after printing but I have found this can be a issue sometimes. Is there a way to make it so that if the order is not a certain status then it does not get marked as printed. For instance if it is not order status of payment completed then do not mark as printed. The issue I have is sometimes I will reprint a invoice after it has been shipped and this will change the status from completed to packing list printed.

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

Re: Customizations in Gold

Post by mazhar » Thu Oct 29, 2015 12:02 am

compunerdy wrote:I got the orders to be marked as printed after printing but I have found this can be a issue sometimes. Is there a way to make it so that if the order is not a certain status then it does not get marked as printed. For instance if it is not order status of payment completed then do not mark as printed. The issue I have is sometimes I will reprint a invoice after it has been shipped and this will change the status from completed to packing list printed.
Edit Your Admin/Orders/Print/Invoices.aspx.cs file and locate following code

Code: Select all

foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
then update it like

Code: Select all

foreach (Order order in orders)
            {
                if (order.OrderStatus != null && order.OrderStatus.Name != "YOUR PRINT ONLY STATUS NAME")
                    continue;
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
Where you will need replace "YOUR PRINT ONLY STATUS NAME" with order status name allowed for printing

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

Re: Customizations in Gold

Post by jmestep » Thu Oct 29, 2015 12:32 am

Mazhar, what version of Gold/browser are you using to get the above to work? I had to struggle with that also and when I print an invoice in R9 and R10, the Print_Click is never hit as long as the OnClientClick is present.
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: Customizations in Gold

Post by mazhar » Thu Oct 29, 2015 12:49 am

I am using Gold R11 but I haven't tried the code. I just looked at the place where we trigger print event. In above change it will still open the print screen but it wouldn't trigger print event unless order status is of a specific name.

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Customizations in Gold

Post by compunerdy » Sat Oct 31, 2015 1:29 pm

This is not working for me. Here is my code..

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                if (order.OrderStatus != null && order.OrderStatus.Name != "Payment Completed")
                    continue;
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }
I printed a invoice for a order with order status completed and it still was changed to packing list printed.

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Customizations in Gold

Post by nadeem » Fri Nov 06, 2015 2:15 am

This is the issue with firefox browser with printing. When you call print using button OnClientClick event, the OnClick event never got fired. As a result the code inside Print_Click never executed.

To fix this issue, you can put the print function inside Print_Click and remove the OnClientClick from print button.

To do so open Admin/Orders/Print/Invoices.aspx

Locate

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();" OnClick="Print_Click" />
and replace with

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClick="Print_Click" />
Similarly, open Admin/Orders/Print/Invoices.aspx.cs

Locate

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {            
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }
and replace with

Code: Select all

protected void Print_Click(object sender, EventArgs e)
        {
            string scriptKey = "scriptKey";
            if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, "window.print();", true);
            }

            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0))
                return;
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            foreach (Order order in orders)
            {
                EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
            }
        }

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Customizations in Gold

Post by compunerdy » Fri Nov 06, 2015 7:00 am

I am confused here..

The original code to change the order status to "packing list printed" worked just fine for me. The problem was if I tried to reprint a order that was order status "completed" for example it would change the status to "packing list printed" which I did not want it to do. So I asked for code that would only change the status to "packing list printed" if the current order status was "payment completed" which I think Maz tried to give me but it did not work for me. Obviously the order status's I listed may not be standard ones but I am sure you get where I am going. If it matters I am using the Edge browser.

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Customizations in Gold

Post by nadeem » Mon Nov 09, 2015 1:08 am

Original code wasn't working in Firefox browser because the Print_Click event wasn't firing. Now that the main issue is fixed, you can use part of code provided by Mazhar to get your desired results.

At Admin/Orders/Print/Invoices.aspx use the following code

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClick="Print_Click" />

and below code at Admin/Orders/Print/Invoices.aspx.cs

Code: Select all

    protected void Print_Click(object sender, EventArgs e)
            {
                string scriptKey = "scriptKey";
                if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
                {
                     this.Page.ClientScript.RegisterStartupScript(this.GetType(), scriptKey, "window.print();", true);
                }

                IList<int> selectedOrders = GetSelectedOrders();
                if ((selectedOrders == null) || (selectedOrders.Count == 0))
                    return;
                IList<Order> orders = GetOrders(selectedOrders.ToArray());
                foreach (Order order in orders)
                {
                    if (order.OrderStatus != null && order.OrderStatus.Name != "Payment Completed")
                        continue;
                    EventsManager.Instance.RaiseOrderInvoicePrinted(null, new OrderEventArgs(order));
                }
            }

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Customizations in Gold

Post by compunerdy » Tue Nov 10, 2015 6:43 am

This code below is what made it so orders where marked as printed.. using the code you posted above does not mark orders as printed.
mazhar wrote:
When an order is printed the status needs to be updated to Order Printed. It was originally addressed at viewtopic.php?f=42&t=8681, but those modifications do not seem to work with Gold, no matter how many different ways we try them.
Edit your Invoice.ascx.cs file and add following method to it

Code: Select all

protected void MarkPrinted_Click(object sender, EventArgs e)
        {
            IList<int> selectedOrders = GetSelectedOrders();
            if ((selectedOrders == null) || (selectedOrders.Count == 0)) Response.Redirect("~/Admin/Orders/Default.aspx");
            IList<Order> orders = GetOrders(selectedOrders.ToArray());
            OrderStatus orderStatus = OrderStatusDataSource.Load(7);
            foreach (Order order in orders)
                order.UpdateOrderStatus(orderStatus);
        }
Now find the following line of code in Invoices.ascx file

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return false;" />
and make it look like

Code: Select all

<asp:Button ID="Print" runat="server" Text="Print" OnClientClick="window.print();return true;" OnClick="MarkPrinted_Click" />
This change will change the order status with the print button.

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: Customizations in Gold

Post by Katie » Tue Nov 10, 2015 8:54 am

Sorry if I'm jumping into the middle of this conversation, but I didn't know if you had seen that we have new triggers in Gold so you can change the order status automatically upon printing. Three new triggers are available for Order Invoice Printed, Packing List Printed, and Inventory Pull Sheet Printed.
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: How to selectively mark as printed based on a certain status

Post by compunerdy » Wed Nov 11, 2015 7:13 am

Thanks to Katie I setup the built in trigger and then Nadeem's code worked for me.. Thanks!!!

Post Reply