def remove_product(): option_remove_product_menu = int( input( "You will have to input the index of the product you would like to remove. If you need to see the list of products, " "select option 2.\n1. Remove product\n2. Display all products\n3. Go back\n" )) if option_remove_product_menu == 1: index_product_to_remove = int( input( "Introduce the index of the product to be removed(starting from 1):\n" )) try: products = Products.load_products() if 0 < index_product_to_remove <= products.__len__(): product_to_remove = products[index_product_to_remove - 1] Products.remove_product(product_to_remove) input( "Product -" + str(product_to_remove) + "- removed successfully\nPress enter key in order to continue\n" ) else: product_option = int( input( "This product does not exist in the list. Input 1 to try again or any other number to return to the store menu:\n" )) if product_option == 1: remove_product() except JSONDecodeError: input( "Error on retrieving the products. Press enter key in order to continue\n" ) elif option_remove_product_menu == 2: display_products() remove_product() elif option_remove_product_menu == 3: print("Going back...\n") else: error_handler() remove_product()
def remove_category(): option_remove_category = int( input( "Warning! Deleting a category will also delete all the products inside of it.\n1. Continue\n2. Go back\n" )) if option_remove_category == 1: category_to_remove = Category( input("Introduce the name of the category to be removed:\n")) try: categories = Categories.load_categories() if categories.count(category_to_remove) > 0: products = Products.load_products() for prod in products: if prod.get_category_name() == category_to_remove.name: Products.remove_product(prod) Categories.remove_category(category_to_remove) input( "Category -" + str(category_to_remove) + "- and all its products were removed successfully.\nPress enter key in order to continue\n" ) else: category_option = int( input( "This category does not exist in the list. Input 1 to try entering another category or any other number to return to the store menu:\n" )) if category_option == 1: remove_category() except JSONDecodeError: input( "Error on retrieving the categories. Press enter key in order to continue\n" ) elif option_remove_category == 2: print("Going back...\n") else: error_handler() remove_category()