How to override product_url in Spree 2.x / Rails 4 to make SEO more friendly?

I would like my product URLs to look like this:

/product-name-here/p

instead:

/product/product-name-here

How can i achieve this?

+4
source share
1 answer

After many studies, I realized this.

There are two steps in this process. The first is to create a route that matches the route of the new product.

So, go into your .rb routes and in this section:

mount Spree::Core::Engine, :at => '/' 
 # Spree Specific routes here
end

Add this line: get ':id/p' => 'spree/products#show'

So now it looks like this:

mount Spree::Core::Engine, :at => '/' 
 # Spree Specific routes here
 get ':id/p' => 'spree/products#show'
end

At this point, you can visit the product page with the new URL structure: /product-name-here/p

, , spree , - URL, . product_path, spree URL-. "spree", products_helper.rb

app/helpers/spree/products_helper.rb :

module Spree::ProductsHelper

  def product_path(product)
    "/#{product.permalink}/p"
  end

end

. URL. , URL-, , .


:

, , ProductHelper , undefined: line_item_description_text

, , , :

def line_item_description_text (var)
  ""
end
+5

Source: https://habr.com/ru/post/1537857/


All Articles