Hi, there; I'm doing some minor modifications to an example script (buy x get y) because I'd like to match one of the 'get' products by handle (this script has to work across 5 similar plus stores, so matching by id is not ideal)
Currently this line: line_item.variant.product.handle.downcase.strip
is giving me this error: [Error] undefined method 'handle' for #<Product:0x7f8f2f16d5f0>
Is it really not possible to access the product's handle, or is there something else causing this error maybe? Thanks for any info!
Solved! Go to the solution
Also, is there somewhere I can access a full list of what properties I have access to?
There's this link, but doesn't seem like it's totally relevant to shopify scripts? https://shopify.dev/docs/admin-api/rest/reference/products/product
Hi, there; I'm doing some minor modifications to an example script (buy x get y) because I'd like to match one of the 'get' products by handle (this script has to work across 5 similar plus stores, so matching by id is not ideal)
If need be a work around is to go through product.tags method, though this can be a hassle if you need to create this convention on lots of products and keep everything in sync when product names change.
@RobertFXR wrote:Also, is there somewhere I can access a full list of what properties I have access to?
https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts
While most methods and properties you may see in scripts are simply standard, not all shopify methods or properties are documented fully and clearly.
I've had issues with just getting the full variant.title and that's in the list of properties!
This is an accepted solution.
Let the stores MSM know your use case for why this feature is needed
If your only using the online store channel you could update the theme to use Line Item Properties to pass the product handle to cart|checkout so it's more automatic though you may need to update theme cart and notifications not to show LIP's ( use single underscore _ prefix , or double underscore convention to hide LIPS during checkout)
You can see some of what's available using the .methods method, other inspection features( .attributes, pp ) are disabled since scripts are a locked down version of ruby also without things like active record
puts line_item.variant.methods(false)
puts product.methods
pass false to not show inherited methods
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |