def get_product(self,values,productid,product,price):
   if productid:
     result=Product.gql("where ean=:1 limit 1",productid).get()
     if not result:
       if price and product:
         result=Product()
         result.ean=productid
         result.name=product
         result.price=int(float(price)*100)
         result.put()
     else:
       product=result.name
       price=result.price
   else:
     result=None
   values["productid"]=productid
   values["product"]=product
   values["price"]=price
   return result
Ejemplo n.º 2
0
    def post(self, pid):
        store_user = self.get_store_user()
        resume = self.get_argument("presume", '')
        name = self.get_argument("pname", '')
        tags = self.get_argument("tags", '')
        intro = self.get_argument("pintro", '')
        quantity = float(self.get_argument("quantity", '0'))
        producer = self.get_argument("pproducer", '')
        metakeywords = self.get_argument("pmetakeywords", '')
        metadescription = self.get_argument("pmetadescription", '')
        metatitle = self.get_argument("pmetatitle", '')
        category = int(self.get_argument("pcategory", '1'))
        quality = self.get_argument("quality", '')
        standard = self.get_argument("standard", '')
        status = self.get_argument("standard", '1')
        prompt = self.get_argument("prompt", '')

        psname = self.get_argument("sname", '')
        psprice = float(self.get_argument("sprice", '0'))
        content = {}
        sku = int(time.time())
        try:
            if pid == '0':
                p = Product()
                p.sku = str(sku)
                if not os.path.exists('upload/' + p.sku):
                    os.mkdir('upload/' + p.sku)
                p.created = int(time.time())
                p.categoryback = 1
                content['operatetype'] = '创建产品'
            else:
                p = Product.get(Product.id == pid)
                content['operatetype'] = '修改产品'
                content['oldproduct'] = simplejson.dumps(str(p))
            p.args = 'C'
            p.categoryfront = 166  #数据库内置分类   经销商
            p.updatedtime = int(time.time())
            p.updatedby = self.get_store_user()
            p.resume = resume
            p.name = name
            p.tags = tags
            p.intro = intro
            p.producer = producer
            p.metakeywords = metakeywords
            p.metadescription = metadescription
            p.metatitle = metatitle
            p.marketprice = 0
            p.quantity = quantity
            p.quality = quality
            p.standard = standard
            p.xgperusernum = 50
            p.xgtotalnum = 99999
            p.status = int(status)  # 默认上架
            p.store = store_user.store.id
            p.is_store = 1
            p.category_store = category
            p.prompt = prompt
            p.validate()
            p.save()
            if pid == '0':
                s = ProductStandard()
            else:
                s = ProductStandard.get(
                    ProductStandard.id == p.defaultstandard)
            s.name = psname
            s.tags = ''
            s.price = psprice
            s.orginalprice = psprice
            s.weight = 0
            s.ourprice = psprice
            s.relations = []
            s.product = p
            s.save()
            s.relations = '[' + str(s.id) + ']'
            s.save()
            p.defaultstandard = s.id
            p.save()
            self.flash("保存成功")
            content['pid'] = p.id
            AdminLog.create(user=self.get_store_user(),
                            dotime=int(time.time()),
                            content=content)
            self.redirect('/store/product/' + str(p.id))
        except Exception, e:
            self.flash("保存失败,请联系管理员" + e.message)
            self.redirect('/store/product/0')