<p>There may be better ways but here was our approach to setting it up in a way that's easy to duplicate for the next project. This method will allow you to use the existing /commerce folder for your templates, while using any replacement word you want for "commerce", in your URIs.</p>

<p>In /config/general.php, create an enviromentVariable using your desired replacement for "commerce":</p>

<pre><code>'environmentVariables' =&gt; array(
  'baseUrl'   =&gt; 'http://commerce.dev',
  'basePath'  =&gt; getcwd(),
  'shopPrefix' =&gt; 'shop' //&lt;- add this line
)
</code></pre>

<p>In /templates/ create a folder of the same name as your prefix. Inside that folder, create a twig template file, such as _entry.twig. Place the following in that file:</p>

<pre><code>{% set shopPrefix = craft.config.environmentVariables.shopPrefix %}
{% set segmentUri = "/" %}
{% for segment in craft.request.segments() %}
    {% set segmentUri = segmentUri ~ "/" ~ segment|replace(shopPrefix, 'commerce') %}
{% endfor %}

{% include segmentUri %}
</code></pre>

<p>Next, open /templates/commerce/_layouts/main.html (or whatever is your primary layout for Commerce pages). After <code>{% set cart = craft.commerce.cart %}</code>, add:</p>

<pre><code>{% set shopPrefix = craft.config.environmentVariables.shopPrefix %} 
</code></pre>

<p>In your various templates, replace any commerce links or input fields used for redirects with <code>{{shopPrefix}}/cart</code>, e.g:</p>

<pre><code>&lt;a href="{{shopPrefix}}/cart"&gt;Link&lt;/a&gt;
&lt;input type="hidden" name="redirect" value="{{shopPrefix}}/cart"/&gt;
</code></pre>

<p>Any redirect URIs part of Twig functions should be replaced as well. Example:</p>

<pre><code>{% if cart.isEmpty %}
    {% redirect shopPrefix ~ '/myProductsPage' %}
{% endif %}
</code></pre>

<p>NOTE: as mentioned above, never replace Commerce action URIs. They are used as controller actions.</p>

<p>The benefit of this method is that next time, if a client wants to use "buy" instead of "shop", you can reuse all these templates, just change the enviromentVariable and one folder name, and you're done.</p>

CC BY-SA 3.0
2016-05-20T16:34:24.407Z
2016-05-20T16:34:24.407Z
jhanshew
<p>You'll need to keep any action URLs as <code>commerce/</code>, as these point to <a href="https://craftcms.com/docs/plugins/controllers#posting-to-controller-actions" rel="noreferrer">controller actions</a> inside the Commerce plugin, not templates in your <code>store</code> directory. So if you find:</p>

<pre><code>&lt;input type="hidden" name="action" value="store/cart/updateCart"&gt;
</code></pre>

<p>That will need to be restored to:</p>

<pre><code>&lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
</code></pre>

CC BY-SA 3.0
2016-03-17T11:06:57.787Z
2016-03-17T11:06:57.787Z
Mike Pepper
<p>Let me apologize right now that my inexperience with Craft is likely the issue here and that my question might be more general to Craft's routing features and not so specific to Craft Commerce.</p>

<p>I'm playing with a clean Craft/Craft Commerce installation and using the included templates in /templates/commerce. I wanted to customize the path however to /store/. I changed the directory name, adjusted the "commerce" where it was hardcoded in the templates, and changed the Product URL Format and Product Template within the Product Types to use store/ instead. Everything seems to look okay until I try to add/remove/update a product into the cart.</p>

<p>When that happens I get a routing error:</p>

<pre><code>CHttpException
Unable to resolve the request "store/cart/updateCart".
/path/to/craft/app/framework/web/CWebApplication.php(286)
</code></pre>

<p>Line 286 is:</p>

<pre><code>throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".'
</code></pre>

<p>Should I be leaving these paths alone and adjusting the URL in a different way? Any help and direction would be greatly appreciated. Thank you!</p>

<plugin-craftcommerce>
Customizing Craft Commerce Template Paths
# Customizing Craft Commerce Template Paths

(Asked by: username_0 on 2016-03-17)

Let me apologize right now that my inexperience with Craft is likely the issue here and that my question might be more general to Craft's routing features and not so specific to Craft Commerce.
I'm playing with a clean Craft/Craft Commerce installation and using the included templates in /templates/commerce. I wanted to customize the path however to /store/. I changed the directory name, adjusted the "commerce" where it was hardcoded in the templates, and changed the Product URL Format and Product Template within the Product Types to use store/ instead. Everything seems to look okay until I try to add/remove/update a product into the cart.
When that happens I get a routing error:
CHttpException
Unable to resolve the request "store/cart/updateCart".
/path/to/craft/app/framework/web/CWebApplication.php(286)

Line 286 is:
throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".'

Should I be leaving these paths alone and adjusting the URL in a different way? Any help and direction would be greatly appreciated. Thank you!

**Tags:** plugin-craftcommerce


---

## 2 answers

### Answer by username_2 on 2016-03-17. Score: 5 | Accepted answer

You'll need to keep any action URLs as commerce/, as these point to controller actions inside the Commerce plugin, not templates in your store directory. So if you find:


That will need to be restored to:


---

### Answer by username_1 on 2016-05-20. Score: 2

There may be better ways but here was our approach to setting it up in a way that's easy to duplicate for the next project. This method will allow you to use the existing /commerce folder for your templates, while using any replacement word you want for "commerce", in your URIs.
In /config/general.php, create an enviromentVariable using your desired replacement for "commerce":
'environmentVariables' => array(
  'baseUrl'   => 'http://commerce.dev',
  'basePath'  => getcwd(),
  'shopPrefix' => 'shop' //<- add this line
)

In /templates/ create a folder of the same name as your prefix. Inside that folder, create a twig template file, such as _entry.twig. Place the following in that file:
{% set shopPrefix = craft.config.environmentVariables.shopPrefix %}
{% set segmentUri = "/" %}
{% for segment in craft.request.segments() %}
    {% set segmentUri = segmentUri ~ "/" ~ segment|replace(shopPrefix, 'commerce') %}
{% endfor %}

{% include segmentUri %}

Next, open /templates/commerce/_layouts/main.html (or whatever is your primary layout for Commerce pages). After {% set cart = craft.commerce.cart %}, add:
{% set shopPrefix = craft.config.environmentVariables.shopPrefix %} 

In your various templates, replace any commerce links or input fields used for redirects with {{shopPrefix}}/cart, e.g:
Link


Any redirect URIs part of Twig functions should be replaced as well. Example:
{% if cart.isEmpty %}
    {% redirect shopPrefix ~ '/myProductsPage' %}
{% endif %}

NOTE: as mentioned above, never replace Commerce action URIs. They are used as controller actions.
The benefit of this method is that next time, if a client wants to use "buy" instead of "shop", you can reuse all these templates, just change the enviromentVariable and one folder name, and you're done.


---

