Beispiel #1
0
    def save_product_features(self, master, features, sku_type):
        if not features:
            return

        product_type = self.get_mapped_sku_type(sku_type)
        if not product_type:
            return

        for f in features:
            if type(features[f]).__name__ != 'list':
                if not features[f]:
                    continue
                if features[f] and not 'data' in features[f]:
                    continue
                if features[f]['data'] and features[f]['data'] != 'null':
                    try:
                        fm = FeatureMapping.objects.using('default').get(account = self.config['ACCOUNT'], sku_type = product_type, feature_name = f)
                        feature = fm.feature
                    except FeatureMapping.DoesNotExist:
                        try:
                            # See if a feature is already added to the system with given name for the same product type
                            feature = Feature.objects.using('default').get(product_type = product_type, name=f)
                            # If yes, then save this as mapping
                            fm = self.get_or_create_feature_mapping(feature, product_type, f)
                        except Feature.DoesNotExist:
                            feature = Feature(product_type = product_type, name=f)
                            if features[f]['type'] == 'char':
                                t = 'text'
                            if features[f]['type'] == 'int':
                                t = 'number'
                            else:
                                t = 'text'
                            feature.type = t
                            feature.save(using='default')
                            self.get_or_create_feature_mapping(feature, product_type, f)

                    try:
                        product_feature = ProductFeatures.objects.using('default').get(product=master,feature=feature)
                    except ProductFeatures.DoesNotExist:
                        product_feature = ProductFeatures(feature=feature,product=master)
                    try:
                        product_feature.data = self.clean_data((features[f]['data']))
                        product_feature.type = features[f].get('feature_type','fixed')
                        if master.type == 'variable':
                            if product_feature.type == 'variable':
                                product_feature.save(using='default')
                        else:
                            product_feature.save(using='default')
                    except Exception, e:
                        log.exception('Error saving feature %s for %s' % (feature.name, master.id))
Beispiel #2
0
    def create_or_update_feature(self, product, mapping, data):
        feature = mapping.feature
        try:
            pf = ProductFeatures.objects.using('default').get(product=product, feature = feature)
        except ProductFeatures.DoesNotExist:
            pf = ProductFeatures(product = product, feature = feature)

        pf.data = data

        pf.clean()
        pf.save(using='default')
Beispiel #3
0
    def save_product_features(self, master, features, sku_type):
        if not features:
            return

        product_type = self.get_mapped_sku_type(sku_type)
        if not product_type:
            return

        for f in features:
            if type(features[f]).__name__ != "list":
                if not features[f]:
                    continue
                if features[f] and not "data" in features[f]:
                    continue
                if features[f]["data"] and features[f]["data"] != "null":
                    try:
                        fm = FeatureMapping.objects.using("default").get(
                            account=self.config["ACCOUNT"], sku_type=product_type, feature_name=f
                        )
                        feature = fm.feature
                    except FeatureMapping.DoesNotExist:
                        try:
                            # See if a feature is already added to the system with given name for the same product type
                            feature = Feature.objects.using("default").get(product_type=product_type, name=f)
                            # If yes, then save this as mapping
                            fm = self.get_or_create_feature_mapping(feature, product_type, f)
                        except Feature.DoesNotExist:
                            feature = Feature(product_type=product_type, name=f, group=self.get_feature_group())
                            if features[f]["type"] == "char":
                                t = "text"
                            if features[f]["type"] == "int":
                                t = "number"
                            else:
                                t = "text"
                            feature.type = t
                            feature.save(using="default")
                            self.get_or_create_feature_mapping(feature, product_type, f)

                    try:
                        product_feature = ProductFeatures.objects.using("default").get(product=master, feature=feature)
                    except ProductFeatures.DoesNotExist:
                        product_feature = ProductFeatures(feature=feature, product=master)
                    try:
                        product_feature.data = self.clean_data((features[f]["data"]))
                        product_feature.type = features[f].get("feature_type", "fixed")
                        if master.type == "variable":
                            if product_feature.type == "variable":
                                product_feature.save(using="default")
                        else:
                            product_feature.save(using="default")
                    except Exception, e:
                        log.exception("Error saving feature %s for %s" % (feature.name, master.id))
Beispiel #4
0
    def save_product_features(self, master, features, sku_type):
        if not features:
            return

        product_type = self.get_mapped_sku_type(sku_type)
        if not product_type:
            return

        for f in features:
            if type(features[f]).__name__ != 'list':
                if not features[f]:
                    continue
                if features[f] and not 'data' in features[f]:
                    continue
                if features[f]['data'] and features[f]['data'] != 'null':
                    try:
                        fm = FeatureMapping.objects.get(account = self.config['ACCOUNT'], sku_type = product_type, feature_name = f)
                        feature = fm.feature
                    except FeatureMapping.DoesNotExist:
                        try:
                            # See if a feature is already added to the system with given name for the same product type
                            feature = Feature.objects.get(product_type = product_type, name=f)
                            # If yes, then save this as mapping
                            fm = self.get_or_create_feature_mapping(feature, product_type, f)
                        except Feature.DoesNotExist:
                            feature = Feature(product_type = product_type, name=f, group = self.get_feature_group())
                            if features[f]['type'] == 'char':
                                t = 'text'
                            if features[f]['type'] == 'int':
                                t = 'number'
                            else:
                                t = 'text'
                            feature.type = t
                            feature.save()
                            self.get_or_create_feature_mapping(feature, product_type, f)

                    try:
                        product_feature = ProductFeatures.objects.get(product=master,feature=feature)
                    except ProductFeatures.DoesNotExist:
                        product_feature = ProductFeatures(feature=feature,product=master)
                    try:
                        product_feature.data = self.clean_data((features[f]['data']))
                        product_feature.type = features[f].get('feature_type','fixed')
                        if master.type == 'variable':
                            if product_feature.type == 'variable':
                                product_feature.save()
                        else:
                            product_feature.save()
                    except Exception, e:
                        log.exception('Error saving feature %s for %s' % (feature.name, master.id))