Comments (7)
we happily accept PRs!
from shopify_python_api.
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.
@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.
@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.
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:
- Does it work if you add more than one metafield in
new_product_image.metafields = ...
? - 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.
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.
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)
- pyactiveresource.connection.Error: Not Found: fulfillments.json when creating fulfillment HOT 5
- Add support to AssignedFulfillmentOrder HOT 2
- Running into certificate issue with python 3.12 HOT 3
- A new release of the Shopify API is due soon HOT 2
- Test failure for `test_raises_if_aud_doesnt_match_api_key` HOT 2
- A new release of the Shopify API occurred
- API Version is not working greater then 2023-04 HOT 12
- Deprecation Notice for `gateway` Field in Order Object - Impact on Shopify Python SDK HOT 2
- Package Version 12.4.0 shows released in CHANGELOG but not available in PyPi HOT 4
- 413 (Payload Too Large) while uploading images under 2Mb HOT 2
- Add promised online access token support HOT 2
- Allow to interact console with ipython
- Global state for sessions causes race conditions on async code HOT 2
- A new release of the Shopify API is due soon HOT 2
- I cannot find the abandoned checkouts endopoint HOT 5
- Shopify Python SDK Deletes Customer Address on Same Address Update HOT 4
- A new release of the Shopify API occurred HOT 2
- request online access token HOT 2
- `calculated_refund` Appears as `None` when Printed but is Not Actually `None` HOT 2
- multi threaded sample request, products API HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shopify_python_api.