It might be quite frustrating for shoppers to browse through a catalog, get an idea of the prices, and then at the checkout discover a significant price increase. This may stop many people from completing their orders. If in your store prices differentiate by region, a good idea might be to display correct prices already in the catalog. A plugin can helpful for this. See below our experience of developing such a plugin.
Challenge
A company provides delivery to different cities within one country. Once on the site, a user can select his/her city. The requirement was to group cities into regions by price, make a system that would define delivery prices depending on those regions and to show the correct prices in real-time as well as place an order with the correct price based on the delivery address.
Solution
To fulfill the task, a plugin was developed. This plugin is using the following nopCommerce customization mechanisms:
- Custom entities development
- Action filter implementation
- Events interception through IConsumer implementation
An existing city selection plugin on the site stored certain values in the GenericAttribute of the Customer entity. Based on this data, a new plugin would define a region and corresponding prices in a catalog and a cart.
New entities development
Using the data access plugin plugin development pattern, we implemented entities for storing connections between cities and ‘price’ regions, as well as for storing connections, currencies and prices between regions and products.
The service for these entities provided CRUD operations on entities, as well as pricing based on the selected city and order value based on the delivery address.
Overriding prices in catalog and cart
To display correct prices on catalog and cart pages, action filter was implemented. It overrides prices in view models based on the city chosen by a user and stored in GenericAttribute of the Customer entity.
Overriding prices when placing an order
To intercept the event of placing an order, IConsumer was implemented. It recalculates the order value taking into account a city of the delivery.
Implementation of the interface for entering prices by region in the admin panel
On the Configure view of the plugin configuration page, the UI for entering price regions and matching cities was implemented. On the product editing page, we added a tab to enter prices at the regional level using IConsumer, which intercepts the AdminTabStripCreated event.
Have questions regarding your projects? Contact us for a free consultation.