-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariantListBeforeRender.cs
More file actions
58 lines (56 loc) · 2.87 KB
/
VariantListBeforeRender.cs
File metadata and controls
58 lines (56 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Extensions;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products;
using Dynamicweb.Ecommerce.Products;
using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Security.UserManagement;
namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.NotificationSubscribers
{
[Subscribe(Ecommerce.Notifications.Ecommerce.VariantList.BeforeRender)]
public class VariantListBeforeRender : NotificationSubscriberBase
{
public override void OnNotify(string notification, NotificationArgs args)
{
if (args is Ecommerce.Notifications.Ecommerce.VariantList.BeforeRenderArgs beforeRenderArgs)
{
var variantCombinationProducts = beforeRenderArgs.VariantCombinationsProducts;
if (variantCombinationProducts != null) {
var settings = SettingsManager.GetSettingsByShop(Global.CurrentShopId);
if (settings != null &&
settings.AddProductFieldsToRequest &&
settings.GetProductInformationForAllVariants &&
CanCheckPrice(settings))
{
var user = UserContext.Current.User;
foreach (var vcp in variantCombinationProducts)
{
var variantProduct = vcp.Value;
if (variantProduct == null)
continue;
var productInfo = ProductManager.GetProductInfo(variantProduct, settings, user);
if (productInfo != null)
{
if (variantProduct.ProductFieldValues == null)
{
ProductService service = new ProductService();
service.SetDefaultProductFields(variantProduct);
}
if (variantProduct.ProductFieldValues != null)
{
ProductManager.FillProductFieldValues(variantProduct, productInfo);
}
}
}
}
}
}
}
private static bool CanCheckPrice(Settings settings)
{
return EnabledAndActive(settings, SubmitType.Live) && settings.EnableLivePrices &&
(settings.LiveProductInfoForAnonymousUsers || Helpers.GetCurrentExtranetUser() != null) &&
(Helpers.GetCurrentExtranetUser() == null || !Helpers.GetCurrentExtranetUser().IsLiveIntegrationPricesDisabled()) &&
!Global.IsProductLazyLoad(settings);
}
}
}