Custom Store Provider
Use this feature to customize various aspects of the Storefront module, such as payment processing, adding shipping costs, integration with CRM and more. The system provides StorefrontStandardProvider which implements out-of-the-box features such as reading the store product data from the system's products and collections and does the order processing with supporting merchants such as PayPal Express, Authorize.NET or Stripe.
To customize, you need to create an Active Class which is derived from StorefrontStandardProvider and can override certain functionalities as documented below:
public class MyStorefrontProvider: StorefrontStandardProvider
{
// override the methods that you need.
}
The following is the list of methods that you may want to override depending on what your requirements are:
CreateShoppingCart()
Use this method to populate the shopping cart defaults and details. This method returns a ShoppingCartInfo object that contains the current user's information, including their mailing address, shipping address, and more. This method is used when the storefront is loaded and/or whenever it needs to access the shopping card information.
CalculateOrder(ShoppingCartInfo info, ShoppingCart cart)
Use this method to add shipping costs, adjust taxes, and apply discount codes or other variables to the shopping cart. All such changes will be applied to the ShoppingCartInfo object passed to the method.
ProcessOrder(ShoppingCartInfo info, ShoppingCart cart)
Use this method to perform tasks pre- or post-transaction. This method is called when the user clicks on "Checkout". If the payment is processed, the ShoppingCartInfo.OrderNumber will be populated.
Let's say we want to integrate EasyPost or ShipEngine with Magentrix so that you can calculate shipping costs and populate the information.
public class MyStorefrontProvider: StorefrontStandardProvider
{
public override ShoppingCartInfo CalculateOrder(ShoppingCartInfo info, ShoppingCart cart)
{
var cartInfo = base.CalculateOrder(info, cart);
// Calculate shipping costs (Assumes a class EasyPost has the implementation)
EasyPost.GetShippingCosts(cartInfo);
return cartInfo;
}
}
The following code provides guidelines on how to get storefront order information after an order is processed to save the results into an external system such as a CRM.
public class MyStorefrontProvider: StorefrontStandardProvider
{
public override ShoppingCartInfo ProcessOrder(ShoppingCartInfo info, ShoppingCart cart)
{
var cartInfo = base.ProcessOrder(info, cart);
// Check to see if the order was processed successfully
if (!string.IsNullOrEmpty(cartInfo.OrderNumber))
{
// Using the ShoppingCartInfo, you may create an "Close/Won" Opportunity
var oppId = MyCrmOrderHelper.CreateOpportunity(info);
// Using the cart information, you may create Opportunity line items
MyCrmOrderHelper.CreateOppLineItems(oppId, cart);
}
}
}
ShoppingCartInfo
| Property Name | Property Type | Comments |
|---|
| CCNumber | string | Credit card number |
| CardType | string | Credit card type (Picklist: Visa, Master Card, Amex) |
| City | string | City (required) |
| Comments | string | Additional comments (multiline text) |
| Company | string | Company name |
| Country | string | Country (required, default set to “United States”) |
| DiscountAmount | decimal | Calculated discount amount |
| DiscountCode | string | Discount code |
| DiscountCodeId | string | Identifier for the discount code |
| Email | string | Customer’s email (required, validated as email) |
| ErrorMessage | string | Error message, if applicable |
| ExpMonth | string | Card expiration month (Picklist: “01” to “12”) |
| ExpYear | int? | Card expiration year (nullable) |
| FirstName | string | Customer’s first name (required) |
| LastName | string | Customer’s last name (required) |
| NameOnCard | string | Name as it appears on the card |
| OrderDate | DateTime? | Order date (nullable) |
| OrderNumber | string | Order number |
| PaymentTransactionId | string | Payment transaction ID |
| PaymentType | string | Payment type (default set to “Credit Card”) |
| Phone | string | Customer’s phone number (validated as phone) |
| PostalCode | string | Postal code (required) |
| Shipping | decimal | Shipping cost (currency) |
| ShippingCity | string | Shipping city |
| ShippingCompany | string | Shipping company name |
| ShippingCountry | string | Shipping country |
| ShippingFirstName | string | Shipping first name |
| ShippingLastName | string | Shipping last name |
| ShippingPhone | string | Shipping phone number (validated as phone) |
| ShippingPostalCode | string | Shipping postal code |
| ShippingState | string | Shipping state/province two-letter code (auto-uppercase) |
| ShippingStreet | string | Shipping street address |
| State | string | State/Province two-letter code (required, auto-uppercase) |
| Street | string | Street address (required) |
| Subtotal | decimal | Subtotal amount (currency) |
| Taxes | decimal | Tax rate percentage (numberic value) |
| TaxesAmount | decimal | Calculated tax amount (currency) |
| Title | string | Title |
| Total | decimal | Total amount (currency) |
ShoppingCart
This class has a list of shopping items which are the products that are added to the cart.
| Property Name | Property Type | Comments |
|---|
| HasPhysicalProducts | bool | The cart has physical products that require shipping or not. |
| Items | List<ShoppingCartItem> | List of items added to the shopping cart. |
ShoppingCartItem
| Property Name | Property Type | Comments |
|---|
| Available | bool | Indicates if the item is available |
| Id | string | Identifier |
| Nm | string | Name (of the product) |
| Option | ShoppingProductOption | Associated product option |
| OptId | string | Option identifier |
| Physical | bool | Indicates if the item is physical |
| Product | ShoppingProduct | Associated product (ignored by JSON serialization) |
| Qty | int | Quantity (required, with a numeric constraint) |
| Te | bool | Tax exempt flag |
| Total | decimal | Total cost (currency) |
| Up | decimal | Unit price (currency) |
ShoppingProduct refers to the Storefront Product entity in Magentrix platform.
ShoppingProductOption refers to the Storefront Product Variation which is selected by the user. If the product does not have any variations, this property will be null.