You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ShopifySharp设置商品PublishedAt属性异常,无法指定未来发布时间

解决ShopifySharp设置商品定时发布(PublishedAt)无效的问题

问题根源

Shopify API的核心逻辑是:如果商品处于已发布状态(默认值为true),设置未来的PublishedAt会被自动忽略,系统会将该属性强制覆盖为当前操作的时间。只有当商品处于未发布状态时,设置未来的PublishedAt才会生效,Shopify会在指定时间自动完成发布。

解决方案

  1. 创建商品时,明确设置Published = false(未发布状态),同时指定未来的PublishedAt时间;
  2. 若先创建未发布商品,后续调整发布时间时,需确保商品仍处于未发布状态,再修改PublishedAt值。

修改后的代码示例

static async Task CreateScheduledProduct() {
    var service = new ProductService(myShopifyUrl, shopAccesstoken);

    // 创建未发布商品并指定定时发布时间
    var product = new Product()
    {
        Title = "title",
        Vendor = "vendor",
        BodyHtml = "<strong>Good snowboard!</strong>",
        ProductType = "none",
        Tags = "test",
        Variants = new List<ProductVariant> {
            new ProductVariant {
                Price = (decimal)20.00,
                Weight = (decimal)0.45,
                InventoryQuantity = 1,
                InventoryManagement = "shopify",
            }
        },
        Published = false, // 关键:设置为未发布状态
        PublishedAt = new DateTimeOffset(2023, 04, 27, 19, 0, 0, TimeSpan.FromHours(2))
    };

    Console.WriteLine(product.PublishedAt); // 输出:27/04/2023 19:00:00 +02:00
    product = await service.CreateAsync(product);
    Console.WriteLine(product.PublishedAt); // 现在会保留设置的未来时间:27/04/2023 19:00:00 +02:00

    // 如需后续调整发布时间,确保商品仍未发布
    product.PublishedAt = new DateTimeOffset(2023, 04, 28, 10, 0, 0, TimeSpan.FromHours(2));
    product = await service.UpdateAsync((long)product.Id, product);
    Console.WriteLine(product.PublishedAt); // 输出调整后的未来时间:28/04/2023 10:00:00 +02:00
}

注意事项

  • 确保PublishedAt的时区设置正确,Shopify会基于该时区执行定时发布;
  • 一旦商品被手动设置为Published = true(已发布),后续再修改PublishedAt为未来时间将不再生效,需重新创建未发布商品来设置定时。

内容的提问来源于stack exchange,提问作者Ni-coco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 13:07:49