nopSolutions/nopCommerce · error · NopException
Shopping was not initiated by customer
Error message
Shopping was not initiated by customer
What it means
Thrown by PrepareAddToCartEventModelAsync when item.CustomerId does not equal the current customer's Id (from _workContext). The event builder refuses to construct a ConversionsEvent for a cart item that belongs to a different customer, as that would leak cross-customer data into the Facebook Pixel event.
Source
Thrown at src/Plugins/Nop.Plugin.Widgets.FacebookPixel/Services/FacebookPixelService.cs:652
/// <summary>
/// Prepare add to cart event model
/// </summary>
/// <param name="item">Shopping cart item</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the ConversionsEvent model
/// </returns>
protected async Task<ConversionsEvent> PrepareAddToCartEventModelAsync(ShoppingCartItem item)
{
ArgumentNullException.ThrowIfNull(item);
//check whether the shopping was initiated by the customer
var customer = await _workContext.GetCurrentCustomerAsync();
var store = await _storeContext.GetCurrentStoreAsync();
if (item.CustomerId != customer.Id)
throw new NopException("Shopping was not initiated by customer");
var eventName = item.ShoppingCartTypeId == (int)ShoppingCartType.ShoppingCart
? FacebookPixelDefaults.ADD_TO_CART
: FacebookPixelDefaults.ADD_TO_WISHLIST;
var product = await _productService.GetProductByIdAsync(item.ProductId);
var categoryMapping = (await _categoryService.GetProductCategoriesByProductIdAsync(product?.Id ?? 0)).FirstOrDefault();
var categoryName = (await _categoryService.GetCategoryByIdAsync(categoryMapping?.CategoryId ?? 0))?.Name;
var sku = product != null ? await _productService.FormatSkuAsync(product, item.AttributesXml) : string.Empty;
var quantity = product != null ? (int?)item.Quantity : null;
var (productPrice, _, _, _) = await _priceCalculationService.GetFinalPriceAsync(product, customer, store, includeDiscounts: false);
var (price, _) = await _taxService.GetProductPriceAsync(product, productPrice);
var currentCurrency = await _workContext.GetWorkingCurrencyAsync();
var priceValue = await _currencyService.ConvertFromPrimaryStoreCurrencyAsync(price, currentCurrency);
var currency = currentCurrency?.CurrencyCode;
var eventObject = new ConversionsEventCustomData
{View on GitHub (pinned to 64bdf2ff08)
Solutions
- Ensure the work-context customer matches item.CustomerId before calling the event preparer (set the correct customer context in background jobs).
- Skip event emission (don't throw) when the item is not owned by the current customer — logging a warning instead.
- In admin/impersonation flows, explicitly bypass Conversions API event preparation.
Example fix
// before
var customer = await _workContext.GetCurrentCustomerAsync();
if (item.CustomerId != customer.Id)
throw new NopException("Shopping was not initiated by customer");
// after — skip silently for non-owner contexts (admin/background)
var customer = await _workContext.GetCurrentCustomerAsync();
if (item.CustomerId != customer.Id)
{
_logger.Debug($"Skipping AddToCart event: item {item.Id} belongs to customer {item.CustomerId}, not current {customer.Id}");
return null;
} Defensive patterns
Strategy: validation
Validate before calling
var current = await _workContext.GetCurrentCustomerAsync(); if (item.CustomerId != current.Id) return null; // not the owner's session
Type guard
static bool IsCartOwner(ShoppingCartItem item, Customer current) => item.CustomerId == current.Id;
Try / catch
try { await PrepareAddToCartEventModelAsync(item); }
catch (NopException ex) when (ex.Message.Contains("not initiated by customer"))
{ _logger.Debug(ex, "Skipping event for non-owner cart item"); } Prevention
- Set the correct work-context customer in background jobs.
- Skip (don't throw) event preparation for admin/impersonation flows.
- Run conversions events inline in the customer's own session.
When it happens
Trigger: A ShoppingCartItem belonging to customer A is passed while the work context current customer is B. Happens during admin impersonation, background order processing for another customer, or cart-merge edge cases where the current-customer context is stale.
Common situations: Admin placing an order on behalf of a customer; a queued/background job processing cart items without setting the correct work-context customer; a signed-in admin viewing another customer's cart; cart migration between guest and registered accounts where context lags.
Related errors
- Purchase was not initiated by customer
- {error.Code} - {error.Message}{Environment.NewLine}Debug ID:
- No configuration found with the specified id
- This is not your product
- Email is not valid.
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/a94c24764fe47ca0.
Report an issue: GitHub.