Subversion Repositories SmartDukaan

Rev

Rev 18106 | Rev 18384 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18106 Rev 18271
Line 2433... Line 2433...
2433
        for x in result['hits']['hits']:
2433
        for x in result['hits']['hits']:
2434
            tempMap = {}
2434
            tempMap = {}
2435
            tempMap = {'skuBundleId':x['_source']['id'],'title':x['_source']['title']}
2435
            tempMap = {'skuBundleId':x['_source']['id'],'title':x['_source']['title']}
2436
            temp.append(tempMap)
2436
            temp.append(tempMap)
2437
            bundles.append(x['_source']['id'])
2437
            bundles.append(x['_source']['id'])
-
 
2438
    #return temp
2438
    return getDealsForNotification(bundles, skipSplitting=True)
2439
    return getDealsForNotification(bundles, skipSplitting=True)
2439
 
2440
 
2440
def getCountForSearchText(subCategoryIds, searchTerm):
2441
def getCountForSearchText(subCategoryIds, searchTerm):
2441
    subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
2442
    subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
2442
    payload = {
2443
    payload = {
Line 2463... Line 2464...
2463
}
2464
}
2464
    
2465
    
2465
    result =  get_elastic_search_connection().search(index="my_index", body=payload)
2466
    result =  get_elastic_search_connection().search(index="my_index", body=payload)
2466
    totalCount= result['hits']['total']
2467
    totalCount= result['hits']['total']
2467
    return {'searchTerm':searchTerm,'count':totalCount}
2468
    return {'searchTerm':searchTerm,'count':totalCount}
-
 
2469
 
-
 
2470
def getDealById(id):
-
 
2471
    item = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(id)}))
-
 
2472
    d = get_mongo_connection().Catalog.Deals.find_one({'_id':int(id)})
-
 
2473
    if d is None:
-
 
2474
        d = {'showDp':0,'dp':0}
-
 
2475
    if len(item) ==0:
-
 
2476
        return {}
-
 
2477
    try:
-
 
2478
        cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
-
 
2479
        if not cashBack or cashBack.get('cash_back_status')!=1:
-
 
2480
            item[0]['cash_back_type'] = 0
-
 
2481
            item[0]['cash_back'] = 0
-
 
2482
        else:
-
 
2483
            if cashBack.get('maxCashBack') is not None:
-
 
2484
                
-
 
2485
                if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
-
 
2486
                    cashBack['cash_back_type'] = 2
-
 
2487
                    cashBack['cash_back'] = cashBack['maxCashBack']
-
 
2488
                elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
-
 
2489
                    cashBack['cash_back'] = cashBack['maxCashBack']
-
 
2490
            
-
 
2491
            item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
-
 
2492
            item[0]['cash_back'] = cashBack['cash_back']
-
 
2493
    except:
-
 
2494
        print "Error in adding cashback to deals"
-
 
2495
        item[0]['cash_back_type'] = 0
-
 
2496
        item[0]['cash_back'] = 0
-
 
2497
    try:
-
 
2498
        item[0]['dp'] = d['dp']
-
 
2499
        item[0]['showDp'] = d['showDp']
-
 
2500
    except:
-
 
2501
        item[0]['dp'] = 0.0
-
 
2502
        item[0]['showDp'] = 0
-
 
2503
    try:
-
 
2504
        item[0]['thumbnail'] = item[0]['thumbnail'].strip()
-
 
2505
    except:
-
 
2506
        pass
-
 
2507
    
-
 
2508
    try:
-
 
2509
        if item[0]['showVideo']==0:
-
 
2510
            item[0]['videoLink'] =""
-
 
2511
    except:
-
 
2512
        item[0]['videoLink'] =""
-
 
2513
    try:
-
 
2514
        if item[0]['quantity'] >1:
-
 
2515
            ppq = float(item[0]['available_price'])/item[0]['quantity']
-
 
2516
             
-
 
2517
            if ppq == round(ppq):
-
 
2518
                item[0]['ppq'] = int(ppq)
-
 
2519
            else:
-
 
2520
                item[0]['ppq'] = round(ppq,2)
-
 
2521
        else:
-
 
2522
            item[0]['ppq'] = 0
-
 
2523
    except:
-
 
2524
        item[0]['ppq'] = 0
-
 
2525
    if item[0]['category_id']!=6:
-
 
2526
        try:
-
 
2527
            item[0]['filterLink'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
-
 
2528
            item[0]['filterText'] = 'More %s items'%(item[0]['brand'])
-
 
2529
        except:
-
 
2530
            item[0]['filterLink'] = ""
-
 
2531
            item[0]['filterText'] = ""
-
 
2532
    else:
-
 
2533
        try:
-
 
2534
            if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
-
 
2535
                raise
-
 
2536
            item[0]['filterLink'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
-
 
2537
            item[0]['filterText'] = 'More %s'%(item[0]['subCategory'])
-
 
2538
        except:
-
 
2539
            item[0]['filterLink'] = ''
-
 
2540
            item[0]['filterText'] = ""
-
 
2541
    try:
-
 
2542
        if item[0]['source_id']==4:
-
 
2543
            item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
-
 
2544
            if item_availability_info is None or len(item_availability_info)==0:
-
 
2545
                item[0]['availabilityInfo'] = [{}]
-
 
2546
            else:
-
 
2547
                item[0]['availabilityInfo'] = item_availability_info
-
 
2548
    except:
-
 
2549
        item[0]['availabilityInfo'] = [{}]
-
 
2550
    return item[0]
-
 
2551
 
2468
            
2552
            
2469
def main():
2553
def main():
2470
    "8-cable , 15- charger, 20-screen guard"
2554
    "8-cable , 15- charger, 20-screen guard"
2471
    
2555
    
2472
    res = getCountForSearchText("20^8","iph")
2556
    res = getDealsForSearchText("20^8","iph",0,1000)
-
 
2557
    for i in res:
-
 
2558
        print i
2473
    
2559
    
2474
if __name__=='__main__':
2560
if __name__=='__main__':
2475
    main()
2561
    main()
2476
 
2562
 
2477
 
2563