Issue with PublishedAt property using ShopifySharp

240 views Asked by At

I'm trying to create a product in my shopify store using ShopifySharp. My issue is that after setting my PublishedAt property and creating the product in my store, the PublishedAt property is changed by the actual time. So i'm not able to publish a product in the future. I've tried to create the product and update the PublishedAt property but it still set the property to the exact time when the "CreateAsync" or "UpdateAsync" method is called. Hope i'm clear enough. Thanks for the help.

static async Task createProduct() {
            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",
                        }
                    },
                PublishedAt = new DateTimeOffset(2023, 04, 27, 19, 0, 0, TimeSpan.FromHours(2))
            };
            Console.WriteLine(product.PublishedAt); //return "27/04/2023 19:00:00 +02:00"
            product = await service.CreateAsync(product);
            Console.WriteLine(product.PublishedAt); // return "26/04/2023 16:32:34 +02:00"
            product.PublishedAt = new DateTimeOffset(2023, 04, 27, 19, 0, 0, TimeSpan.FromHours(2));
            Console.WriteLine(product.PublishedAt); // return "27/04/2023 19:00:00 +02:00"
            product = await service.UpdateAsync((long)product.Id, product);
            Console.WriteLine(product.PublishedAt); // return "26/04/2023 16:32:35 +02:00"
        }

I'm expecting to create a product where his publishing date match the PublishedAt property. The product is well created but published at the time i run the script.

1

There are 1 answers

0
David Lazar On

The issue here is you are not using the right API calls. First off, create your product. It will exist in your store, but not be assigned to any sales channels. So it is just an ID you can use for the next step. The next step is to identify the sales channel you want to publish the product to. When you get the ID of that sales channel, for example, the online store, you can then create a mutation in the publishable publish endpoint with a publish date. That way, your product will show up in the channel you chose at that time.