def DelProducts(): while True: id = utils.IntegerInputGet("Enter product id to be deleted: ") print("") if id not in Products.products_dict: utils.ErrorPrint( "Product ID: {0} doesn't exist!!\n".format(id)) else: Products.HeadingPrint() print(Products.products_dict[id]) print("") r = utils.YesNoGet("Delete this product") if (r == "y"): del Products.products_dict[id] with open("products.file", "wb") as products_file: pickle.dump(Products.products_dict, products_file) utils.SuccessPrint( "Product ID: {0} deleted!!\n".format(id)) else: utils.ErrorPrint( "Product ID: {0} not deleted!!\n".format(id)) r = utils.YesNoGet("\nDelete another product") if r != "y": break
def AddProduct(self, prod_id): quantity = 0 product = Products.products_dict[prod_id] if prod_id in self.products_quantity_dict: utils.BoldPrint( "Product ID {0} alread exits in your cart!!\n".format(prod_id)) curr_quantity = self.products_quantity_dict[prod_id] utils.BoldPrint("Current Quantity: {0}\n".format(curr_quantity)) r = utils.YesNoGet("Change Quantity") if r != "y": return False self.total_price -= curr_quantity * product.price quantity = utils.IntegerInputGet("Enter new quantity: ") if quantity != 0: self.products_quantity_dict[prod_id] = quantity else: quantity = utils.IntegerInputGet("Enter quantity: ") while (quantity == 0): ErrorPrint("Quantity can't be 0... please try again!!\n") quantity = utils.IntegerInputGet("Enter quantity: ") self.products_quantity_dict[prod_id] = quantity self.total_price += self.products_quantity_dict[prod_id] * product.price utils.SuccessPrint( "Product ID {0} added to your cart!!".format(prod_id)) self.Print() return True
def AddProducts(): while True: id = utils.IntegerInputGet("Enter product id: ") if id in Products.products_dict: utils.ErrorPrint( "Product ID: {0} already exists!!... try again.\n".format( id)) continue new_product = Products(id) Products.HeadingPrint() print(new_product) new_product.Modify() with open("products.file", "wb") as products_file: pickle.dump(Products.products_dict, products_file) utils.SuccessPrint( "Product ID: {0} successfully added!!\n\n".format(id)) r = utils.YesNoGet("Add another product") if r != "y": break
def AddToCart(self): while True: id = utils.IntegerInputGet("Enter product id: ") if id not in Products.products_dict: utils.ErrorPrint( "Product ID: {0} doesn't exist!!\n".format(id)) else: if True == self.cart.AddProduct(id): with open("customer.file", "wb") as customer_file: pickle.dump(Customer.customer_dict, customer_file) r = utils.YesNoGet("\nAdd another product to cart") if r != "y": break
def DeleteFromCart(self): if self.cart.IsEmpty() == True: utils.ErrorPrint("Cart is Empty!!\n") return while True: id = utils.IntegerInputGet("Enter product id: ") if id not in Products.products_dict: utils.ErrorPrint( "Product ID: {0} doesn't exist!!\n".format(id)) else: if True == self.cart.DeleteProduct(id): with open("customer.file", "wb") as customer_file: pickle.dump(Customer.customer_dict, customer_file) r = utils.YesNoGet("\nDelete another product from cart") if r != "y": break
def ModifyProducts(): while True: id = utils.IntegerInputGet("Enter product id to be modified: ") print("") if id not in Products.products_dict: utils.ErrorPrint( "Product ID: {0} doesn't exist!!\n".format(id)) else: Products.HeadingPrint() print(Products.products_dict[id]) Products.products_dict[id].Modify() with open("products.file", "wb") as products_file: pickle.dump(Products.products_dict, products_file) r = utils.YesNoGet("\nModify another product") if r != "y": break
def DeleteProduct(self, prod_id): if prod_id not in self.products_quantity_dict: utils.ErrorPrint( "Product ID {0} doesn't exist in your cart!!\n".format( prod_id)) return False product = Products.products_dict[prod_id] r = utils.YesNoGet("Delete the product completely") if (r != "y"): curr_quantity = self.products_quantity_dict[prod_id] utils.BoldPrint("Current Quantity: {0}\n".format(curr_quantity)) new_quantity = utils.IntegerInputGet("Decrease the Quantity to: ") if (new_quantity > curr_quantity): utils.ErrorPrint( "Use \"Add to Cart\" option to increase the quantity\n") return False if (new_quantity == curr_quantity): return False if (new_quantity != 0): self.products_quantity_dict[prod_id] = new_quantity self.total_price -= curr_quantity * product.price self.total_price += new_quantity * product.price self.Print() return True self.total_price -= self.products_quantity_dict[prod_id] * product.price del self.products_quantity_dict[prod_id] utils.SuccessPrint( "Product ID {0} deleted from your cart!!".format(prod_id)) self.Print() return True