示例#1
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                listing_id=listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title', '')
            product.description = listing.get('description', '')
            product.currency = listing.get('currency', 'inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId', 0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp', 0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',
                                                             0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty', '')
            rate_chart.gift_title = listing.get('gifts', '')
            rate_chart.shipping_charges = Decimal(
                str(listing.get('shippingCharges', '0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration',
                                                       '7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id,
                                                         rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
示例#2
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                    listing_id = listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title','')
            product.description = listing.get('description','')
            product.currency = listing.get('currency','inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId',0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp',0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty','')
            rate_chart.gift_title = listing.get('gifts','')
            rate_chart.shipping_charges = Decimal(str(listing.get('shippingCharges','0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration','7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id, rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
示例#3
0
文件: feed.py 项目: daasara/riba
    def create_master_product(self, data, sync, product=None, is_update=False):
        if not product:
            product = Product()
        product.title = data['cleaned_data']['title']
        product.description = data['cleaned_data']['detailed_desc'] or data['cleaned_data']['description']
        product.brand = data['cleaned_data']['brand']
        product.category = data['cleaned_data']['category']
        product.slug = slugify(product.title)[:150]
        product.model = data['cleaned_data']['model']
        product.moderate = True
        product.currency = data['cleaned_data'].get('currency','inr')
        product.type = data['cleaned_data'].get('product_type','normal')
        product.product_type = self.get_mapped_sku_type(data['cleaned_data'].get('sku_type',''))
        if data['cleaned_data'].get('video',''):
            product.video_embed = data['cleaned_data']['video']

        #If the category belongs to BLACKLIST_CATEGORIES, then set product.status = 'deactive'
        #else product.status = data['cleaned_data']['status']
        category = data['cleaned_data']['category']
        if str(category.ext_id) in getattr(settings, 'BLACKLIST_CATEGORIES', []):
            product.status = 'deactive'
        elif data['cleaned_data']['status'] in ['active','deactive','deleted']:
            product.status = data['cleaned_data']['status']

        product.save(using='default')
        product.productimage_set.using('default').all().delete()

        if self.download_images:
            # download the image
            for url in data['cleaned_data']['image_url']:
                try:
                    feedutils.attach_image_to_product(product,url)
                except Exception, e:
                    log.exception(
                            'Error adding image to product %s from %s: %s' % (
                                product.id, data['cleaned_data']['image_url'],
                                repr(e)))