| 3133 |
rajveer |
1 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 1970 |
rajveer |
2 |
|
|
|
3 |
'''
|
|
|
4 |
Created on 26-May-2011
|
|
|
5 |
|
|
|
6 |
@author: rajveer
|
|
|
7 |
'''
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
class CategoryManager(object):
|
|
|
11 |
_instance = None
|
|
|
12 |
categories = dict()
|
|
|
13 |
def __init__(self,):
|
| 2101 |
rajveer |
14 |
print "Returning category list"
|
| 1970 |
rajveer |
15 |
|
|
|
16 |
def __new__(cls, *args, **kwargs):
|
|
|
17 |
if not cls._instance:
|
|
|
18 |
cls._instance = super(CategoryManager, cls).__new__(cls, *args, **kwargs)
|
| 3133 |
rajveer |
19 |
client = CatalogClient().get_client()
|
| 1970 |
rajveer |
20 |
t_categories = client.getAllCategories()
|
|
|
21 |
for category in t_categories:
|
|
|
22 |
cls.categories[category.id] = category
|
|
|
23 |
for category in t_categories:
|
|
|
24 |
if category.parent_category_id != 0:
|
|
|
25 |
if cls.categories[category.parent_category_id].children_category_ids is None:
|
|
|
26 |
cls.categories[category.parent_category_id].children_category_ids = []
|
|
|
27 |
cls.categories[category.parent_category_id].children_category_ids.append(category.id)
|
|
|
28 |
|
|
|
29 |
return cls._instance
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
def getCategory(self, id):
|
|
|
33 |
return self.categories.get(id)
|
|
|
34 |
|
|
|
35 |
'''
|
|
|
36 |
if __name__ == '__main__':
|
|
|
37 |
catm = CategoryManager()
|
|
|
38 |
print catm.getCategory(10000).description
|
|
|
39 |
print catm.getCategory(10001).description
|
|
|
40 |
|
|
|
41 |
catm1 = CategoryManager()
|
|
|
42 |
print catm1.getCategory(10000).description
|
|
|
43 |
'''
|
|
|
44 |
|