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".

Issue fork commerce-3444403

Command icon 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

rszrama created an issue. See original summary.

tBKoT made their first commit to this issue’s fork.

jsacksick’s picture

Can you attach a screenshot? Also wondering about Views? No idea if some people override the default list by a view.

tbkot’s picture

StatusFileSize
new40.34 KB

Here is the screenshot
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.

majmunbog’s picture

@tBKoT I think we should not reference variation in CSS, libraries, or data attributes. That way we can reuse this link and styles elsewhere.

tbkot’s picture

Status: Active » Needs review
jsacksick’s picture

Status: Needs review » Needs work
StatusFileSize
new1.41 KB

Works great, 2 comments though: navigator.clipboard.writeText is async, it returns a promise so technically:

The following try catch isn't going to work.

            try {
              const successful = navigator.clipboard.writeText(link);
              if (!successful) {
                console.log('Failed to copy link');
              }
            } catch (err) {
              console.log('Failed to copy link');
            }

So we either need to convert the code to look like this:

navigator.clipboard.writeText("This is the text to be copied").then(() => {
  console.log('Content copied to clipboard');
  /* Resolved - text copied to clipboard successfully */
},() => {
  console.error('Failed to copy');
  /* Rejected - text failed to copy to the clipboard */
});

Or create a function and make it async:

async function copyContent() {
  try {
    await navigator.clipboard.writeText('This is the text to be copied');
    console.log('Content copied to clipboard');
    /* Resolved - text copied to clipboard successfully */
  } catch (err) {
    console.error('Failed to copy: ', err);
    /* Rejected - text failed to copy to the clipboard */
  }
}

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/.

tbkot’s picture

Status: Needs work » Needs review

@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.

jsacksick’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.