コード例 #1
0
ファイル: product.py プロジェクト: chachun88/bodegas
    def InitById(self, identifier):

        cur = self.connection.cursor(
            cursor_factory=psycopg2.extras.RealDictCursor)

        q = '''select string_agg(s.name,',') as size, array_agg(s.id) as size_id, p.*, c.name as category from "Product" p 
                inner join "Category" c on c.id = p.category_id 
                inner join "Product_Size" ps on ps.product_sku = p.sku
                inner join "Size" s on s.id = ps.size_id
                where p.id = %(id)s group by p.id, c.name limit 1'''
        p = {"id": identifier}
        try:
            cur.execute(q, p)
            producto = cur.fetchone()

            # print producto

            producto["tags"] = []

            tag = Tag()
            response = tag.GetTagsByProductId(identifier)

            if "success" in response:
                tags = response["success"]
                for t in tags:
                    producto["tags"].append(t["tag_id"])

                # print producto

            # else:
            #   print response["error"]

            if cur.rowcount > 0:
                return self.ShowSuccessMessage(producto)
            else:
                return self.ShowError("product cannot be initialized")
        except Exception, e:
            return self.ShowError(
                "product cannot be initialized, error: {}".format(str(e)))
コード例 #2
0
ファイル: product.py プロジェクト: chachun88/bodegas
    def InitBySku(self, sku):

        cur = self.connection.cursor(
            cursor_factory=psycopg2.extras.RealDictCursor)

        q = '''select string_agg(s.name,',') as size, array_agg(s.id) as size_id, p.*, c.name as category from "Product" p 
                inner join "Category" c on c.id = p.category_id 
                inner join "Product_Size" ps on ps.product_sku = p.sku
                inner join "Size" s on s.id = ps.size_id
                where p.sku = %(sku)s group by p.id, c.name limit 1'''
        p = {"sku": sku}
        try:

            # print cur.mogrify(q,p)

            cur.execute(q, p)
            producto = cur.fetchone()

            producto["tags"] = []

            tag = Tag()
            response = tag.GetTagsByProductId(producto["id"])

            if "success" in response:
                tags = response["success"]
                for t in tags:
                    producto["tags"].append(t["tag_id"])

            if cur.rowcount > 0:
                return self.ShowSuccessMessage(producto)
            else:
                return self.ShowError(
                    "product with sku {} not found".format(sku))
        except Exception, e:
            return self.ShowError(
                "product cannot be initialized by sku, {}".format(str(e)))
コード例 #3
0
ファイル: product.py プロジェクト: chachun88/bodegas
    def InitById(self, identifier):

        cur = self.connection.cursor(
            cursor_factory=psycopg2.extras.RealDictCursor)

        q = '''select string_agg(s.name,',') as size, array_agg(s.id) as size_id, p.*, c.name as category from "Product" p 
                inner join "Category" c on c.id = p.category_id 
                inner join "Product_Size" ps on ps.product_sku = p.sku
                inner join "Size" s on s.id = ps.size_id
                where p.id = %(id)s and deleted = %(deleted)s group by p.id, c.name limit 1'''
        p = {
            "id": identifier,
            "deleted": False
        }
        try:
            cur.execute(q, p)
            producto = cur.fetchone()
            producto["tags"] = []

            tag = Tag()
            response = tag.GetTagsByProductId(identifier)

            if "success" in response:
                tags = response["success"]
                for t in tags:
                    producto["tags"].append(t["tag_id"])

            if cur.rowcount > 0:
                self.id = producto["id"]
                self.category = producto["category"]
                self.sku = producto["sku"]
                self.name = producto["name"]
                self.upc = producto["upc"]
                self.description = producto["description"]
                self.brand = producto["brand"]
                self.manufacturer = producto["manufacturer"]
                self.size = producto["size"].split(",")
                self.color = producto["color"]
                self.material = producto["material"]
                self.bullet_1 = producto["bullet_1"]
                self.bullet_2 = producto["bullet_2"]
                self.bullet_3 = producto["bullet_3"]
                self.size_id = producto["size_id"]
                self.price = producto["price"]
                self.image = producto["image"]
                self.image_2 = producto["image_2"]
                self.image_3 = producto["image_3"]
                self.image_4 = producto["image_4"]
                self.image_5 = producto["image_5"]
                self.image_6 = producto["image_6"]
                self.sell_price = producto["sell_price"]
                self.tags = producto["tags"]
                self.which_size = producto["which_size"]
                self.delivery = producto["delivery"]
                self.for_sale = producto["for_sale"]
                self.promotion_price = producto["promotion_price"]
                self.bulk_price = producto["bulk_price"]
                self.position = producto["position"]
                self.added = producto["added"]
                self.sold = producto["sold"]
                return self.ShowSuccessMessage(producto)
            else:
                return self.ShowError("product cannot be initialized")
        except Exception, e:
            return self.ShowError("product cannot be initialized, error: {}".format(str(e)))