hello every one. we have some limitation for our store . we have to sell just 3 products per month for each customer. in the admin page we can set max quantity per card for each customer. its not per month . where and what should i write in then code design to handle this issue. i use nop4.1
Yes we did that in an old version. We added extra fields to product so you can define a Weekly, Monthly and Yearly limit
Essentially you need to look at all the orders for the customer where they purchased the item they are intending to purchase. Then have a limit set somewhere. Either hardcoded in settings if it is the same limit for all products Or alternatively you could use the GenericAttribute feature and create a generic attribute limit for a particular product in this table
Then you need to check the quantity they want to add to the cart with the monthly limit as set above Then display a warning message and not let them purchase the product if it breaches the limit
You need to do this for a number of functions AddtoCart, Reorder, etc so you can add this limit check in a common place. So in the routine
public virtual IList<string> GetRequiredProductWarnings(Customer customer, ShoppingCartType…
You would add the above check
This is some old code fragment that maybe useful
/// <summary> /// Checks the quantity to purchase for a customer is not greater than monthly limit /// </summary> /// /// <remarks> /// Returns true if customer can purchase quantity requested /// </remarks> public static bool GetAllowedToPurchaseMonthlyNumber(Product product, Customer c, int quantity) { int limit = 0;
// Check Monthly Purchases if (product.PurchaseLimitMonthly > 0) // Can also e a setting or GenericAttribute { limit = product.PurchaseLimitMonthly; var dateFrom = DateTime.UtcNow.AddMonths(-1); var dateTo = DateTime.UtcNow;
limit -= // Search all orders for the customer between the dates dateFrom to dateTo // get the Quantity of items purchased in all the orders }
@jigarsangoi, You can add attribute without customization, but you cannot check monthly/weekly purchase limitation using that. Even after customization, it will be difficult (except hard code or extra setting values) to identity which attribute value is used to check the limitations.