Commerce Core supports deep linking to product variations by appending a variation ID query parameter to a PDP URL. The Add to Cart form adds and updates this parameter as options are changed on the Add to Cart form, such that if I configure a product and copy the link to send to someone, they will see my same selection:
example.com/some-cool-product?v=42
The only way for an admin right now to get such a link is to do so from the PDP even though we list the variations out in the product edit interface. I think we should add a link copying operation there as a convenience feature, the method based on the ease of either strategy:
- Add a "Copy link" operations link to the dropbutton that would copy the variation specific link to the clipboard when selected. If we can do that without needing any sort of interstitial page, this is a fine option; I just wasn't sure what amount of flexibility we had here.
- Add a copy icon to the right of the dropbutton similar to what you see on GitHub and elsewhere for copying links to repositories with a hover text that explains, "Copy variation link to clipboard".
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | copy-success.png | 1.41 KB | jsacksick |
Issue fork commerce-3444403
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 #4
jsacksick commentedCan you attach a screenshot? Also wondering about Views? No idea if some people override the default list by a view.
Comment #5
tbkot commentedHere is the screenshot

We could create a new field and theme for the views because I do not think 'operations' is a good way to add this logic as we do not do anything with variation.
Comment #6
majmunbog commented@tBKoT I think we should not reference variation in CSS, libraries, or data attributes. That way we can reuse this link and styles elsewhere.
Comment #7
tbkot commentedComment #8
jsacksick commentedWorks great, 2 comments though: navigator.clipboard.writeText is async, it returns a promise so technically:
The following try catch isn't going to work.
So we either need to convert the code to look like this:
Or create a function and make it async:
Additionally, there is no visual feedback after successfully copying the text, like on Github (See the attached screenshot):
Let's use the following icon for this: https://icons.getbootstrap.com/icons/check-lg/.
Comment #9
tbkot commented@jsacksick icon now changing if the copy process was successful together with the title attribute. After 2 seconds everything is turning back to the previous state.
Comment #10
jsacksick commented