def _get_template_engine_and_context(): engine = django.template.engines['jinja2'] assert isinstance(engine, django_jinja.backend.Jinja2) shop = get_default_shop() shop.currency = 'USD' shop.prices_include_tax = False shop.save() request = RequestFactory().get('/') request.shop = shop request.customer = AnonymousContact() request.person = request.customer PriceDisplayOptions(include_taxes=False).set_for_request(request) tax = get_default_tax() create_default_tax_rule(tax) tax_class = get_default_tax_class() order, order_line = _get_order_and_order_line(request) product = create_product(sku='6.0745', shop=shop, tax_class=tax_class) context = { 'request': request, 'prod': product, # TODO: Test also with variant products 'sline': _get_source_line(request), 'bline': _get_basket_line(request), 'oline': order_line, 'order': order } return (engine, context)
def handle_product_data(self, request): product_id = request.GET["id"] shop_id = request.GET["shop_id"] customer_id = request.GET.get("customer_id") product = Product.objects.get(pk=product_id) shop = Shop.objects.get(pk=shop_id) ctx_request = RequestFactory().get("/") ctx_request.shop = shop ctx_request.customer = Contact.objects.filter(pk=customer_id).first() ctx_request.user = AnonymousUser() context = get_pricing_module().get_context_from_request(ctx_request) price_info = product.get_price_info(context, quantity=1) return { "id": product.id, "sku": product.sku, "name": product.name, "taxClass": { "id": product.tax_class.id, "name": force_text(product.tax_class), }, "unitPrice": { "value": price_info.price.value, # TODO: This is always zero?! "includesTax": price_info.price.includes_tax } }
def get_price_info(shop, customer, product, quantity): ctx_request = RequestFactory().get("/") ctx_request.shop = shop if customer: ctx_request.customer = customer ctx_request.user = AnonymousUser() context = get_pricing_module().get_context_from_request(ctx_request) return product.get_price_info(context, quantity=quantity)
def _get_template_engine_and_context(product_sku="6.0745", create_var_product=False): engine = django.template.engines["jinja2"] assert isinstance(engine, django_jinja.backend.Jinja2) shop = get_default_shop() shop.currency = "USD" shop.prices_include_tax = False shop.save() request = RequestFactory().get("/") request.shop = shop request.customer = AnonymousContact() request.person = request.customer PriceDisplayOptions(include_taxes=False).set_for_request(request) tax = get_default_tax() create_default_tax_rule(tax) tax_class = get_default_tax_class() order, order_line = _get_order_and_order_line(request) product = create_product(sku=product_sku, shop=shop, tax_class=tax_class) supplier = get_default_supplier(shop) if create_var_product: var_product = create_product(sku="32.9", shop=shop, tax_class=tax_class) child_product_1 = create_product(sku="4.50", shop=shop, tax_class=tax_class, supplier=supplier, default_price="4.5") child_product_2 = create_product(sku="12.00", shop=shop, tax_class=tax_class, supplier=supplier, default_price="12") child_product_1.link_to_parent(var_product, variables={"color": "red"}) child_product_2.link_to_parent(var_product, variables={"color": "blue"}) context = { "request": request, "prod": product, "var_prod": var_product if create_var_product else None, # TODO: Test also with variant products "sline": _get_source_line(request), "bline": _get_basket_line(request), "oline": order_line, "order": order, } return (engine, context)
def initialize_editor_view(view_name, placeholder_name, request=None): if request is None: request = RequestFactory().get("/") request.shop = get_default_shop() request.user = SuperUser() if hasattr(request.GET, "_mutable"): request.GET._mutable = True # Ahem request.GET.update({ "theme": FauxTheme.identifier, "view": view_name, "ph": placeholder_name }) with plugin_override(): with override_provides("xtheme", ["shuup_tests.xtheme.utils:FauxTheme"]): with override_current_theme_class(FauxTheme): yield EditorView(request=request, args=(), kwargs={})
def _get_template_engine_and_context(): engine = django.template.engines['jinja2'] assert isinstance(engine, django_jinja.backend.Jinja2) request = RequestFactory().get('/') request.shop = Shop(currency='USD', prices_include_tax=False) request.customer = AnonymousContact() request.person = request.customer context = { 'request': request, 'prod': Product(sku='6.0745'), # TODO: Test also with variant products 'sline': _get_source_line(request), 'bline': _get_basket_line(request), 'oline': _get_order_line(request), } return (engine, context)
def _get_template_engine_and_context(product_sku='6.0745', create_var_product=False): engine = django.template.engines['jinja2'] assert isinstance(engine, django_jinja.backend.Jinja2) shop = get_default_shop() shop.currency = 'USD' shop.prices_include_tax = False shop.save() request = RequestFactory().get('/') request.shop = shop request.customer = AnonymousContact() request.person = request.customer PriceDisplayOptions(include_taxes=False).set_for_request(request) tax = get_default_tax() create_default_tax_rule(tax) tax_class = get_default_tax_class() order, order_line = _get_order_and_order_line(request) product = create_product(sku=product_sku, shop=shop, tax_class=tax_class) if create_var_product: var_product = create_product(sku="32.9", shop=shop, tax_class=tax_class) child_product_1 = create_product(sku="4.50", shop=shop, tax_class=tax_class, supplier=get_default_supplier()) child_product_2 = create_product(sku="12.00", shop=shop, tax_class=tax_class, supplier=get_default_supplier()) child_product_1.link_to_parent(var_product, variables={"color": "red"}) child_product_2.link_to_parent(var_product, variables={"color": "blue"}) context = { 'request': request, 'prod': product, 'var_prod': var_product if create_var_product else None, # TODO: Test also with variant products 'sline': _get_source_line(request), 'bline': _get_basket_line(request), 'oline': order_line, 'order': order } return (engine, context)
def get_request(): request = RequestFactory().get('/') request.shop = Shop(currency='USD', prices_include_tax=False) request.customer = AnonymousContact() request.person = request.customer
def get_price_info(shop, customer, product, quantity): ctx_request = RequestFactory().get("/") ctx_request.shop = shop ctx_request.customer = (customer or AnonymousContact()) context = get_pricing_module().get_context_from_request(ctx_request) return product.get_price_info(context, quantity=quantity)