本文整理汇总了Python中shoop.core.pricing.get_pricing_module函数的典型用法代码示例。如果您正苦于以下问题:Python get_pricing_module函数的具体用法?Python get_pricing_module怎么用?Python get_pricing_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_pricing_module函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_price_infos_are_discounted
def test_price_infos_are_discounted(rf):
request = initialize_test(rf, True)
price = request.shop.create_price
product_one = create_product("Product_1", request.shop, default_price=150)
product_two = create_product("Product_2", request.shop, default_price=250)
spp = DiscountedProductPrice(product=product_one, shop=request.shop, price_value=100)
spp.save()
spp = DiscountedProductPrice(product=product_two, shop=request.shop, price_value=200)
spp.save()
product_ids = [product_one.pk, product_two.pk]
dpm = get_pricing_module()
pricing_context = dpm.get_context_from_request(request)
price_infos = dpm.get_price_infos(pricing_context, product_ids)
assert len(price_infos) == 2
assert product_one.pk in price_infos
assert product_two.pk in price_infos
first_price_info = price_infos[product_one.pk]
second_price_info = price_infos[product_two.pk]
assert first_price_info.price == price(100)
assert first_price_info.base_price == price(150)
assert first_price_info.is_discounted
assert second_price_info.price == price(200)
assert second_price_info.base_price == price(250)
assert second_price_info.is_discounted
示例2: test_price_infos
def test_price_infos(rf):
request, shop, group = initialize_test(rf, True)
price = shop.create_price
product_one = create_product("Product_1", shop, default_price=150)
product_two = create_product("Product_2", shop, default_price=250)
spp = SimpleProductPrice(product=product_one, shop=shop, group=group, price_value=100)
spp.save()
spp = SimpleProductPrice(product=product_two, shop=shop, group=group, price_value=200)
spp.save()
product_ids = [product_one.pk, product_two.pk]
spm = get_pricing_module()
assert isinstance(spm, SimplePricingModule)
pricing_context = spm.get_context_from_request(request)
price_infos = spm.get_price_infos(pricing_context, product_ids)
assert len(price_infos) == 2
assert product_one.pk in price_infos
assert product_two.pk in price_infos
assert price_infos[product_one.pk].price == price(100)
assert price_infos[product_two.pk].price == price(200)
assert price_infos[product_one.pk].base_price == price(100)
assert price_infos[product_two.pk].base_price == price(200)
示例3: handle_product_data
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
}
}
示例4: get_price_info
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)
示例5: get_price
def get_price(self, context, quantity=1):
"""
:type context: shoop.core.contexts.PriceTaxContext
:rtype: shoop.core.pricing.Price
"""
from shoop.core.pricing import get_pricing_module
module = get_pricing_module()
pricing_context = module.get_context(context)
return module.get_price(pricing_context, product_id=self.pk, quantity=quantity)
示例6: get_price_info
def get_price_info(self, context, quantity=1):
"""
returns a `PriceInfo` object for product
Returned `PriceInfo` object contains calculated `price` and `base_price`.
The calculation of prices is handled in the current pricing module.
:type context: shoop.core.contexts.PriceTaxContext
:rtype: shoop.core.pricing.PriceInfo
"""
from shoop.core.pricing import get_pricing_module
module = get_pricing_module()
pricing_context = module.get_context(context)
return module.get_price_info(pricing_context, product=self, quantity=quantity)
示例7: get_price_info
def get_price_info(shop, customer, product, quantity):
"""
Get price info of given product for given context parameters.
:type shop: shoop.core.models.Shop
:type customer: shoop.core.models.Contact
:type product: shoop.core.models.Product
:type quantity: numbers.Number
"""
pricing_mod = get_pricing_module()
pricing_ctx = pricing_mod.get_context_from_data(
shop=shop,
customer=(customer or AnonymousContact()),
)
return pricing_mod.get_price_info(pricing_ctx, product, quantity=quantity)
示例8: test_pricing_module_is_active
def test_pricing_module_is_active():
"""
Make sure that our custom pricing module is active.
"""
shop = Shop(currency='USD', prices_include_tax=False)
customer = AnonymousContact()
product = Product(sku='6.0745')
pricing_mod = get_pricing_module()
pricing_ctx = pricing_mod.get_context_from_data(shop, customer)
pi = product.get_price_info(pricing_ctx, quantity=2)
price = shop.create_price
assert pi.price == price('12.149')
assert pi.base_price == price('48.596')
assert pi.quantity == 2
assert pi.discounted_unit_price == price('6.0745')
assert pi.base_unit_price == price('24.298')
assert pi.discount_rate == Decimal('0.75')
示例9: test_module_is_active
def test_module_is_active(): # this test is because we want to make sure `SimplePricing` is active
module = get_pricing_module()
assert isinstance(module, DefaultPricingModule)
示例10: test_module_is_active
def test_module_is_active():
"""
Check that DiscountPricingModule is active.
"""
module = get_pricing_module()
assert isinstance(module, DiscountPricingModule)
示例11: test_module_is_active
def test_module_is_active():
"""
Check that SimplePricingModule is active.
"""
module = get_pricing_module()
assert isinstance(module, SimplePricingModule)
示例12: test_module_is_active
def test_module_is_active():
"""
Check that CustomerGroupPricingModule is active.
"""
module = get_pricing_module()
assert isinstance(module, CustomerGroupPricingModule)
示例13: _get_pricing_context
def _get_pricing_context(shop, customer=None):
return get_pricing_module().get_context_from_data(
shop=shop,
customer=(customer or AnonymousContact()),
)
示例14: from_request
def from_request(cls, request):
return cls(
pricing_context=get_pricing_module().get_context_from_request(request),
taxing_context=get_tax_module().get_context_from_request(request),
)
示例15: get_price_info
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)