private PushState UpdateProduct(string destinationId)
        {
            var attrModel   = (AttributeModel)GetIndexModel();
            var entityModel = (EntityModel)GetEntityModel();

            soap.SetOptions(Adapter.Options);

            try
            {
                var storeIds = Regex.Split(Options.FirstOrDefault(o => o.Name == "store_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                var data     = LoadData();

                soap.Begin();
                var client    = soap.GetClient();
                var sessionId = soap.GetSession();

                foreach (var storeId in storeIds)
                {
                    client.catalogProductUpdate(sessionId, destinationId, data, storeId, "id");
                }
                return(PushState.Success);
            }
            finally
            {
                soap.End();
            }
        }
        private PushState UpdateStock(string destinationId)
        {
            var attrModel   = (AttributeModel)GetIndexModel();
            var entityModel = (EntityModel)GetEntityModel();

            soap.SetOptions(Adapter.Options);
            try
            {
                var updateData = Load();

                soap.Begin();
                var client    = soap.GetClient();
                var sessionId = soap.GetSession();

                client.catalogInventoryStockItemUpdate(sessionId, destinationId, updateData.stock_data);
                return(PushState.Success);
            }
            finally
            {
                soap.End();
            }
        }
Beispiel #3
0
        private PushState Update()
        {
            var result        = PushState.Success;
            var destinationId = IndexedItem.Value <string>("DestinationId");

            soap.SetOptions(Adapter.Options);
            try
            {
                var data     = LoadEntity();
                var storeIds = Regex.Split(Options.FirstOrDefault(o => o.Name == "store_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase);

                soap.Begin();
                var client = soap.GetClient();
                foreach (var storeId in storeIds)
                {
                    var success = client.catalogProductUpdate(soap.GetSession(), destinationId, data, storeId, "id");
                }
                return(result);
            }
            finally
            {
                soap.End();
            }
        }
Beispiel #4
0
        public override PushState Create(out string destinationId)
        {
            var pushState = PushState.Success;

            soap.SetOptions(Adapter.Options);
            var indexedModel     = GetIndexModel();
            var additionalFields = IndexedItem.Properties().Where(p => !HexaFields.Contains(p.Name) && !ProductFields.Contains(p.Name)).Select(p => p.Name);
            var websiteIds       = Regex.Split(Options.FirstOrDefault(o => o.Name == "website_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            var storeIds         = Regex.Split(Options.FirstOrDefault(o => o.Name == "store_ids").Value, "[,;|]", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            var normalizedValues = GetNormalizedValuesByDependencies();

            try
            {
                var additionalAttrs = additionalFields.Select(f => new associativeEntity
                {
                    key   = f,
                    value = normalizedValues.ContainsKey(f) ? normalizedValues[f] : IndexedItem.Value <string>(f)
                });

                var attributes = new catalogProductAdditionalAttributesEntity {
                    single_data = additionalAttrs.ToArray()
                };
                var data = new catalogProductCreateEntity
                {
                    website_ids           = websiteIds,
                    additional_attributes = attributes,
                    status     = "2",
                    visibility = "4",
                    stock_data = new catalogInventoryStockItemUpdateEntity()
                    {
                        qty         = "0",
                        is_in_stock = 1,
                    }
                };

                soap.Begin();
                var client = soap.GetClient();
                destinationId = client
                                .catalogProductCreate(soap.GetSession(),
                                                      normalizedValues.ContainsKey("type") ? normalizedValues["type"] : IndexedItem.Value <string>("type"),
                                                      normalizedValues.ContainsKey("attribute_set_id") ? normalizedValues["attribute_set_id"] : IndexedItem.Value <string>("attribute_set_id"),
                                                      IndexedItem.Value <string>("sku"),
                                                      data,
                                                      "0").ToString();
                foreach (var storeId in storeIds)
                {
                    client.catalogProductMultiUpdateAsync(
                        soap.GetSession(),
                        new string[] { destinationId },
                        new catalogProductCreateEntity[]
                    {
                        new catalogProductCreateEntity
                        {
                            website_ids = websiteIds,
                            status      = "2" // Creating product always set status to false. itemModel.removed == DIndex.ConstYes ? "2" : "1"
                        }
                    },
                        storeId,
                        "id");
                }

                return(pushState);
            }
            finally
            {
                soap.End();
            }
        }