Answers.Body: <p>Yep so can just create a route in the control panel.  </p>
  
  <p>See: <a href="https://docs.craftcms.com/v3/routing.html" rel="nofollow noreferrer">https://docs.craftcms.com/v3/routing.html</a></p>
  
  <p>You'll see you can use a slug (using the token <code>slug</code>) so that Craft will validate the url actually has a valid slug on the end, or you can just use <code>*</code> and craft will route to this template no matter what is on the end.</p>
  
  <p><a href="https://i.sstatic.net/wwNTp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wwNTp.png" alt="enter image description here"></a></p>
  
  <p>(I personally prefer to create routes in source control managed &amp; commented code using the <code>routes.php</code> config file - <a href="https://docs.craftcms.com/v3/routing.html#advanced-routing-with-url-rules" rel="nofollow noreferrer">https://docs.craftcms.com/v3/routing.html#advanced-routing-with-url-rules</a>  ... so this would be something like:</p>
  
  <p><code>'samples/sample/&lt;slug&gt;'          =&gt; ['template' =&gt; '/your/samples/template']</code></p>
  
  <p>Then, on the main product page, build your url to the samples page as, basically:</p>
  
  <p><code>/samples/sample/{{ thisProduct.slug }}</code></p>
  
  <p>Then, in your samples template you just grab the last segment, as you are, and use that in your code to pre-select the particular sample from you list...as you are.</p>
  
  <p>So basically, you're almost there apart from creating the route.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-21T01:08:36.707Z
Answers.LastActivityDate: 2020-05-21T01:08:36.707Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>We have a commerce site that provides samples of its items. We have a single product that handles all the samples and displays them in a dropdown.  What I'd like to do is have a link on the product page that passes this product name/slug to the sample product. What would be the best way to approach this? </p>
  
  <p>The sample product url is /samples/sample. I have tried something like Order a Sample. But that tries to look up a product with that url and it does not exist.  </p>
  
  <p>In the dropmenu I am trying </p>
  
  <pre><code>{% set prodSlug = craft.request.getLastSegment() %} 
  &lt;select&gt;
  {% for purchasable in product.variants %}
      {% set current = (product.slug == prodSlug) %}
         {% if current %} 
          &lt;option {% if purchasable.stock &lt;= 0 and purchasable.hasUnlimitedStock == false %}disabled {% endif %} value="{{ purchasable.id }}"&gt;
          {{ purchasable.description }}  {{ purchasable.price|commerceCurrency(cart.currency) }}&lt;/option&gt;
         {% endif %}
  {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
  <p>Is there a way to setup a product that could accept different slugs to make this work? Maybe with a route?</p>
  
Tags: <plugin-craftcommerce>
Title: passing product info to another product
ThreadText: # passing product info to another product
  
  (Asked by: username_0 on 2020-05-18)
  
  We have a commerce site that provides samples of its items. We have a single product that handles all the samples and displays them in a dropdown. What I'd like to do is have a link on the product page that passes this product name/slug to the sample product. What would be the best way to approach this?
  
  The sample product url is /samples/sample. I have tried something like Order a Sample. But that tries to look up a product with that url and it does not exist.
  
  In the dropmenu I am trying
  
  ```
  {% set prodSlug = craft.request.getLastSegment() %} 
  <select>
  {% for purchasable in product.variants %}
      {% set current = (product.slug == prodSlug) %}
         {% if current %} 
          <option {% if purchasable.stock <= 0 and purchasable.hasUnlimitedStock == false %}disabled {% endif %} value="{{ purchasable.id }}">
          {{ purchasable.description }}  {{ purchasable.price|commerceCurrency(cart.currency) }}</option>
         {% endif %}
  {% endfor %}
  </select>
  
  ```
  
  Is there a way to setup a product that could accept different slugs to make this work? Maybe with a route?
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-21. Score: 1
  
  Yep so can just create a route in the control panel.
  
  See: <https://docs.craftcms.com/v3/routing.html>
  
  You'll see you can use a slug (using the token `slug`) so that Craft will validate the url actually has a valid slug on the end, or you can just use `*` and craft will route to this template no matter what is on the end.
  
  [![enter image description here](https://i.sstatic.net/wwNTp.png)](https://i.sstatic.net/wwNTp.png)
  
  (I personally prefer to create routes in source control managed & commented code using the `routes.php` config file - <https://docs.craftcms.com/v3/routing.html#advanced-routing-with-url-rules> ... so this would be something like:
  
  `'samples/sample/<slug>' => ['template' => '/your/samples/template']`
  
  Then, on the main product page, build your url to the samples page as, basically:
  
  `/samples/sample/{{ thisProduct.slug }}`
  
  Then, in your samples template you just grab the last segment, as you are, and use that in your code to pre-select the particular sample from you list...as you are.
  
  So basically, you're almost there apart from creating the route.
  
  
  ---
  
  