Sent Invoice to Vendors

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
imagesport
Ensign (ENS)
Ensign (ENS)
Posts: 1
Joined: Thu Oct 16, 2008 8:54 am

Sent Invoice to Vendors

Post by imagesport » Thu Oct 16, 2008 9:05 am

In your Demo Version I set up 2 vendors and assigned an email to each one. I then created a product for each vendor and assigned the vendor to the product. I placed a product in the cart from each vendor. I was hoping each vendor would get a reciept with only their products on it. Currently both vendors recieve an email with the order however the whole order appears rather then their certian products. Please advise asap how this works.

Glen

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

Re: Sent Invoice to Vendors

Post by mazhar » Thu Oct 16, 2008 12:02 pm

---comments removed---
see a solution in my last post....
Last edited by mazhar on Tue Oct 21, 2008 9:29 am, edited 1 time in total.

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Sent Invoice to Vendors

Post by sohaib » Thu Oct 16, 2008 12:07 pm

When we select a particular email template to be sent on an email event the contents of that email will be sent to all the recipients. There is no way to distinguish who the mail is being sent to so that we could chose to modify its contents depending on the recipient.

One way to handle this would be to change the way mails are currently being generated. We will have to generate a separate email for each vendor.

Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Re: Sent Invoice to Vendors

Post by Odettes » Mon Oct 20, 2008 11:23 am

How do I manually select an emailtemplate and send it to vendors as I could do in Able5.5?

Best regards, Thomas
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

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

Re: Sent Invoice to Vendors

Post by mazhar » Tue Oct 21, 2008 9:46 am

In your Demo Version I set up 2 vendors and assigned an email to each one. I then created a product for each vendor and assigned the vendor to the product. I placed a product in the cart from each vendor. I was hoping each vendor would get a reciept with only their products on it. Currently both vendors recieve an email with the order however the whole order appears rather then their certian products. Please advise asap how this works.

Glen
Well guys here is the solution to send vendor specific notification. For this we have to write a piece of code and create a new Email Template that will be sent to the vendors. In order to use this solution each vendor must have Name and Email address provided.

First of all we need to locate the place from where we want our Email to be triggered and I have selected that i have to trigger the Email when admin ships the orders. Edit the
Website\Admin\Orders\Shipments\ShipOrder.aspx page and locate the following lines of code in it

Code: Select all

//SHIP THE CURRENT SHIPMENT
            _OrderShipment.Ship();
and make it look like

Code: Select all

 //SHIP THE CURRENT SHIPMENT
            _OrderShipment.Ship();
            
            //Vendor Notification Code Start

            foreach (OrderItem orderItem in _Order.Items)
            {
                if (orderItem.OrderItemType == OrderItemType.Product)
                {
                    if (orderItem.Product.Vendor != null)
                    {
                        EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
                        if (emailTemplates.Count > 0)
                        {
                            emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                            emailTemplates[0].Parameters.Add("order", _Order);
                            emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                            emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                            emailTemplates[0].Send();
                        }
                    }
                }
            }
            
            //Vendor Notification Code End
Now to go to Email Templates and create a new Email Template VendorNotificationEx and paste the code below in its contents. Provide some from address and specify vendor keyword in the To Address. Do not attach any trigger with this Email Template and save it
Template Contents

Code: Select all

<html>
<head>
<style type="text/css">
TABLE.Email {
width: 640px;
padding: 5px;
margin: 0px;
border: 1px solid #5872CB;
}
TABLE.Email TH {
font-weight: bold;
font-size: 12px;
color: #ffffff;
font-family: Arial, Verdana, Sans-Serif;
font-style: strong;
background-color: #304FBA;
text-align: center;
text-decoration: none;
padding: 5px;
}
TABLE.Email TD {
font-weight: normal;
font-size: 12px;
color: #000000;
font-family: Arial, Verdana, Sans-Serif;
background-color: #ffffff;
text-align: left;
text-decoration: none;
padding: 3px;
}
</style>
</head>
<body>
<table class="Email">
<tr>
<td valign="top"><strong>$store.Name</strong><br>
<div style="padding-left:30px;">
$store.DefaultWarehouse.FormatAddress(true)
<BR>Phone: $store.DefaultWarehouse.Phone
<BR>Email: $store.DefaultWarehouse.Email
</div>
</td>
<td align="right">
<H1>Packing Slip</H1>
<strong>Order Number</strong>: $order.OrderId<br>
<strong>Order Date</strong>: ${order.OrderDate}</td>
</tr>
</table>
<table class="Email">
#foreach( $shipment in $order.Shipments )
<tr>
<td>
<strong>Ship To:</strong>
<div style="padding-left:30px;">
<p>$shipment.FormatToAddress(true)
<BR>Phone: $shipment.ShipToPhone
<br><strong>Address Type:</strong> 
#if ($shipment.ShipToResidence) Residential #else Commercial #end
#if ($shipment.ShipMessage.Length > 0) <br>
<strong>Message:</strong> $shipment.ShipMessage
#end</p>
</div>
</td>
</tr>
<tr>
<td>
<table width="100%" border="2" align="center">
<tr>
<th class="Email">SKU</th>
<th class="Email">Product Name</th>
<th class="Email">Options</th>
<th class="Email">Quantity</th>
</tr>
<b>Vendor Name: </b>$vendorname
#foreach( $orderItem in $order.Items )

