Git Product home page Git Product logo

django_oscar_multicurrency's Introduction

django-oscar-multicurrency

Showcase Oscar application with multi-currency support.

It allows to switch basket currency and do purchases in any allowed currency.

Implementation described in the blog post on Metaclass website - https://metaclass.co/django_multicurrency.html

django_oscar_multicurrency's People

Contributors

dclimber avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django_oscar_multicurrency's Issues

Dashboard complaining about price_currency

price_currency = forms.ChoiceField(choices=CURRENCY_CHOICES)

If left this code as it is the dashboard start complaining about not filled values for Stock and pricing. This happens in my case because the default choice field widget has no empty value. This is why an empty extra form always change initial value for price_currency from None to first value from settings.OSCAR_CURRENCIES.

Just setting initial should help in this case.

price_currency = forms.ChoiceField(initial=settings.OSCAR_CURRENCIES[0], choices=CURRENCY_CHOICES)

Basket line shows warning about price change since adding to basket in wrong currency

Hi,

I have found uncovered case. When add a product to a basket and then change its price next time you open a basket you will see a warning about changing in price. The price will be in the wrong currency. This happens because the method get_warning doesn't take into account the line currency and asummes it always default.

The solution is to override the method and pass correct currency.

# apps/basket/models.py

class Line(AbstractLine):
    def get_warning(self):
        """
        Return a warning message about this basket line if one is applicable

        This could be things like the price has changed
        """
        if isinstance(self.purchase_info.availability, Unavailable):
            msg = "'%(product)s' is no longer available"
            return _(msg) % {'product': self.product.get_title()}

        if not self.price_incl_tax:
            return
        if not self.purchase_info.price.is_tax_known:
            return

        # Compare current price to price when added to basket
        current_price_incl_tax = self.purchase_info.price.incl_tax
        if current_price_incl_tax != self.price_incl_tax:
            product_prices = {
                'product': self.product.get_title(),
                'old_price': currency(self.price_incl_tax, self.price_currency),  # pass the line price currency
                'new_price': currency(current_price_incl_tax, self.price_currency)  # pass the line price currency
            }
            if current_price_incl_tax > self.price_incl_tax:
                warning = _("The price of '%(product)s' has increased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices
            else:
                warning = _("The price of '%(product)s' has decreased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.