本文整理汇总了Python中shoop.front.basket.get_basket函数的典型用法代码示例。如果您正苦于以下问题:Python get_basket函数的具体用法?Python get_basket怎么用?Python get_basket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_basket函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_only_cheapest_price_is_selected
def test_only_cheapest_price_is_selected(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount1 = "10"
discount2 = "20" # should be selected
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount1, active=True
)
campaign.conditions.add(rule)
campaign.save()
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount2, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2
line_types = [l.type for l in basket.get_final_lines()]
assert OrderLineType.DISCOUNT in line_types
for line in basket.get_final_lines():
if line.type == OrderLineType.DISCOUNT:
assert line.discount_amount == price(discount2)
开发者ID:luizgustavo90,项目名称:shoop,代码行数:35,代码来源:test_basket_campaigns.py
示例2: test_basket_shipping_error
def test_basket_shipping_error(rf):
StoredBasket.objects.all().delete()
shop = get_default_shop()
supplier = get_default_supplier()
shipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.SHIPPED
)
unshipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.NOT_SHIPPED
)
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
# With a shipped product but no shipping methods, we oughta get an error
basket.add_product(supplier=supplier, shop=shop, product=shipped_product, quantity=1)
assert any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
basket.clear_all()
# But with an unshipped product, we should not
basket.add_product(supplier=supplier, shop=shop, product=unshipped_product, quantity=1)
assert not any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
开发者ID:00WhengWheng,项目名称:shuup,代码行数:27,代码来源:test_basket.py
示例3: test_percentage_campaign
def test_percentage_campaign(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount_percentage = "0.1"
expected_discounted_price = price(product_price) - (price(product_price) * Decimal(discount_percentage))
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_percentage=discount_percentage, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2
assert basket.product_count == 1
assert basket.total_price == expected_discounted_price
开发者ID:luizgustavo90,项目名称:shoop,代码行数:27,代码来源:test_basket_campaigns.py
示例4: _get_order_with_coupon
def _get_order_with_coupon(request, initial_status, condition_product_count=1):
shop = request.shop
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test",
public_name="test",
coupon=dc,
discount_amount_value=shop.create_price("20"),
active=True
)
rule = BasketTotalProductAmountCondition.objects.create(value=1)
campaign.conditions.add(rule)
campaign.save()
basket.add_code(dc.code)
basket.save()
basket.status = initial_status
creator = OrderCreator(request)
order = creator.create_order(basket)
assert order.lines.count() == 2
assert OrderLineType.DISCOUNT in [l.type for l in order.lines.all()]
return order
开发者ID:NinaWelch,项目名称:shoop,代码行数:28,代码来源:test_order_edit_with_coupons.py
示例5: test_contact_group_basket_condition_with_none
def test_contact_group_basket_condition_with_none(rf):
request = rf.get("/")
request.shop = Shop()
basket = get_basket(request)
condition = ContactGroupBasketCondition.objects.create()
result = condition.matches(basket) # Should not raise any errors
assert result is False
开发者ID:monokrome,项目名称:shuup,代码行数:7,代码来源:test_basket_contact_conditions.py
示例6: test_basket_campaign_module_case1
def test_basket_campaign_module_case1(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = "50"
discount_amount_value = "10"
# create basket rule that requires 2 products in basket
basket_rule1 = BasketTotalProductAmountCondition.objects.create(value="2")
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert basket.product_count == 1
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount_amount_value, active=True)
campaign.conditions.add(basket_rule1)
campaign.save()
assert len(basket.get_final_lines()) == 1 # case 1
assert basket.total_price == price(single_product_price) # case 1
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert len(basket.get_final_lines()) == 2 # case 1
assert basket.product_count == 2
assert basket.total_price == (price(single_product_price) * basket.product_count - price(discount_amount_value))
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
开发者ID:NARESHARADHYULA,项目名称:shoop,代码行数:35,代码来源:test_basket_campaigns.py
示例7: test_basket
def test_basket(rf, storage):
StoredBasket.objects.all().delete()
quantities = [3, 12, 44, 23, 65]
shop = get_default_shop()
get_default_payment_method() # Can't create baskets without payment methods
supplier = get_default_supplier()
products_and_quantities = []
for quantity in quantities:
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=50)
products_and_quantities.append((product, quantity))
is_database = (storage == "shoop.front.basket.storage:DatabaseBasketStorage")
with override_settings(SHOOP_BASKET_STORAGE_CLASS_SPEC=storage):
for product, q in products_and_quantities:
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
assert basket == request.basket
assert basket.product_count == 0
line = basket.add_product(supplier=supplier, shop=shop, product=product, quantity=q)
assert line.quantity == q
assert basket.get_lines()
assert basket.get_product_ids_and_quantities().get(product.pk) == q
assert basket.product_count == q
basket.save()
delattr(request, "basket")
basket = get_basket(request)
assert basket.get_product_ids_and_quantities().get(product.pk) == q
if is_database:
product_ids = set(StoredBasket.objects.last().products.values_list("id", flat=True))
assert product_ids == set([product.pk])
if is_database:
stats = StoredBasket.objects.all().aggregate(
n=Sum("product_count"),
tfs=Sum("taxful_total_price_value"),
tls=Sum("taxless_total_price_value"),
)
assert stats["n"] == sum(quantities)
if shop.prices_include_tax:
assert stats["tfs"] == sum(quantities) * 50
else:
assert stats["tls"] == sum(quantities) * 50
basket.finalize()
开发者ID:00WhengWheng,项目名称:shuup,代码行数:47,代码来源:test_basket.py
示例8: test_basket
def test_basket(rf):
shop = get_default_shop()
product = get_default_product()
supplier = get_default_supplier()
request = rf.get("/")
request.session = {}
request.shop = shop
basket = get_basket(request)
assert basket == request.basket
SimpleProductPrice.objects.get_or_create(shop=shop, product=product, defaults={"price": 50, "includes_tax": False})
line = basket.add_product(supplier=supplier, shop=shop, product=product, quantity=10)
assert line.quantity == 10
assert basket.get_lines()
assert basket.get_product_ids_and_quantities().get(product.pk) == 10
delattr(request, "basket")
basket = get_basket(request)
assert basket.get_product_ids_and_quantities().get(product.pk) == 10
开发者ID:charn,项目名称:shoop,代码行数:17,代码来源:test_basket.py
示例9: test_campaign_with_coupons
def test_campaign_with_coupons(rf):
status = get_initial_order_status()
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
for x in range(2):
product = create_product(printable_gibberish(), shop, supplier=supplier, default_price="50")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test", public_name="test",
coupon=dc,
discount_amount_value=shop.create_price("20"),
active=True
)
rule = BasketTotalProductAmountCondition.objects.create(value=2)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2 # no discount was applied because coupon is required
basket.add_code(dc.code)
assert len(basket.get_final_lines()) == 3 # now basket has codes so they will be applied too
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
# Ensure codes persist between requests, so do what the middleware would, i.e.
basket.save()
# and then reload the basket:
del request.basket
basket = get_basket(request)
assert basket.codes == [dc.code]
assert len(basket.get_final_lines()) == 3 # now basket has codes so they will be applied too
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
basket.status = status
creator = OrderCreator(request)
order = creator.create_order(basket)
assert CouponUsage.objects.filter(order=order).count() == 1
assert CouponUsage.objects.filter(order=order, coupon__code=dc.code).count() == 1
开发者ID:NinaWelch,项目名称:shoop,代码行数:44,代码来源:test_discount_codes.py
示例10: test_basket
def test_basket(rf, storage):
StoredBasket.objects.all().delete()
quantities = [3, 12, 44, 23, 65]
shop = get_default_shop()
supplier = get_default_supplier()
products_and_quantities = []
for quantity in quantities:
product = create_product(printable_gibberish(), shop=shop, supplier=supplier)
SimpleProductPrice.objects.get_or_create(
shop=shop, product=product, defaults={"price": 50, "includes_tax": False}
)
products_and_quantities.append((product, quantity))
is_database = (storage == "shoop.front.basket.storage:DatabaseBasketStorage")
with override_settings(SHOOP_BASKET_STORAGE_CLASS_SPEC=storage):
for product, q in products_and_quantities:
request = rf.get("/")
request.session = {}
request.shop = shop
basket = get_basket(request)
assert basket == request.basket
line = basket.add_product(supplier=supplier, shop=shop, product=product, quantity=q)
assert line.quantity == q
assert basket.get_lines()
assert basket.get_product_ids_and_quantities().get(product.pk) == q
basket.save()
delattr(request, "basket")
basket = get_basket(request)
assert basket.get_product_ids_and_quantities().get(product.pk) == q
if is_database:
product_ids = set(StoredBasket.objects.last().products.values_list("id", flat=True))
assert product_ids == set([product.pk])
if is_database:
stats = StoredBasket.objects.all().aggregate(
n=Sum("product_count"),
s=Sum("taxless_total"),
)
assert stats["n"] == sum(quantities)
assert stats["s"] == sum(quantities) * 50
开发者ID:jaywink,项目名称:shoop,代码行数:40,代码来源:test_basket.py
示例11: test_basket_total_amount_condition
def test_basket_total_amount_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product-Too", shop, default_price="200")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
condition = BasketTotalAmountCondition.objects.create()
condition.value = 1
condition.save()
assert condition.value == 1
assert condition.matches(basket, [])
开发者ID:monokrome,项目名称:shuup,代码行数:14,代码来源:test_basket_product_conditions.py
示例12: test_basket_total_value_condition
def test_basket_total_value_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product-Too", shop, default_price="200")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
condition = BasketTotalProductAmountCondition.objects.create()
condition.value = 1
condition.save()
assert condition.value == 1
assert condition.matches(basket, [])
assert "basket has at least the product count entered here" in force_text(condition.description)
开发者ID:monokrome,项目名称:shuup,代码行数:15,代码来源:test_basket_product_conditions.py
示例13: test_product_in_basket_condition
def test_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product-Too", shop, default_price="200")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
condition = ProductsInBasketCondition.objects.create()
condition.values = [product]
condition.save()
assert condition.values.first() == product
assert condition.matches(basket, [])
开发者ID:monokrome,项目名称:shuup,代码行数:16,代码来源:test_basket_product_conditions.py
示例14: test_basket_campaign_case2
def test_basket_campaign_case2(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
single_product_price = "50"
discount_amount_value = "10"
unique_shipping_method = ShippingMethod(tax_class=get_default_tax_class(), module_data={"price": 50})
unique_shipping_method.save()
for x in range(3):
product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price
)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert basket.product_count == 3
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount_amount_value, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 3
assert basket.total_price == price(single_product_price) * basket.product_count
# check that shipping method affects campaign
basket.shipping_method = unique_shipping_method
basket.save()
basket.uncache()
assert len(basket.get_final_lines()) == 4 # Shipping should not affect the rule being triggered
line_types = [l.type for l in basket.get_final_lines()]
assert OrderLineType.DISCOUNT not in line_types
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert len(basket.get_final_lines()) == 6 # Discount included
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
开发者ID:luizgustavo90,项目名称:shoop,代码行数:47,代码来源:test_basket_campaigns.py
示例15: test_basket_dirtying_with_fnl
def test_basket_dirtying_with_fnl(rf):
shop = get_default_shop()
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=50)
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
line = basket.add_product(
supplier=supplier,
shop=shop,
product=product,
quantity=1,
force_new_line=True,
extra={"foo": "foo"}
)
assert basket.dirty # The change should have dirtied the basket
开发者ID:00WhengWheng,项目名称:shuup,代码行数:18,代码来源:test_basket.py
示例16: test_basket_free_product_coupon
def test_basket_free_product_coupon(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = "50"
discount_amount_value = "10"
# create basket rule that requires 2 products in basket
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
second_product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
rule = BasketTotalProductAmountCondition.objects.create(value="2")
coupon = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(active=True, shop=shop, name="test", public_name="test", coupon=coupon)
campaign.conditions.add(rule)
effect = FreeProductLine.objects.create(campaign=campaign)
effect.products.add(second_product)
basket.add_code(coupon.code)
basket.uncache()
final_lines = basket.get_final_lines()
assert len(final_lines) == 2
line_types = [l.type for l in final_lines]
assert OrderLineType.DISCOUNT not in line_types
for line in basket.get_final_lines():
assert line.type == OrderLineType.PRODUCT
if line.product != product:
assert line.product == second_product
开发者ID:digideskio,项目名称:shuup,代码行数:42,代码来源:test_effects.py
示例17: create_basket_and_campaign
def create_basket_and_campaign(request, conditions, product_price_value, campaign_discount_value):
product = create_product(
"Some crazy product", request.shop, get_default_supplier(), default_price=product_price_value)
basket = get_basket(request)
basket.customer = request.customer
supplier = get_default_supplier()
basket.add_product(supplier=supplier, shop=request.shop, product=product, quantity=1)
original_line_count = len(basket.get_final_lines())
assert original_line_count == 1
assert basket.product_count == 1
original_price = basket.total_price
campaign = BasketCampaign.objects.create(
shop=request.shop, name="test", public_name="test", discount_amount_value=campaign_discount_value, active=True)
for condition in conditions:
campaign.conditions.add(condition)
assert campaign.is_available()
return basket, original_line_count, original_price
开发者ID:gs-ronak,项目名称:shoop,代码行数:20,代码来源:test_basket_contact_conditions.py
示例18: test_multiple_campaigns_match_with_coupon
def test_multiple_campaigns_match_with_coupon(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount1 = "10"
discount2 = "20"
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign = BasketCampaign.objects.create(shop=shop, public_name="test", name="test", active=True)
campaign.conditions.add(rule)
campaign.save()
BasketDiscountAmount.objects.create(discount_amount=discount1, campaign=campaign)
dc = Coupon.objects.create(code="TEST", active=True)
campaign2 = BasketCampaign.objects.create(
shop=shop, public_name="test",
name="test",
coupon=dc,
active=True
)
BasketDiscountAmount.objects.create(discount_amount=discount2, campaign=campaign2)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
resp = handle_add_campaign_code(request, basket, dc.code)
assert resp.get("ok")
discount_lines_values = [line.discount_amount for line in basket.get_final_lines()]
assert price(discount1) in discount_lines_values
assert price(discount2) in discount_lines_values
assert basket.total_price == (price(product_price) * basket.product_count - price(discount1) - price(discount2))
开发者ID:digideskio,项目名称:shuup,代码行数:41,代码来源:test_basket_campaigns.py
示例19: _set_basket
def _set_basket(self, request):
request.basket = get_basket(request)
开发者ID:NinaWelch,项目名称:shoop,代码行数:2,代码来源:middleware.py
注:本文中的shoop.front.basket.get_basket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论