public void AssignImage(ImageRef image, AttributeRef varianterAttr)
        {
            Should(() => Variants.Any(v => v.HasSameTypeVarianterAttribute(varianterAttr)),
                   $"Product does not have any attribute with given attributeId: {varianterAttr.AttributeId}");

            ApplyChange(new ImageAddedToProduct(Id, varianterAttr, image));
        }
        public void Approve()
        {
            Should(() => _contents.Any(), "Product must have at least one content");
            Should(() => Variants.Any(), "Product must have at least one variant");
            Should(() => Variants.SelectMany(v => v.Images).Any(), "Product must have at least one image");

            ApplyChange(new ProductApproved(Id));
        }
Exemple #3
0
        public override string ToString()
        {
            var variants = Variants != null
                ? Variants.Any() ? $" [{Variants}]" : ""
                : "null";

            return($"{Source?.Name.ToStringOrNullLiteral()} => " +
                   $"{_target.ToStringOrNullLiteral()}" +
                   $"{variants}");
        }
        public override string ToString()
        {
            var variants = Variants != null
                ? Variants.Any() ? $" [{Variants}]" : ""
                : "null";

            var implicitVariants = _implicitVariants != null
                ? _implicitVariants.Any() ? $" ({_implicitVariants})" : ""
                : "null";

            return($"{Source?.Name.ToStringOrNullLiteral()} => " +
                   $"{Target?.Name.ToStringOrNullLiteral()}" +
                   $"{variants}{implicitVariants}");
        }
        public ActionParameterAttribute(string name, params string[] variants)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. Must provive parameter name");
            }
            if (name.Any(_ => !char.IsLetterOrDigit(_)))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. Parameter name must only contain letters and digits");
            }
            if (!char.IsLetter(name.Trim()[0]))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. Parameter name must start with letter");
            }

            PropertyName = name;
            Variants     = variants;
            if (!Variants.Any())
            {
                Variants = new[] { $"-{PropertyName[0]}", $"--{PropertyName}" }
            }
            ;

            if (Variants.Any(v => !v.StartsWith("-")))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. Parameter variant must start with -");
            }
            //TODO - nicer condition
            if (Variants.Any(v => v.StartsWith("-") && v.Length > 1 && v[1] != '-' && v.Length != 2))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. If parameter starts with -, it must be a single letter");
            }
            if (Variants.Any(v => v.StartsWith("--") && v.Length <= 3))
            {
                throw new ArgumentOutOfRangeException($"Error processing '{name}' Action Parameter. Parameter variant must start with -- must be more than one letter");
            }

            Type = typeof(string);
        }
    /// <summary>
    /// Loads product options.
    /// </summary>
    private void LoadProductOptions()
    {
        DataSet dsCategories = null;

        if (IsLiveSite)
        {
            // Get cache minutes
            int cacheMinutes = SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSCacheMinutes");

            // Try to get data from cache
            using (var cs = new CachedSection <DataSet>(ref dsCategories, cacheMinutes, true, null, "skuoptioncategories", SKUID))
            {
                if (cs.LoadData)
                {
                    // Get all option categories for SKU
                    dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false);

                    // Save to the cache
                    if (cs.Cached)
                    {
                        // Get dependencies
                        var dependencies = new List <string>
                        {
                            "ecommerce.sku|byid|" + SKUID,
                            "ecommerce.optioncategory|all"
                        };

                        // Set dependencies
                        cs.CacheDependency = CacheHelper.GetCacheDependency(dependencies);
                    }

                    cs.Data = dsCategories;
                }
            }
        }
        else
        {
            // Get all option categories for SKU
            dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false);
        }

        // Initialize product option selectors
        if (!DataHelper.DataSourceIsEmpty(dsCategories))
        {
            mProductOptions = new Hashtable();

            // Is only one option category available for variants?
            var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null;
            mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1;

            foreach (DataRow dr in dsCategories.Tables[0].Rows)
            {
                try
                {
                    // Load control for selection product options
                    ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx");

                    // Add control to the collection
                    var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0);
                    selector.ID = "opt" + categoryID;

                    // Init selector
                    selector.LocalShoppingCartObj = ShoppingCart;
                    selector.IsLiveSite           = IsLiveSite;
                    selector.CssClassFade         = CssClassFade;
                    selector.CssClassNormal       = CssClassNormal;
                    selector.SKUID          = SKUID;
                    selector.OptionCategory = new OptionCategoryInfo(dr);

                    // If one category is used, fix the one selector with options to use only options which are not in disabled variants
                    if (mOneCategoryUsed && variantCategories.Contains(categoryID))
                    {
                        var disabled = from variant in Variants
                                       where !variant.Variant.SKUEnabled
                                       from productAttributes in variant.ProductAttributes
                                       select productAttributes.SKUID;

                        var disabledList = disabled.ToList();

                        selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null;
                    }

                    // Load all product options
                    foreach (DictionaryEntry entry in selector.ProductOptions)
                    {
                        mProductOptions[entry.Key] = entry.Value;
                    }

                    var lc = selector.SelectionControl as ListControl;
                    if (lc != null)
                    {
                        // Add Index change handler
                        lc.AutoPostBack = true;
                    }

                    pnlSelectors.Controls.Add(selector);
                }
                catch
                {
                }
            }
        }
    }