#if($orderItem.Product.Vendor.Name == $vendorname)

#if ($orderItem.OrderShipmentId == $shipment.OrderShipmentId)
<tr>
<td style="text-align: center;">$orderItem.Sku</td>
<td>$orderItem.Name<br><font size=2><strong>$orderItem.LineMessage</strong>
#if ($orderItem.Inputs.Count > 0)
  #foreach( $input in $orderItem.Inputs )
    <strong>$input.Name</strong><strong>:</strong> 
	$input.InputValue
  #end
#end
</font></td>
<td>$orderItem.VariantName</td>
<td style="text-align: center;">$orderItem.Quantity</td>
</tr>
#end

#end

#end
</table>
</td>
</tr>
<tr>
<td style="text-align: center;">
<br>
Thank you for your order.  If you have any questions, please contact
$store.Name<br></td>
</tr>
#end
</table>
</body>
</html>
Now you can test the functionality by first creating an order with items that have some test vendors. When you ship the order each vendor will receive invoice with only its own product item information.

amgym-jt
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 27
Joined: Mon Mar 17, 2008 12:35 pm

Re: Sent Invoice to Vendors

Post by amgym-jt » Mon Mar 02, 2009 9:22 am

[/quote]
First of all we need to locate the place from where we want our Email to be triggered and I have selected that i have to trigger the Email when admin ships the orders. Edit the
Website\Admin\Orders\Shipments\ShipOrder.aspx page and locate the following lines of code in it

Code: Select all

//SHIP THE CURRENT SHIPMENT
            _OrderShipment.Ship();
[/quote]

What if I wanted to trigger the Email to send when the Admin captures payment for the order? Could you please post the code for that? Pretty please!

I need the email to send to the vendor BEFORE we Ship the item. We are "shipping" the item once we get a tracking number back from the vendor and can put this information into Able for the customer to see.

Thank you!

Jay
http://www.American-Gymnast.com/shop

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Mar 02, 2009 9:37 am

Edit your Admin/Orders/Payments/CapturePayment.aspx.cs file and locate the following method

Code: Select all

protected void SubmitCaptureButton_Click(object sender, EventArgs e)
    {
        //GET THE CAPTURE AMOUNT
        LSDecimal captureAmount = AlwaysConvert.ToDecimal(CaptureAmount.Text);
        bool finalCapture = NoAdditionalCapture.Checked;
        if (captureAmount > 0)
        {
            _Payment.Capture(captureAmount, finalCapture, false);
            if (!string.IsNullOrEmpty(CustomerNote.Text))
            {
                OrderNote note = new OrderNote(_Order.OrderId, Token.Instance.UserId, DateTime.UtcNow, CustomerNote.Text, NoteType.Public);
                note.Save();
            }
        }
        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }
and change it as

Code: Select all

protected void SubmitCaptureButton_Click(object sender, EventArgs e)
    {
        //GET THE CAPTURE AMOUNT
        LSDecimal captureAmount = AlwaysConvert.ToDecimal(CaptureAmount.Text);
        bool finalCapture = NoAdditionalCapture.Checked;
        if (captureAmount > 0)
        {
            _Payment.Capture(captureAmount, finalCapture, false);
            if (!string.IsNullOrEmpty(CustomerNote.Text))
            {
                OrderNote note = new OrderNote(_Order.OrderId, Token.Instance.UserId, DateTime.UtcNow, CustomerNote.Text, NoteType.Public);
                note.Save();
            }
        }

        //Vendor Notification Code Start

        foreach (OrderItem orderItem in _Order.Items)
        {
            if (orderItem.OrderItemType == OrderItemType.Product)
            {
                if (orderItem.Product.Vendor != null)
                {
                    EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
                    if (emailTemplates.Count > 0)
                    {
                        emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                        emailTemplates[0].Parameters.Add("order", _Order);
                        emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                        emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                        emailTemplates[0].Send();
                    }
                }
            }
        }

        //Vendor Notification Code End

        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }

