<s> from satchless . item import InsufficientStock <EOL> def contains_unavailable_products ( cart ) : <EOL> try : <EOL> [ item . product . check_quantity ( item . quantity ) for item in cart ] <EOL> except InsufficientStock : <EOL> return True <EOL> return False <EOL> def remove_unavailable_products ( cart ) : <EOL> for item in cart : <EOL> try : <EOL> cart . add ( item . product , quantity = item . quantity , replace = True ) <EOL> except InsufficientStock as e : <EOL> quantity = e . item . get_stock_quantity ( ) <EOL> cart . add ( item . product , quantity = quantity , replace = True ) <EOL> def get_product_variants_and_prices ( cart , product ) : <EOL> lines = ( cart_line for cart_line in cart <EOL> if cart_line . product . product_id == product . id ) <EOL> for line in lines : <EOL> for i in range ( line . quantity ) : <EOL> yield line . product , line . get_price_per_item ( ) <EOL> def get_category_variants_and_prices ( cart , discounted_category ) : <EOL> products = set ( ( cart_line . product . product for cart_line in cart ) ) <EOL> discounted_products = [ ] <EOL> for product in products : <EOL> for category in product . categories . all ( ) : <EOL> is_descendant = category . is_descendant_of ( <EOL> discounted_category , include_self = True ) <EOL> if is_descendant : <EOL> discounted_products . append ( product ) <EOL> for product in discounted_products : <EOL> for line in get_product_variants_and_prices ( cart , product ) : <EOL> yield line </s>