Exemple #7
0
        /// <summary>
        /// Initialization method
        /// </summary>
        /// <param name="progress">Progress value of the initialization</param>
        /// <returns>Task</returns>
        public Task Initialize(IProgress <float> progress)
        {
            if (IsInitialized)
            {
                progress.Report(1.0f);
                return(Task.CompletedTask);
            }
            inputManager = ScenarioManager.Instance.GetExtension <InputManager>();

            //Load referenced controllables
            foreach (var controllablePrefab in controllablesPrefabs)
            {
                if (controllablePrefab == null)
                {
                    continue;
                }
                var controllable = controllablePrefab.GetComponent <IControllable>();
                if (controllable == null)
                {
                    continue;
                }
                var variant = new ControllableVariant();
                controllable.Spawned = true;
                variant.Setup(controllable.GetType().Name, controllable);
                Variants.Add(variant);
            }
            foreach (var editPanelsPrefab in customEditPanelsPrefabs)
            {
                if (editPanelsPrefab == null)
                {
                    continue;
                }
                var editPanel = editPanelsPrefab.GetComponent <IControllableEditPanel>();
                if (editPanel == null)
                {
                    continue;
                }
                editPanel = Instantiate(editPanelsPrefab, transform).GetComponent <IControllableEditPanel>();
                editPanel.PanelObject.SetActive(false);
                CustomEditPanels.Add(editPanel);
            }

            //Import controllables from config
            var controllables      = Config.Controllables;
            var controllablesCount = controllables.Count;
            var i = 0;

            foreach (var controllable in controllables)
            {
                if (Variants.Any(v => ((ControllableVariant)v).controllable.GetType() == controllable.GetType()))
                {
                    continue;
                }
                var variant = new ControllableVariant();
                Debug.Log($"Loading controllable {controllable.Key} from the config.");
                controllable.Value.Spawned = true;
                variant.Setup(controllable.Key, controllable.Value);
                Variants.Add(variant);
                var assets = Config.ControllableAssets[controllable.Value];
                foreach (var asset in assets)
                {
                    var editPanel = asset.GetComponent <IControllableEditPanel>();
                    //Add edit panel if same type is not registered yet
                    if (editPanel != null && customEditPanelsPrefabs.Any(panel => panel.GetType() == editPanel.GetType()))
                    {
                        CustomEditPanels.Add(editPanel);
                    }
                }
                progress.Report((float)++i / controllablesCount);
            }

            //Let all the custom edit panels edit initialized controllable variants
            foreach (var variant in Variants)
            {
                var controllableVariant = variant as ControllableVariant;
                if (controllableVariant == null)
                {
                    continue;
                }
                foreach (var customEditPanel in CustomEditPanels)
                {
                    if (customEditPanel.EditedType == controllableVariant.controllable.GetType())
                    {
                        customEditPanel.InitializeVariant(controllableVariant);
                    }
                }
            }

            IsInitialized = true;
            return(Task.CompletedTask);
        }
    /// <summary>
    /// Loads product options.
    /// </summary>
    private void LoadProductOptions()
    {
        // Get all option categories for SKU
        DataSet dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false);

        // Initialize product option selectors
        if (!DataHelper.DataSourceIsEmpty(dsCategories))
        {
            mProductOptions = new Hashtable();

            // Is only one option category available for variants?
            var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null;
            mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1;

            foreach (DataRow dr in dsCategories.Tables[0].Rows)
            {
                try
                {
                    // Load control for selection product options
                    ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx");

                    // Add control to the collection
                    var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0);
                    selector.ID = "opt" + categoryID;

                    // Init selector
                    selector.LocalShoppingCartObj = ShoppingCart;
                    selector.IsLiveSite           = false;
                    selector.CssClassFade         = "text-muted";
                    selector.CssClassNormal       = "normal";
                    selector.SKUID          = SKUID;
                    selector.OptionCategory = new OptionCategoryInfo(dr);

                    // If one category is used, fix the one selector with options to use only options which are not in disabled variants
                    if (mOneCategoryUsed && variantCategories.Contains(categoryID))
                    {
                        var disabled = from variant in Variants
                                       where !variant.Variant.SKUEnabled
                                       from productAttributes in variant.ProductAttributes
                                       select productAttributes.SKUID;

                        var disabledList = disabled.ToList();

                        selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null;
                    }

                    // Load all product options
                    foreach (DictionaryEntry entry in selector.ProductOptions)
                    {
                        mProductOptions[entry.Key] = entry.Value;
                    }

                    var lc = selector.SelectionControl as ListControl;
                    if (lc != null)
                    {
                        // Add Index change handler
                        lc.AutoPostBack = true;
                    }

                    pnlSelectors.Controls.Add(selector);
                }
                catch
                {
                }
            }
        }
    }
Exemple #9
0
 public bool Any()
 {
     return(Variants?.Any() ?? false);
 }