Personalized checkout and custom promotions with Shopify Scripts
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
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
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
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!
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Thanks!
Hmm. Seems like a given that you'd be able to access the handle. Seems very weird to have to replicate your handle as a tag.
For now I've created a few temporary tags to get around this, but not ideal if we had to do this for many many products.
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
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Super helpful, Paul. Thanks!
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024