如何在我的网站上创建Kentico的新订单?

时间:2016-04-23 19:34:17

标签: kentico

对于Kentico我是新手,我创建了电子商务网站,并希望使用API​​来创建订单。可以任何人告诉我应该使用哪种方法??,也想询问是否有人试图在Sharepoint应用程序上显示kentico网站。

1 个答案:

答案 0 :(得分:2)

创建订单有点复杂,因为您需要获取客户,货币,送货地址,产品和其他可能相关的对象。一个简单的例子可能如下所示:

// Gets the first customer whose last name is 'Smith'
CustomerInfo customer = CustomerInfoProvider.GetCustomers()
                                            .WhereEquals("CustomerLastName", "Smith")
                                            .FirstObject;

// Prepares the order addresses
OrderAddressInfo orderBillingAddress = null;
OrderAddressInfo orderShippingAddress = null;

// Gets the customer's address
AddressInfo customerAddress = AddressInfoProvider.GetAddresses()
                                                    .WhereEquals("AddressCustomerID", customer.CustomerID)
                                                    .FirstObject;

if (customerAddress != null)
{
    // Gets the data from the customer's address
    orderBillingAddress = OrderAddressInfoProvider.CreateOrderAddressInfo(customerAddress);
    orderShippingAddress = OrderAddressInfoProvider.CreateOrderAddressInfo(customerAddress);

    // Sets the order addresses
    OrderAddressInfoProvider.SetAddressInfo(orderBillingAddress);
    OrderAddressInfoProvider.SetAddressInfo(orderShippingAddress);
}

// Gets a status for the order
OrderStatusInfo orderStatus = OrderStatusInfoProvider.GetOrderStatusInfo("NewStatus", SiteContext.CurrentSiteName);

// Gets a currency for the order
CurrencyInfo currency = CurrencyInfoProvider.GetCurrencyInfo("NewCurrency", SiteContext.CurrentSiteName);

if ((customer != null) && (orderStatus != null) && (currency != null) && (orderBillingAddress != null))
{
    // Creates a new order object and sets its properties
    OrderInfo newOrder = new OrderInfo
    {
        OrderInvoiceNumber = "1",
        OrderBillingAddress = orderBillingAddress,
        OrderShippingAddress = orderShippingAddress,
        OrderTotalPrice = 200,
        OrderTotalTax = 30,
        OrderDate = DateTime.Now,
        OrderStatusID = orderStatus.StatusID,
        OrderCustomerID = customer.CustomerID,
        OrderSiteID = SiteContext.CurrentSiteID,
        OrderCurrencyID = currency.CurrencyID
    };

    // Saves the order to the database
    OrderInfoProvider.SetOrderInfo(newOrder);
}

这是从Kentico docs获取的,我真的建议您查看,因为还有更多您可能会觉得有用的示例。

至于你的第二个问题 - 我不太确定你在Sharepoint应用程序中显示Kentico是什么意思。 Kentico是一个独立的ASP Web表单应用程序,需要在IIS上运行,并且本身不能在Sharepoint中嵌入