def get_byid(self, order_id): try: # Setup connection to the DB db_config = read_db_config() conn = MySQLConnection(**db_config) cursor = conn.cursor() order = None args = [order_id] cadao = CustomerAddressDao() pdao = PaymentInfoDao() # Calls the stored procedure cursor.callproc('getRetailOrderByOrderID', args) # This loop iterates through the resultsets for result in cursor.stored_results(): # This loop iterates through the rows in each resultset for x in result.fetchall(): order = RetailOrder() order.order_id = x[0] order.date_ordered = x[1] order.discount = x[2] order.total_price = x[3] order.status = x[4] u = User() u.id = x[5] u.first_name = x[6] u.last_name = x[7] order.customer = u p = PaymentInfo() p.card_id = x[8] p.last_four = x[9] p.card_issuer = x[10] order.card = p a = CustomerAddress() a.address_id = x[11] a.street = x[12] a.city = x[13] a.state_code = x[14] a.zip_code = x[15] order.shipping_address = a # Close the connection to the DB cursor.close() conn.close() except Error as error: print(error) except Exception as e: print(e) return order
def getAllCancelledOrders(self): orders = [] try: # Setup connection to the DB db_config = read_db_config() conn = MySQLConnection(**db_config) cursor = conn.cursor() udao = UserDao() cadao = CustomerAddressDao() pdao = PaymentInfoDao() # Calls the stored procedure cursor.callproc('getAllCancelledOrders') # This loop iterates through the resultsets for result in cursor.stored_results(): # This loop iterates through the rows in each resultset for x in result.fetchall(): order = RetailOrder() order.order_id = x[0] order.date_ordered = x[1] order.total_price = x[2] order.discount = x[3] order.customer = udao.get_byid(x[4]) order.shipping_address = cadao.get_byid(x[5]) order.card = pdao.get_byid(x[6]) order.status = x[7] orders.append(order) # Close the connection to the DB cursor.close() conn.close() except Error as error: print(error) except Exception as e: print(e) return orders