public async Task <PickStoreModel> InitializePickStoreModelAsync() { // initialize model for the view PickStoreModel model = new PickStoreModel(); // get the store that the customer selected previously if selected at all CustomerShopMapping currentCustomerShopMapping = _customerShopService.GetCurrentCustomerShopMapping((await _workContext.GetCurrentCustomerAsync()).Id); var shoppingCartItems = await _shoppingCartService.GetShoppingCartAsync(await _workContext.GetCurrentCustomerAsync()); // if selected before, add it to the model, else -1 if (currentCustomerShopMapping != null) { model.SelectedShop = await _shopService.GetShopByIdAsync(currentCustomerShopMapping.ShopId); } model.PickupInStoreText = _pickupInStoreSettings.PickupInStoreText; model.GoogleMapsAPIKey = _storeLocatorSettings.GoogleApiKey; return(model); }
public async Task <IViewComponentResult> InvokeAsync( string widgetZone, object additionalData = null ) { int productId = -1; if (additionalData != null && additionalData is ProductDetailsModel) { productId = (additionalData as ProductDetailsModel).Id; } else if (additionalData != null && additionalData is int) { productId = (int)additionalData; } // clearance store specific var storeUrl = (await _storeContext.GetCurrentStoreAsync()).Url; if (storeUrl.Contains("clearance")) { if (widgetZone == PICKUP_INFO_WIDGET_ZONE) { return(View( "~/Plugins/Widgets.AbcPickupInStore/Views/ClearanceStoreStockContainer.cshtml", productId )); } else { return(Content("")); } } // normal abc store else { Product product = await _productService.GetProductByIdAsync(productId); if (productId > 0) { // if the buy button is disabled, do not show any UI about // products if (product.DisableBuyButton || !product.Published) { return(Content("")); } } PickStoreModel model = await _pickStoreModelFactory.InitializePickStoreModelAsync(); model.ProductId = productId; if (string.IsNullOrWhiteSpace(model.GoogleMapsAPIKey)) { await _logger.WarningAsync( "Google Maps API Key not included in Store Locator " + "settings, will have issues with ABC Pickup in Store"); } // if item is pickup in store, then display the UI for pickup // in store var pams = await _productAttributeService.GetProductAttributeMappingsByProductIdAsync(product.Id); var pamsWithPickup = await pams.WhereAwait( async pam => (await _productAttributeService.GetProductAttributeByIdAsync(pam.ProductAttributeId)).Name == "Pickup" ).ToListAsync(); if (pamsWithPickup.Any()) { string url = ""; if (widgetZone == PICKUP_INFO_WIDGET_ZONE) { url = "~/Plugins/Widgets.AbcPickupInStore/Views/PickupInStoreContainer.cshtml"; } else if (widgetZone == DELIVERY_SELECTION_WIDGET_ZONE) { url = "~/Plugins/Widgets.AbcPickupInStore/Views/SelectDeliveryMethod.cshtml"; } return(View(url, model)); } else { return(Content("")); } } }