Ejemplo n.º 1
0
 public override string GetDestinationId()
 {
     soap.SetOptions(Adapter.Options);
     try
     {
         soap.Begin();
         var client  = soap.GetClient();
         var product = client.catalogProductInfo(
             soap.GetSession(),
             IndexedItem.Value <string>("sku"),
             "0" /* Store 0 always contains all products */,
             null,
             "sku");
         return(product.product_id);
     }
     finally
     {
         soap.End();
     }
 }
Ejemplo n.º 2
0
        private catalogProductCreateEntity Load()
        {
            var qty           = IndexedItem.Value <double>("stock");
            var inStock       = qty > 0 ? 1 : 0;
            var manageStock   = Options.FirstOrDefault(o => o.Name == "manage_stock").Value == bool.TrueString ? 1 : 0;
            var useQtyDecimal = Options.FirstOrDefault(o => o.Name == "decimal").Value == bool.TrueString ? 1 : 0;

            return(new catalogProductCreateEntity
            {
                stock_data = new catalogInventoryStockItemUpdateEntity()
                {
                    qty = IndexedItem.Value <string>("stock"),
                    is_in_stock = inStock,
                    manage_stock = manageStock,
                    is_in_stockSpecified = true,
                    is_qty_decimal = useQtyDecimal,
                    is_qty_decimalSpecified = true,
                }
            });
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 5
0
        private catalogProductCreateEntity LoadEntity()
        {
            var normalizedValues = GetNormalizedValuesByDependencies();
            var attributes       = IndexedItem.Properties().Where(p => !HexaFields.Contains(p.Name))
                                   .Select(a => new associativeEntity
            {
                key   = a.Name,
                value = normalizedValues.ContainsKey(a.Name) ? normalizedValues[a.Name] : IndexedItem.Value <string>(a.Name)
            })
                                   .ToArray();

            var result = new catalogProductCreateEntity
            {
                additional_attributes = new catalogProductAdditionalAttributesEntity
                {
                    single_data = attributes
                },
            };

            return(result);
        }
Ejemplo n.º 6
0
 public override string GetDestinationId()
 {
     return(IndexedItem.Value <string>("DestinationId"));
 }
Ejemplo n.º 7
0
 public override PushState Create(out string destinationId)
 {
     destinationId = IndexedItem.Value <string>("DestinationId");
     return(Update());
 }