def _get_products(self, request, skus): partner = get_partner_for_site(request) products = Product.objects.filter(stockrecords__partner=partner, stockrecords__partner_sku__in=skus) if not products: raise BadRequestException( _('Products with SKU(s) [{skus}] do not exist.').format( skus=', '.join(skus))) return products
def _get_available_products(self, request, products): unavailable_product_ids = [] for product in products: purchase_info = request.strategy.fetch_for_product(product) if not purchase_info.availability.is_available_to_buy: logger.warning('Product [%s] is not available to buy.', product.title) unavailable_product_ids.append(product.id) available_products = products.exclude(id__in=unavailable_product_ids) if not available_products: raise BadRequestException(_('No product is available to buy.')) return available_products
def _get_skus(self, request): skus = [escape(sku) for sku in request.GET.getlist('sku')] if not skus: raise BadRequestException(_('No SKUs provided.')) return skus