amgym-jt
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 27
Joined: Mon Mar 17, 2008 12:35 pm

Re: Sent Invoice to Vendors

Post by amgym-jt » Mon Mar 02, 2009 10:59 am

Thank you for the help, however something broke when I tried that. I uploaded that code to the Admin/Orders/Payments/CapturePayment.aspx.cs file. Then I created a new vendor notification email named "VendorNotificationEx" according to your previous post.

When I tried processing the payment on an order, I now get the following "Compilation Error Message."
error-screenshot.jpg
Any thoughts? Again, thanks so much for your help on this!

Jay

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Mar 02, 2009 11:04 am

Edit the file again and find the following code

Code: Select all

using CommerceBuilder.Users;
and make it look like

Code: Select all

using CommerceBuilder.Users;
using CommerceBuilder.Messaging;

amgym-jt
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 27
Joined: Mon Mar 17, 2008 12:35 pm

Re: Sent Invoice to Vendors

Post by amgym-jt » Mon Mar 02, 2009 11:16 am

mazhar wrote:Edit the file again and find the following code

Code: Select all

using CommerceBuilder.Users;
and make it look like

Code: Select all

using CommerceBuilder.Users;
using CommerceBuilder.Messaging;
Thanks again, but I now get a different error message after trying that:
error2-screenshot.jpg

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Mar 02, 2009 11:22 am

It seems that you over written the Cancel_Button method. so just add following method to the file

Code: Select all

protected void CancelCaptureButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }

amgym-jt
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 27
Joined: Mon Mar 17, 2008 12:35 pm

Re: Sent Invoice to Vendors

Post by amgym-jt » Mon Mar 02, 2009 11:37 am

mazhar wrote:It seems that you over written the Cancel_Button method. so just add following method to the file

Code: Select all

protected void CancelCaptureButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }

I appreciate your patience and work with me on this. I'm not sure where to add this code in the file (I'm not a programmer ... more just a internet marketing guy). Here is my code currently for that file:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Utility;
using CommerceBuilder.Orders;
using CommerceBuilder.Payments;
using CommerceBuilder.Payments.Providers;
using CommerceBuilder.Common;
using CommerceBuilder.Users;
using CommerceBuilder.Messaging;

public partial class Admin_Orders_Payments_CapturePayment : CommerceBuilder.Web.UI.AbleCommerceAdminPage
{
private int _OrderId = 0;
private Order _Order;
private int _PaymentId = 0;
private Payment _Payment;

protected void InitVars()
{
_PaymentId = AlwaysConvert.ToInt(Request.QueryString["PaymentId"]);
_Payment = PaymentDataSource.Load(_PaymentId);
if (_Payment == null) Response.Redirect("../Default.aspx");
_OrderId = _Payment.OrderId;
_Order = _Payment.Order;
}


protected void Page_Load(object sender, EventArgs e)
{
InitVars();
if (!Page.IsPostBack)
{
Caption.Text = string.Format(Caption.Text, (_Order.Payments.IndexOf(_PaymentId) + 1), _Payment.ReferenceNumber);
CurrentPaymentStatus.Text = StringHelper.SpaceName(_Payment.PaymentStatus.ToString()).ToUpperInvariant();
CurrentPaymentStatus.CssClass = CssHelper.GetPaymentStatusCssClass(_Payment.PaymentStatus);
PaymentDate.Text = string.Format("{0:g}", _Payment.PaymentDate);
Amount.Text = string.Format("{0:lc}", _Payment.Amount);
PaymentMethod.Text = _Payment.PaymentMethodName;
LSDecimal orig = _Payment.Transactions.GetTotalAuthorized();
LSDecimal rem = _Payment.Transactions.GetRemainingAuthorized();
LSDecimal bal = _Order.GetBalance(false);
OriginalAuthorization.Text = string.Format("{0:lc}", orig);
RemainingAuthorization.Text = string.Format("{0:lc}", rem);
trRemainingAuthorization.Visible = (orig != rem);
CaptureAmount.Text = string.Format("{0:F2}", bal);
OrderBalance.Text = string.Format("{0:lc}", bal);
trAdditionalCapture.Visible = IsPartialCaptureSupported();
}
AccountDataViewport.PaymentId = _PaymentId;
}

protected bool IsPartialCaptureSupported()
{
Transaction lastAuth = _Payment.Transactions.LastAuthorization;
if (lastAuth != null)
{
PaymentGateway gateway = lastAuth.PaymentGateway;
if (gateway != null)
{
IPaymentProvider instance = gateway.GetInstance();
return ((instance.SupportedTransactions & SupportedTransactions.PartialCapture) == SupportedTransactions.PartialCapture);
}
}
return false;
}

protected void SubmitCaptureButton_Click(object sender, EventArgs e)
{
//GET THE CAPTURE AMOUNT
LSDecimal captureAmount = AlwaysConvert.ToDecimal(CaptureAmount.Text);
bool finalCapture = NoAdditionalCapture.Checked;
if (captureAmount > 0)
{
_Payment.Capture(captureAmount, finalCapture, false);
if (!string.IsNullOrEmpty(CustomerNote.Text))
{
OrderNote note = new OrderNote(_Order.OrderId, Token.Instance.UserId, DateTime.UtcNow, CustomerNote.Text, NoteType.Public);
note.Save();
}
}

//Vendor Notification Code Start

foreach (OrderItem orderItem in _Order.Items)
{
if (orderItem.OrderItemType == OrderItemType.Product)
{
if (orderItem.Product.Vendor != null)
{
EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
if (emailTemplates.Count > 0)
{
emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
emailTemplates[0].Parameters.Add("order", _Order);
emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
emailTemplates[0].Send();
}
}
}
}

//Vendor Notification Code End

Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
}
}

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Mar 02, 2009 11:58 am

