Subversion Repositories SmartDukaan

Rev

Rev 19437 | Blame | Compare with Previous | Last modification | View Log | RSS feed

from datetime import datetime
from dtr.utils.utils import to_java_date, CATEGORY_MAP, SUB_CATEGORY_MAP, get_mongo_connection_cms, get_mongo_connection
from shop2020.config.client.ConfigClient import ConfigClient
from dtr.dao import ProductInfo
from pymongo import DESCENDING
import traceback

config_client = ConfigClient()
mongo_cms_host = config_client.get_property('mongo_cms_host')



def addData(bulkItemsList):
    notAdded = []
    for item in bulkItemsList:
        v= ProductInfo(None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None)
        v. _id = None
        v.addedOn = to_java_date(datetime.now())
        v.available_price = item.available_price 
        v.brand = item.brand 
        v.cashback = ""
        v.category= CATEGORY_MAP.get(item.category_id)
        v.category_id = item.category_id
        v.identifier = item.identifier      
        v.in_stock = 0
        v.marketPlaceUrl = None
        v.model_name = item.model_name
        v.mrp = item.mrp if item.mrp else 0
        v.product_name = item.product_name
        v.rank = 0
        v.secondaryIdentifier = ""
        v.skuBundleId = None
        v.source = "saholic.com"
        v.sourceCategoryId=""
        v.sourceProductId=""
        v.source_id=4
        v.source_product_name = item.source_product_name
        v.source_url = ""
        v.status  = 1
        v.stock_status = "Out of stock"
        v.thumbnail = None
        v.updatedOn = to_java_date(datetime.now())
        v.url = None
        v.priceUpdatedOn = 0
        v.offer = item.offer
        v.tagline = item.tagline
        v.is_shortage = 0
        v.brand_id = item.brand_id
        v.maxPrice = 0
        v.buyBoxFlag = 1
        v.coupon = ""
        v.codAvailable = 1
        v.gross_price = 0
        v.ignorePricing = 0       
        v.quantity = item.quantity
        v.videoLink = ""
        v.showVideo = 0
        v.subCategoryId = item.subCategoryId
        v.subCategory= SUB_CATEGORY_MAP.get(item.subCategoryId)
        v.showMrp = 1 if item.showMrpFlag else 0
        v.shippingCost = 0
        v.showNetPrice = 1 if item.showNetPrice else 0
        v.internalRank = item.internalRank
         
        try:
            col = list(get_mongo_connection_cms(host=mongo_cms_host).CONTENT.siteContent.find({'_id':long(v.identifier)}))
            if len(col) ==0:
                print "Content not found for %s"%(v.identifier)
                notAdded.append(v.identifier)
                continue
            else:
                v.url = "http://saholic.com/"+col[0]['url']
                v.thumbnail = col[0]['defaultImageUrl']
                v.marketPlaceUrl = "http://saholic.com/"+col[0]['url']
        except:
            traceback.print_exc()
            print "Exception in %s"%(v.identifier)
            notAdded.append(v.identifier)
            continue
            
        
        exist = list(get_mongo_connection().Catalog.MasterData.find({'identifier':v.identifier}))
        if len(exist) > 0:
            notAdded.append(v.identifier)
            continue
        max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',DESCENDING)]).limit(1))
        max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',DESCENDING)]).limit(1))
        v._id = max_id[0]['_id'] + 1
        v.skuBundleId = max_bundle[0]['skuBundleId'] + 1
        get_mongo_connection().Catalog.MasterData.insert(v.__dict__)
    
    return notAdded