本文整理汇总了Python中shuup.front.basket.get_basket函数的典型用法代码示例。如果您正苦于以下问题:Python get_basket函数的具体用法?Python get_basket怎么用?Python get_basket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_basket函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parallel_baskets
def test_parallel_baskets(rf):
request = get_request_with_basket()
shop = get_default_shop()
customer = create_random_person()
request = rf.get("/")
request.shop = shop
apply_request_middleware(request)
request.customer = customer
basket_one = get_basket(request, basket_name="basket_one")
basket_two = get_basket(request, basket_name="basket_two")
product_one = get_default_product()
product_two = get_default_product()
product_two.sku = "derpy-hooves"
sales_unit = SalesUnit.objects.create(identifier="test-sales-partial", decimals=2, name="Partial unit")
product_two.sales_unit = sales_unit # Set the sales unit for the product
product_two.save()
basket_commands.handle_add(request, basket_one, product_id=product_one.pk, quantity=1)
basket_commands.handle_add(request, basket_two, product_id=product_two.pk, quantity=3.5)
assert basket_one.product_count == 1
assert basket_two.product_count == 3.5
开发者ID:suutari-ai,项目名称:shuup,代码行数:25,代码来源:test_basket_commands.py
示例2: 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 == "shuup.front.basket.storage:DatabaseBasketStorage")
with override_settings(SHUUP_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)
basket.shipping_method = get_shipping_method(shop=shop) # For shippable product
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:suutari,项目名称:shoop,代码行数:48,代码来源:test_basket.py
示例3: test_stripe_checkout_phase
def test_stripe_checkout_phase(rf, stripe_payment_processor):
request = rf.get("/")
request.shop = get_default_shop()
request.session = {}
request.basket = get_basket(request)
service = stripe_payment_processor.create_service(
None, shop=request.shop, tax_class=get_default_tax_class(),
enabled=True)
checkout_phase = StripeCheckoutPhase(
request=request, service=service)
assert not checkout_phase.is_valid() # We can't be valid just yet
context = checkout_phase.get_context_data()
assert context["stripe"]
request.method = "POST"
token = get_stripe_token(stripe_payment_processor)
request.POST = {
"stripeToken": token["id"],
"stripeTokenType": token["type"],
"stripeTokenEmail": token.get("email"),
}
checkout_phase.post(request)
assert checkout_phase.is_valid() # We should be valid now
assert request.session # And things should've been saved into the session
checkout_phase.process() # And this should do things to the basket
assert request.basket.payment_data.get("stripe")
开发者ID:farzeni,项目名称:shuup-stripe,代码行数:25,代码来源:test_stripe.py
示例4: test_productfilter_works
def test_productfilter_works(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
product_price = "100"
discount_percentage = "0.30"
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
shop_product = product.get_shop_instance(shop)
# create catalog campaign
catalog_filter = ProductFilter.objects.create()
catalog_filter.products.add(product)
assert catalog_filter.matches(shop_product)
catalog_campaign = CatalogCampaign.objects.create(shop=shop, active=True, name="test")
catalog_campaign.filters.add(catalog_filter)
cdp = ProductDiscountPercentage.objects.create(campaign=catalog_campaign, discount_percentage=discount_percentage)
# add product to basket
basket = get_basket(request)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop)
basket.save()
expected_total = price(product_price) - (Decimal(discount_percentage) * price(product_price))
assert basket.total_price == expected_total
开发者ID:gurch101,项目名称:shuup,代码行数:28,代码来源:test_filters.py
示例5: test_campaign_with_coupons1
def test_campaign_with_coupons1(rf):
basket, dc, request, status = _init_basket_coupon_test(rf)
assert len(basket.get_final_lines()) == 3 # no discount was applied because coupon is required
basket.add_code(dc.code)
assert len(basket.get_final_lines()) == 4 # 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:gurch101,项目名称:shuup,代码行数:25,代码来源:test_discount_codes.py
示例6: test_basket_orderability_change_shop_product
def test_basket_orderability_change_shop_product(rf):
StoredBasket.objects.all().delete()
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 len(basket.get_lines()) == 1
assert len(basket.get_unorderable_lines()) == 0
product.get_shop_instance(shop).delete()
basket.uncache()
assert basket.dirty
assert len(basket.get_lines()) == 0
assert len(basket.get_unorderable_lines()) == 1
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:test_basket.py
示例7: test_basket_total_undiscounted_value_conditions
def test_basket_total_undiscounted_value_conditions(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product("Just-A-Product", shop, default_price="150", supplier=supplier)
discounted_product = create_product("Just-A-Second-Product", shop, default_price="200", supplier=supplier)
# CatalogCampaign
catalog_campaign = CatalogCampaign.objects.create(active=True, shop=shop, name="test", public_name="test")
# Limit catalog campaign to "discounted_product"
product_filter = ProductFilter.objects.create()
product_filter.products.add(discounted_product)
catalog_campaign.filters.add(product_filter)
basket.add_product(supplier=supplier, shop=shop, product=discounted_product, quantity=1)
condition = BasketTotalUndiscountedProductAmountCondition.objects.create()
condition.value = 1
condition.save()
assert not condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert condition.matches(basket, [])
# Too high amount for undiscounted value
condition.value = 151
condition.save()
assert not condition.matches(basket, [])
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:test_basket_product_conditions.py
示例8: 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 at least 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", active=True)
campaign.conditions.add(rule)
campaign.save()
BasketDiscountPercentage.objects.create(campaign=campaign, discount_percentage=discount_percentage)
assert len(basket.get_final_lines()) == 2
assert basket.product_count == 1
assert basket.total_price == expected_discounted_price
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:28,代码来源:test_basket_campaigns.py
示例9: 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:NamiStudio,项目名称:shuup,代码行数:27,代码来源:test_basket.py
示例10: test_contact_group_basket_condition_with_none
def test_contact_group_basket_condition_with_none(rf):
request = apply_request_middleware(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:ruqaiya,项目名称:shuup,代码行数:7,代码来源:test_basket_contact_conditions.py
示例11: 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)
campaign1 = BasketCampaign.objects.create(shop=shop, public_name="test", name="test", active=True)
campaign1.conditions.add(rule)
campaign1.save()
BasketDiscountAmount.objects.create(discount_amount=discount1, campaign=campaign1)
campaign2 = BasketCampaign.objects.create(shop=shop, public_name="test", name="test", active=True)
campaign2.conditions.add(rule)
campaign2.save()
BasketDiscountAmount.objects.create(discount_amount=discount2, campaign=campaign2)
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:hrayr-artunyan,项目名称:shuup,代码行数:34,代码来源:test_basket_campaigns.py
示例12: basket
def basket(self):
"""
The basket used in this checkout process.
:rtype: shuup.front.basket.objects.BaseBasket
"""
return get_basket(self.request)
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:_process.py
示例13: test_category_product_in_basket_condition
def test_category_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
category = get_default_category()
product = create_product("The Product", shop=shop, default_price="200", supplier=supplier)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
shop_product = product.get_shop_instance(shop)
assert category not in shop_product.categories.all()
condition = CategoryProductsBasketCondition.objects.create(
category=category, operator=ComparisonOperator.EQUALS, quantity=1)
# No match the product does not have the category
assert not condition.matches(basket, [])
shop_product.categories.add(category)
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
condition.operator = ComparisonOperator.GTE
condition.save()
assert condition.matches(basket, [])
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:27,代码来源:test_basket_category_products_campaigns.py
示例14: 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, [])
condition.quantity = 2
condition.save()
assert not condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert condition.matches(basket, [])
condition.operator = ComparisonOperator.EQUALS
condition.save()
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
开发者ID:NamiStudio,项目名称:shuup,代码行数:32,代码来源:test_basket_product_conditions.py
示例15: _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)
basket.shipping_method = get_shipping_method(shop=shop) # For shippable products
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test",
public_name="test",
coupon=dc,
active=True
)
BasketDiscountAmount.objects.create(discount_amount=shop.create_price("20"), campaign=campaign)
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() == 3
assert OrderLineType.DISCOUNT in [l.type for l in order.lines.all()]
return order
开发者ID:gurch101,项目名称:shuup,代码行数:31,代码来源:test_order_edit_with_coupons.py
示例16: test_product_in_basket_condition_with_variation_parent
def test_product_in_basket_condition_with_variation_parent(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product(
"test-product", shop, default_price="200", supplier=supplier, mode=ProductMode.SIMPLE_VARIATION_PARENT)
child_products = []
for x in range(0, 3):
child_product = create_product("test-product-%s" % x, shop, default_price="10", supplier=supplier)
child_product.link_to_parent(product)
child_products.append(child_product)
condition = ProductsInBasketCondition.objects.create()
condition.values = [product]
condition.operator = ComparisonOperator.EQUALS
condition.quantity = 3
condition.save()
assert not condition.matches(basket, [])
for child_product in child_products:
basket.add_product(supplier=supplier, shop=shop, product=child_product, quantity=1)
assert condition.matches(basket, [])
开发者ID:ruqaiya,项目名称:shuup,代码行数:27,代码来源:test_basket_product_conditions.py
示例17: test_category_product_in_basket_condition
def test_category_product_in_basket_condition(rf):
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
category = get_default_category()
product = create_product("The Product", shop=shop, default_price="200", supplier=supplier)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop)
shop_product = product.get_shop_instance(shop)
assert category not in shop_product.categories.all()
condition = CategoryProductsBasketCondition.objects.create(operator=ComparisonOperator.EQUALS, quantity=1)
condition.categories.add(category)
# No match the product does not have the category
assert not condition.matches(basket, [])
category.shop_products.add(shop_product)
assert condition.matches(basket, [])
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
assert not condition.matches(basket, [])
condition.operator = ComparisonOperator.GTE
condition.save()
assert condition.matches(basket, [])
condition.excluded_categories.add(category)
assert not condition.matches(basket, [])
with pytest.raises(CampaignsInvalidInstanceForCacheUpdate):
update_filter_cache("test", shop)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:test_basket_category_products_campaigns.py
示例18: test_basket_total_amount_conditions
def test_basket_total_amount_conditions(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, [])
condition2 = BasketMaxTotalAmountCondition.objects.create()
condition2.value = 200
condition2.save()
assert condition2.matches(basket, [])
condition2.value = 199
condition2.save()
assert not condition2.matches(basket, [])
开发者ID:NamiStudio,项目名称:shuup,代码行数:25,代码来源:test_basket_product_conditions.py
示例19: test_basket_campaign_with_multiple_supppliers
def test_basket_campaign_with_multiple_supppliers(rf):
request, shop, group = initialize_test(rf, False)
supplier1 = Supplier.objects.create(identifier="1")
supplier2 = Supplier.objects.create(identifier="2")
price = shop.create_price
basket = get_basket(request)
single_product_price = "50"
discount_amount_supplier1 = "10"
discount_amount_supplier2 = "40"
product1 = create_product("product1", shop=shop, supplier=supplier1, default_price=single_product_price)
product2 = create_product("product2", shop=shop, supplier=supplier2, default_price=single_product_price)
basket.add_product(supplier=supplier1, shop=shop, product=product1, quantity=1)
basket.add_product(supplier=supplier2, shop=shop, product=product2, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop)
basket.save()
assert basket.product_count == 2
assert basket.total_price.value == 100
# Create campaign for supplier one
basket_rule1 = ProductsInBasketCondition.objects.create(quantity=1)
basket_rule1.products.add(product1)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", active=True, supplier=supplier1)
campaign.conditions.add(basket_rule1)
campaign.save()
BasketDiscountAmount.objects.create(
campaign=campaign, discount_amount=discount_amount_supplier1)
basket.uncache()
lines = basket.get_final_lines()
assert len(lines) == 4
assert basket.total_price.value == 90 # 10d discount from the supplier1 product
line = _get_discount_line(lines, 10)
assert line.supplier == supplier1
# Create campaign for supplier two
basket_rule2 = ProductsInBasketCondition.objects.create(quantity=1)
basket_rule2.products.add(product2)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", active=True, supplier=supplier2)
campaign.conditions.add(basket_rule2)
campaign.save()
BasketDiscountAmount.objects.create(
campaign=campaign, discount_amount=discount_amount_supplier2)
basket.uncache()
lines = basket.get_final_lines()
assert len(lines) == 5
assert basket.total_price.value == 50 # -10d - 40d from 100d
line = _get_discount_line(lines, 40)
assert line.supplier == supplier2
开发者ID:ruqaiya,项目名称:shuup,代码行数:59,代码来源:test_supplier_campaigns.py
示例20: 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)
basket.shipping_method = get_shipping_method(shop=shop) # For shippable products
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test", public_name="test",
coupon=dc,
active=True
)
BasketDiscountAmount.objects.create(discount_amount=shop.create_price("20"), campaign=campaign)
rule = BasketTotalProductAmountCondition.objects.create(value=2)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 3 # no discount was applied because coupon is required
basket.add_code(dc.code)
assert len(basket.get_final_lines()) == 4 # 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:suutari,项目名称:shoop,代码行数:45,代码来源:test_discount_codes.py
注:本文中的shuup.front.basket.get_basket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论