Here is the fixed version

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Utility;
using CommerceBuilder.Orders;
using CommerceBuilder.Payments;
using CommerceBuilder.Payments.Providers;
using CommerceBuilder.Common;
using CommerceBuilder.Users;
using CommerceBuilder.Messaging;

public partial class Admin_Orders_Payments_CapturePayment : CommerceBuilder.Web.UI.AbleCommerceAdminPage
{
    private int _OrderId = 0;
    private Order _Order;
    private int _PaymentId = 0;
    private Payment _Payment;

    protected void InitVars()
    {
        _PaymentId = AlwaysConvert.ToInt(Request.QueryString["PaymentId"]);
        _Payment = PaymentDataSource.Load(_PaymentId);
        if (_Payment == null) Response.Redirect("../Default.aspx");
        _OrderId = _Payment.OrderId;
        _Order = _Payment.Order;
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        InitVars();
        if (!Page.IsPostBack)
        {
            Caption.Text = string.Format(Caption.Text, (_Order.Payments.IndexOf(_PaymentId) + 1), _Payment.ReferenceNumber);
            CurrentPaymentStatus.Text = StringHelper.SpaceName(_Payment.PaymentStatus.ToString()).ToUpperInvariant();
            CurrentPaymentStatus.CssClass = CssHelper.GetPaymentStatusCssClass(_Payment.PaymentStatus);
            PaymentDate.Text = string.Format("{0:g}", _Payment.PaymentDate);
            Amount.Text = string.Format("{0:lc}", _Payment.Amount);
            PaymentMethod.Text = _Payment.PaymentMethodName;
            LSDecimal orig = _Payment.Transactions.GetTotalAuthorized();
            LSDecimal rem = _Payment.Transactions.GetRemainingAuthorized();
            LSDecimal bal = _Order.GetBalance(false);
            OriginalAuthorization.Text = string.Format("{0:lc}", orig);
            RemainingAuthorization.Text = string.Format("{0:lc}", rem);
            trRemainingAuthorization.Visible = (orig != rem);
            CaptureAmount.Text = string.Format("{0:F2}", bal);
            OrderBalance.Text = string.Format("{0:lc}", bal);
            trAdditionalCapture.Visible = IsPartialCaptureSupported();
        }
        AccountDataViewport.PaymentId = _PaymentId;
    }

    protected bool IsPartialCaptureSupported()
    {
        Transaction lastAuth = _Payment.Transactions.LastAuthorization;
        if (lastAuth != null)
        {
            PaymentGateway gateway = lastAuth.PaymentGateway;
            if (gateway != null)
            {
                IPaymentProvider instance = gateway.GetInstance();
                return ((instance.SupportedTransactions & SupportedTransactions.PartialCapture) == SupportedTransactions.PartialCapture);
            }
        }
        return false;
    }

