Exemplo n.º 1
0
        private void AssignOptionsToProduct(string bvin)
        {
            wl(" - Migrating Options...");

            data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString()));


            Api proxy = GetBV6Proxy();

            var choices = db.bvc_ProductXChoice.Where(y => y.ProductId == bvin);
            if (choices == null) return;
            foreach (data.bvc_ProductXChoice choice in choices)
            {
                if (this.EmptyOptions.Contains(choice.ChoiceId)) continue; // Skip already assigned
                proxy.ProductOptionsAssignToProduct(choice.ChoiceId, bvin, false);
            }

            var modifiers = db.bvc_ProductXModifier.Where(y => y.ProductId == bvin);
            if (modifiers == null) return;
            foreach (data.bvc_ProductXModifier mod in modifiers)
            {
                if (this.EmptyOptions.Contains(mod.ModifierId)) continue; // Skip already assigned
                proxy.ProductOptionsAssignToProduct(mod.ModifierId, bvin, false);
            }

            var inputs = db.bvc_ProductXInput.Where(y => y.ProductId == bvin);
            if (inputs == null) return;
            foreach (data.bvc_ProductXInput input in inputs)
            {
                proxy.ProductOptionsAssignToProduct(input.InputId, bvin, false);
            }

            // Only generate variants after all options are added. Saves Time
            proxy.ProductOptionsGenerateAllVariants(bvin);

            // Now Assign Variant Skus
            var combos = db.bvc_ProductChoiceCombinations.Where(y => y.ParentProductId == bvin).ToList();
            if (combos == null) return;
            if (combos.Count < 1)
            {
                wl("No Combos Found.");
                return;
            }
            else
            {
                wl(combos.Count + " combos found");
            }
            var children = db.bvc_Product.Where(y => y.ParentID == bvin).ToList();
            if (children == null) return;
            if (children.Count < 1)
            {
                wl("No children found.");
                return;
            }
            else
            {
                wl(children.Count + " children found to update skus");
            }

            int childCounter = 0;
            foreach (var child in children)
            {
                childCounter++;
                wl("Updating Child Variant Sku " + childCounter);
                var dto = new ProductVariantSkuUpdateDTO();
                dto.Sku = child.SKU.Trim();
                dto.ProductBvin = bvin;

                if (dto.Sku.Length > 0)
                {
                    var matchingChoices = combos.Where(y => y.ProductId == child.bvin).ToList();
                    foreach (var match in matchingChoices)
                    {
                        dto.MatchingOptions.Add(new VariantOptionDataDTO()
                        {
                            ChoiceId = match.ChoiceId,
                            ChoiceItemId = match.ChoiceOptionId
                        });
                    }
                }
                
                wl("SKU: " + dto.Sku + " of parent " + dto.ProductBvin + " matches ");
                foreach (var match in dto.MatchingOptions)
                {
                    wl("Choice: " + match.ChoiceId + " Option:" + match.ChoiceItemId);
                }

                proxy.ProductVariantUpdateSku(dto);
            }            
        }
Exemplo n.º 2
0
 public ApiResponse<bool> ProductVariantUpdateSku(ProductVariantSkuUpdateDTO data)
 {
     ApiResponse<bool> result = new ApiResponse<bool>();
     result = RestHelper.PostRequest<ApiResponse<bool>>(this.fullApiUri + "productvariantssku/" + Enc(data.ProductBvin) + "?key=" + Enc(key), MerchantTribe.Web.Json.ObjectToJson(data));
     return result;
 }