protected async virtual Task <string> GetVariantInventoryStatus(ItemVariationComponent variant, string inventorySetName, CommercePipelineExecutionContext context)
        {
            if (variant.HasPolicy <AvailabilityAlwaysPolicy>())
            {
                return(Engine.CatalogConstants.InventoryStatus.Perpetual);
            }

            if (!variant.HasComponent <InventoryComponent>())
            {
                return(Engine.CatalogConstants.InventoryStatus.NotAvailable);
            }

            var inventoryComponent = variant.GetComponent <InventoryComponent>();
            var association        = inventoryComponent.InventoryAssociations.FirstOrDefault(
                i => i.InventorySet.EntityTarget.RemoveIdPrefix <InventorySet>().Equals(inventorySetName, StringComparison.InvariantCultureIgnoreCase));

            if (association != null)
            {
                var inventoryInformation = await Commander.GetEntity <InventoryInformation>(context.CommerceContext, association.InventoryInformation.EntityTarget).ConfigureAwait(false);

                return(this.ToInventoryStatus(inventoryInformation));
            }

            return(Engine.CatalogConstants.InventoryStatus.NotAvailable);
        }
Beispiel #2
0
        public static ProductExtensionComponent GetProductExtensionComponent(SellableItem instance, string variationId)
        {
            ItemVariationComponent variation = instance.GetVariation(variationId);

            if (variation.HasComponent <ProductExtensionComponent>() == false)
            {
                var component = instance.GetComponent <ProductExtensionComponent>().Clone();
                variation.SetComponent(component);

                return(component);
            }
            else
            {
                return(variation.GetComponent <ProductExtensionComponent>());
            }
        }