Describe your bug or feature request.
Drupal commerce allows the variation associated with a loaded product to be specified by "sku" or "v" query string values thanks to ProductVariationStorage::loadFromContext. However, the only variation tokens that are available with a product require you to use the field delta [commerce_product:variations:0]. It would be nice to access the currently selected variation using token [commerce_product:commerce_product_variation] so that it matches the following scenario:
Product id 1 has variations 1, 2 and 3. When hitting /product/1?v=2 the token [commerce_product:commerce_product_variation:id] would return 2. If there were no argument in the url, the returned id would be 1 (the default)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 0001-Issue-3249743-Add-token-support-for-product-variatio.patch | 5.86 KB | andyg5000 |
Issue fork commerce-3249743
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andyg5000MR ready for review and associated patch attached .
Comment #5
andyg5000Comment #6
karlsheaWorks great!
Comment #7
jsacksick commentedThe token label says "Default variation", but it isn't actually the default variation that we're returning so it could be misleading I guess.
Here's the comment for the loadFromContext() method.
By reading this, I'd expect the default variation to be returned, (i.e $product->getDefaultVariation());
Also, the merge request needs to be rebased so the pipelines are running.
Comment #8
jsacksick commentedPerhaps we should call the token "current_variation"? Thoughts?
Comment #9
rszrama commentedI think
current_variationworks, and maybedefault_variationis an additional token we should consider supporting. 🧐Comment #10
karlsheaRebased issue branch, addressed some comments, renamed commerce_product_variation token to current_variation, added default_variation token.
Comment #13
jsacksick commentedUpdated the array keys per my comments and merged this, thanks everyone!
Comment #14
jsacksick commentedOh I suck! I misread the code... It has to be "commerce_product_variation". Reverting my change :)!
Comment #17
karlsheaIf you look at my last commit I made exactly the same mistake except in the other argument lol