GithubHelp home page GithubHelp logo

Comments (7)

kevinhughes27 avatar kevinhughes27 commented on August 22, 2024

we happily accept PRs!

from shopify_python_api.

michaelgeary avatar michaelgeary commented on August 22, 2024

This is not a good fix, because metafields then becomes read-only. This makes it impossible (or hard?) to add a metafield to a new image. I had to change my Image.metafields to Image.get_metafields so i could set a meta field:
new_image.metafields = [{'value_type': 'string', 'namespace': 'tags', 'value': 'this is an alt tag', 'key': 'alt'}]

thoughts?

from shopify_python_api.

gavinballard avatar gavinballard commented on August 22, 2024

@michaelgeary: I believe all usages of the metafields() method on other classes are read-only (that method delegates to a shopify.resources.Metafield.find call, see here).

I don't think setting metafields in the manner you've outlined will actually be propagated to the server when you call new_image.save() (could stand corrected on this though).

As far as I'm aware, metafields can only be added one-by-one through the calling of the add_metafield() method.

from shopify_python_api.

michaelgeary avatar michaelgeary commented on August 22, 2024

@gavinballard: if you inspect the query body from pyactiveresource.connection, you'll see that setting a metafield like i show above does indeed produce the correct results. I just added several images to a product using this approach. Additionally, the Image class doesn't support the add_metafield() on a new record. Here is my code snippet, which worked with my modified Image class:

the_product = shopify.Product.find("2012358789")

## upload the image
new_product_image = shopify.Image()
new_product_image.position = 2

local_image = "product_image.jpg"
im = Image.open(local_image)
im.thumbnail((3000,3000))

output = StringIO.StringIO()
im.save(output, "JPEG")
contents = output.getvalue()
output.close()

new_product_image.attach_image(contents)

if those_alt_tags:

    new_product_image.metafields = [{'value_type': 'string', 'namespace': 'tags', 'value': "This is the image alt tag", 'key': 'alt'}]


this_product.images.append(new_product_image)

this_product.save()

I could find no other way of adding a meta/alt tag to an image at the same time as creating it. I'd welcome a more correct way of doing this.

from shopify_python_api.

gavinballard avatar gavinballard commented on August 22, 2024

Oh, that's neat - I didn't realise that you could include Metafields in an initial POST request to create a new resource. Two questions:

  1. Does it work if you add more than one metafield in new_product_image.metafields = ...?
  2. Does this method work for other (non-Image) resources as well?

I think we might need @kevinhughes27 to chime in on this to see what the proper behaviour should be.

from shopify_python_api.

kevinhughes27 avatar kevinhughes27 commented on August 22, 2024

I didn't realize that either - it might only work for products since that endpoint has a lot of code behind it to let you do multiple things at once (like add images etc). If it works then I am okay with a method that lets you add metafields easily.

At the end of the day this lib just sends json to shopify

from shopify_python_api.

michaelgeary avatar michaelgeary commented on August 22, 2024

yes, it works with any number of metafields, because, as Kevin says, it just converts it to JSON. However, I don't see a way to save an Image directly. It would be nice if we could simply assign a product_id to an image instance, and it would post to the correct URL. Anyways, i'm not sure where to go from here... I was able to accomplish my immediate needs, but don't really have (currently) ongoing Shopify integration needs, so i'm not sure i'm the best person to try to submit a PR for this...

from shopify_python_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.