    protected void SubmitCaptureButton_Click(object sender, EventArgs e)
    {
        //GET THE CAPTURE AMOUNT
        LSDecimal captureAmount = AlwaysConvert.ToDecimal(CaptureAmount.Text);
        bool finalCapture = NoAdditionalCapture.Checked;
        if (captureAmount > 0)
        {
            _Payment.Capture(captureAmount, finalCapture, false);
            if (!string.IsNullOrEmpty(CustomerNote.Text))
            {
                OrderNote note = new OrderNote(_Order.OrderId, Token.Instance.UserId, DateTime.UtcNow, CustomerNote.Text, NoteType.Public);
                note.Save();
            }
        }

        //Vendor Notification Code Start

        foreach (OrderItem orderItem in _Order.Items)
        {
            if (orderItem.OrderItemType == OrderItemType.Product)
            {
                if (orderItem.Product.Vendor != null)
                {
                    EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
                    if (emailTemplates.Count > 0)
                    {
                        emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                        emailTemplates[0].Parameters.Add("order", _Order);
                        emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                        emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                        emailTemplates[0].Send();
                    }
                }
            }
        }

        //Vendor Notification Code End

        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }
    protected void CancelCaptureButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }
}




amgym-jt
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 27
Joined: Mon Mar 17, 2008 12:35 pm

Re: Sent Invoice to Vendors

Post by amgym-jt » Mon Mar 02, 2009 3:34 pm

Working like a charm now! Thank you for all your help!

Jay

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

Re: Sent Invoice to Vendors

Post by mazhar » Tue Mar 03, 2009 5:09 am

sounds good

ozlighting
Lieutenant (LT)
Lieutenant (LT)
Posts: 53
Joined: Tue Mar 24, 2009 9:49 pm
Contact:

Re: Sent Invoice to Vendors

Post by ozlighting » Tue Apr 07, 2009 5:17 pm

Hi,

is it possible to do this for multiple orders at once. For example, in the "Administration > Orders" screen, is it possible to select multiple orders and then collate all sales items in those orders into one email per Vendor.

Any assistance would be greatly appreciated,

Kind regards,

Lance
Australian Online Lighting Store

log on and light up...

User avatar
Intelliflex
Lieutenant (LT)
Lieutenant (LT)
Posts: 78
Joined: Tue Feb 17, 2004 7:51 pm

Re: Sent Invoice to Vendors

Post by Intelliflex » Wed May 27, 2009 3:21 pm

Mazhar

I assume we can do something similar to send a packing slip to the vendor also? We have developed a site that sells the products for the vendors, we just process it, so getting an order and packing slip to the vendor with just the vendors portion of the order is critical.
Dave

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

Re: Sent Invoice to Vendors

Post by mazhar » Thu May 28, 2009 4:11 am

Yes possible.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Sent Invoice to Vendors

Post by ZLA » Sun May 31, 2009 8:41 pm

mazhar wrote:Edit your Admin/Orders/Payments/CapturePayment.aspx.cs file and locate the following method

Code: Select all

protected void SubmitCaptureButton_Click(object sender, EventArgs e)
    {
        //GET THE CAPTURE AMOUNT
... SNIP ...
    }
and change it as

Code: Select all

protected void SubmitCaptureButton_Click(object sender, EventArgs e)
    {
        //GET THE CAPTURE AMOUNT
... SNIP ...

        //Vendor Notification Code Start

        foreach (OrderItem orderItem in _Order.Items)
        {
            if (orderItem.OrderItemType == OrderItemType.Product)
            {
                if (orderItem.Product.Vendor != null)
                {
                    EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
                    if (emailTemplates.Count > 0)
                    {
                        emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                        emailTemplates[0].Parameters.Add("order", _Order);
                        emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                        emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                        emailTemplates[0].Send();
                    }
                }
            }
        }

        //Vendor Notification Code End

        Response.Redirect("Default.aspx?OrderId=" + _OrderId.ToString());
    }
Thanks Mazhar. Wouldn't this also have to be added to \Admin\Orders\Default.aspx.cs as well as \Admin\Orders\Payments\CapturePayment.aspx.cs so that if you process payments from the default Order Manager page, it also happens? I haven't tested the above code, but it also looks like it sends a notification for each item. So if the order contains 2 items for Vendor A, it will send 2 notifications. Am I missing something?


