似乎有一个错误,这是解决方法...
https://github.com/nozzlegear/ShopifySharp/issues/373
创建和使用以下服务
using System;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ShopifySharp;
using ShopifySharp.Infrastructure;
public class ProductVariantServiceEx : ProductVariantService
{
public ProductVariantServiceEx(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { }
public virtual async Task<ProductVariant> UpdateAsync(long productVariantId, ProductVariant variant)
{
try
{
// BUGFIX: If variant.CompareAtPrice is set to 0, then force it to empty
string json = new JsonContent(new { variant }).ReadAsStringAsync().Result;
if (json.Contains("\"compare_at_price\":0.00}")
|| json.Contains("\"compare_at_price\":0.00,"))
{
json = json.Replace("\"compare_at_price\":0.00", "\"compare_at_price\":\"\"");
var req = PrepareRequest($"variants/{productVariantId}.json");
using var content = new StringContent(json, Encoding.UTF8, "application/json");
await Task.Run(() => Thread.Sleep(500));
return (await ExecuteRequestAsync<ProductVariant>(req, HttpMethod.Put, default, content, "variant")
.ConfigureAwait(false)).Result;
}
return await base.UpdateAsync(productVariantId, variant);
}
catch (Exception)
{
return null;
}
}
}