示例#1
0
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 = CgpPrice(product=product_one,
                   shop=shop,
                   group=group,
                   price_value=100)
    spp.save()

    spp = CgpPrice(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, CustomerGroupPricingModule)
    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)
示例#2
0
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
0
 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
0
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
示例#5
0
文件: create.py 项目: sebad78/shoop
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)
示例#6
0
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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
    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)
示例#10
0
文件: create.py 项目: RF-77/shoop
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)
示例#11
0
文件: create.py 项目: hanoibee/shoop
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)
示例#12
0
    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)
示例#13
0
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')
示例#14
0
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
示例#15
0
def test_module_is_active():
    """
    Check that DiscountPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, DiscountPricingModule)
示例#16
0
def test_module_is_active():
    """
    Check that DiscountPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, DiscountPricingModule)
示例#17
0
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)
示例#18
0
def test_module_is_active():
    """
    Check that SimplePricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, SimplePricingModule)
示例#19
0
    def get_base_price(self):
        from shoop.core.pricing import get_pricing_module

        module = get_pricing_module()
        return module.get_base_price(product_id=self.pk)
示例#20
0
文件: create.py 项目: LuanaF/shoop
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)
示例#21
0
 def get_base_price(self):
     from shoop.core.pricing import get_pricing_module
     module = get_pricing_module()
     return module.get_base_price(product_id=self.pk)
示例#22
0
def _get_pricing_context(shop, customer=None):
    return get_pricing_module().get_context_from_data(
        shop=shop,
        customer=(customer or AnonymousContact()),
    )
示例#23
0
def test_module_is_active():
    """
    Check that SimplePricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, SimplePricingModule)
示例#24
0
def test_module_is_active():
    """
    Check that CustomerGroupPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, CustomerGroupPricingModule)
示例#25
0
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)
def test_module_is_active():
    """
    Check that CustomerGroupPricingModule is active.
    """
    module = get_pricing_module()
    assert isinstance(module, CustomerGroupPricingModule)
示例#27
0
def _get_pricing_context(shop, customer=None):
    return get_pricing_module().get_context_from_data(
        shop=shop,
        customer=(customer or AnonymousContact()),
    )
示例#28
0
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)
示例#29
0
文件: contexts.py 项目: Jeewes/shoop
 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),
     )
示例#30
0
 def from_request(cls, request):
     return cls(pricing_context=get_pricing_module().get_context(request),
                taxing_context=get_tax_module().get_context(request))