For my client, I think I need the following process:
  • customer places order
  • gateway set to authorize and capture so order status goes directly to Shipment Pending (I'll have to disable the normal vendor notification email trigger)
  • merchant reviews orders and changes order to a custom order status called Shipment Approved
  • custom vendor notification code must be triggered somehow for this custom status.
For the above process, can you tell me if the following is workable or would you suggest something else?
  • Find all code locations where statuses can be changed to custom order status Shipment Approved and make call to custom vendor notification there.
Thanks.

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Jun 01, 2009 3:32 am

Thanks Mazhar. Wouldn't this also have to be added to \Admin\Orders\Default.aspx.cs as well as \Admin\Orders\Payments\CapturePayment.aspx.cs so that if you process payments from the default Order Manager page, it also happens? I haven't tested the above code, but it also looks like it sends a notification for each item. So if the order contains 2 items for Vendor A, it will send 2 notifications. Am I missing something?
Yes it seems that sample code will send vendor notification for each product within order. We need to make a small change to the code that will first group the vendors available in order and then send one copy of notification to each of them. Update code could be something like

Code: Select all

//Vendor Notification Code Start
        VendorCollection vendors = new VendorCollection();
        foreach (OrderItem orderItem in _Order.Items)
        {
            if (orderItem.OrderItemType == OrderItemType.Product)
                if (orderItem.Product.Vendor != null)
                    vendors.Add(orderItem.Product.Vendor);
            
        }

        foreach (Vendor vendor in vendors)
        {
            EmailTemplateCollection emailTemplates = EmailTemplateDataSource.LoadForCriteria(" Name = 'VendorNotificationEx' ");
            
            if (emailTemplates.Count > 0)
            {
                emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                emailTemplates[0].Parameters.Add("order", _Order);
                emailTemplates[0].Parameters.Add("vendorname", orderItem.Product.Vendor.Name);
                emailTemplates[0].ToAddress = orderItem.Product.Vendor.Email;
                emailTemplates[0].Send();
            }
        }
//Vendor Notification Code End
For my client, I think I need the following process:

* customer places order
* gateway set to authorize and capture so order status goes directly to Shipment Pending (I'll have to disable the normal vendor notification email trigger)
* merchant reviews orders and changes order to a custom order status called Shipment Approved
* custom vendor notification code must be triggered somehow for this custom status.


For the above process, can you tell me if the following is workable or would you suggest something else?

* Find all code locations where statuses can be changed to custom order status Shipment Approved and make call to custom vendor notification there.
Yes above procedure is correct. You need to put Email trigger code against the code changing order status.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Sent Invoice to Vendors

Post by ZLA » Mon Jun 01, 2009 7:48 am

mazhar wrote:
Yes above procedure is correct. You need to put Email trigger code against the code changing order status.
Is there an easy way to search for those code locations? Or can you list where I need to change them? In some cases, I think the order status isn't changed by the code but is changed by commerceBuilder actions. For example, payment.Capture or shipment.Ship.

So far, I think I need to trigger the code from the following locations:
  • Order Summary - Update Selected Orders
  • Order Shipments - Ship Items (if changing quantity)
Have I missed anything? Thanks Mazhar.

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

Re: Sent Invoice to Vendors

Post by mazhar » Mon Jun 01, 2009 10:02 am

Yep you need to automate these locations in order manager.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Sent Invoice to Vendors

Post by ZLA » Tue Jun 02, 2009 12:27 pm

According to another post, there is no way to reissue a normal vendor notification through the system. Am I correct that if I wanted to reissue normal vendor notifications or the above modified multiple vendor notifications, I would have to customize the View Order -> Send Email Functionality?

As a work-around, since our vendor emails are BCC'd to the merchant, they can forward the copy from their email client.

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

Re: Sent Invoice to Vendors

Post by mazhar » Wed Jun 03, 2009 4:18 am

Yes you can manually trigger Emails from Admin -> View Order -> Trigger an Email, so you can update that place as well for your custom Emails or as you stated they can also forward to resend notification copy they received as bcc.

William M
Commander (CMDR)
Commander (CMDR)
Posts: 150
Joined: Sat Feb 14, 2009 9:40 am
Contact:

Re: Sent Invoice to Vendors

Post by William M » Wed Jun 03, 2009 4:39 am

This thread has given me a headache. ...Can't tell the fixes from the repairs.

Sending a vendor ONLY his products from a multi-product order seems like an important - and basic - feature.

Please tell me that 7.0.3 will incorporate this into it.

Post Reply