Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Product Update Broken #379

Open
lantram opened this issue Jul 3, 2019 · 3 comments
Open

Partial Product Update Broken #379

lantram opened this issue Jul 3, 2019 · 3 comments
Labels
object updating Bugs and strange behavior around updating objects, primarly related to #284 stale Issues that have become inactive and need attention/review from @nozzlegear

Comments

@lantram
Copy link

lantram commented Jul 3, 2019

Using a sample store with a product catalog from here ("jewelry.csv"):

https://github.com/shopifypartners/product-csvs

If I do this:

await productService.UpdateAsync(product.Id.Value,
    new Product()
    {
        Title = "New product title"
    });

It messes up the store. In particular, it makes the product unavailable (removes the online store sales channel). I don't know if anything else is affected.

Instead I have to do this:

var product = await productService.GetAsync(productId);
product.Title = "New product title";
await productService.UpdateAsync(product.Id.Value,product);

The documentation on Updating a product at https://github.com/nozzlegear/ShopifySharp#products says we can do this:

var service = new ProductService(myShopifyUrl, shopAccessToken);
var product = await service.UpdateAsync(productId, new Product()
{
    Title = "New product title"
});

However, that is not currently correct since it appears to be broken.

@nozzlegear nozzlegear added the object updating Bugs and strange behavior around updating objects, primarly related to #284 label Jul 4, 2019
@nozzlegear
Copy link
Owner

nozzlegear commented Aug 6, 2019

I'm currently working on a ShopifySharp.Experimental package, with the main goal of introducing a new way to create/update objects without accidentally sending values you didn't intend to send (including null). I'll update here when it's published.

#388

@shafaqat-ali-cms365
Copy link

I am having the same issue, I had 5000 products and I updated all of them and now all products have been removed form the the Online Store channel. Please help, all products have been unlinked from the online store channel.

Any temporary fix or anything, please help.

@nozzlegear
Copy link
Owner

Hey @shafaqat-ali-cms365, this issue is partially out of date as it doesn't contain the fix for the problem. I'm keeping it open because I'm still planning a better, more encompassing fix in 6.0.

The problem is, because of the nature of C# and Json.Net, fields that you don't explicitly set on an object will get serialized to their default C# value. For a nullable date field, that value is null which unpublishes your products. When updating the product, you need to explicitly set the PublishedAt value so it doesn't get serialized to null:

var product = await service.UpdateAsync(new Product
{
    PublishedAt = someDateTimeValue,
    // And other updated values here 
});

@Laurabee530 Laurabee530 added the stale Issues that have become inactive and need attention/review from @nozzlegear label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
object updating Bugs and strange behavior around updating objects, primarly related to #284 stale Issues that have become inactive and need attention/review from @nozzlegear
Projects
None yet
Development

No branches or pull requests

4 participants