Parent/slug combo has to be unique - not just the slug

Issue #590 new
Former user created an issue

Satchmo currently does not allow for categories to be setup in the following manner:

  • Men's
    • Shirts
    • Pants
    • Etc.
  • Boys'
    • Shirts
    • Pants
    • Etc.

Currently, as an example, only the following URLs are achievable:

domain.com/categories/mens/shirtsBR domain.com/categories/boys/shirts-1

Original solution as proposed by Chris Moffitt:

  • Modify product/views/category_view
    • Pull category based on the parent_slug as well as the actual slug

Reported by trevor.ochocki

Comments (3)

  1. Former user Account Deleted

    After studying of category_tree template tag code I think that it is better to hold category tree in SQL( see http://www.ibase.ru/devinfo/DBMSTrees/sqltrees.html for example).

    It is possible to store l,r,level,category_id fields for each record. In this case it will be possible to do only one query to DB to show very large left menu, single query to select all parents, recursive children, ...

  2. Former user Account Deleted

    Sorry, repeating

    To resolve this temporary I have to change satchmo/product/urls.py to include full URL to parent_slugs:

        (r'^category/(?P<parent_slugs>([-\w]+/)*)(?P<slug>[-\w]+)/$',
            'category_view', {}, 'satchmo_category'),
    

    and satchmo/product/views.py to process whole path to category:

    import re
    def category_view(request, slug, parent_slugs='', template='base_category.html'):
        """Display the category, its child categories, and its products.
    
        Parameters:
         - slug: slug of category
         - parent_slugs: ignored
        """
        try:
            if parent_slugs:
                            nodes=[]
                            for rec in re.finditer('([-\w]*)/', parent_slugs):
                                    nodes.append(rec.group(1)) # Split to parts
                            obj = Category.objects # will construct reqest
                            nodes.reverse()
                            cond = ''
                            for node in nodes:
                                    cond = 'parent__' + cond
                                    r={}
                                    r[cond+'slug'] = node
                                    obj = obj.filter(**r)
                            category = obj.get(slug=slug)
            else:
                    category = Category.objects.get(slug=slug)
            products = list(category.active_products())
            sale = find_best_auto_discount(products)
    

    But correct way is to exclude such limitations by satchmo design changes. Full category urls should be constructed on category creation/changes and hold in a separate table. URL paring is a very frequent operation, it is good idea to exclude any actions in python code here.

  3. Former user Account Deleted

    To resolve this temporary I have to change satchmo/product/urls.py to include full URL to parent_slugs:

    (r'^category/(?P<parent_slugs>([-\w]+/)*)(?P<slug>[-\w]+)/$', 'category_view', {}, 'satchmo_category'),

    and satchmo/product/views.py to process whole path to category:

    import re def category_view(request, slug, parent_slugs='', template='base_category.html'): """Display the category, its child categories, and its products.

    Parameters: - slug: slug of category - parent_slugs: ignored """ try: if parent_slugs: nodes=[] for rec in re.finditer('([-\w]*)/', parent_slugs): nodes.append(rec.group(1)) # Split to parts obj = Category.objects # will construct reqest nodes.reverse() cond = '' for node in nodes: cond = 'parent' + cond r={} r[cond+'slug'] = node obj = obj.filter(r) category = obj.get(slug=slug) else: category = Category.objects.get(slug=slug) products = list(category.active_products()) sale = find_best_auto_discount(products)

    But correct way is to exclude such limitations by satchmo design changes. Full category urls should be constructed on category creation/changes and hold in a separate table. URL paring is a very frequent operation, it is good idea to exclude any actions in python code here.

  4. Log in to comment