Coder Social home page Coder Social logo

valicm / commerce_currency_resolver Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 222 KB

Drupal 8 Commerce multi currency module

Home Page: https://www.drupal.org/project/commerce_currency_resolver

PHP 100.00%
drupal drupal-commerce currency multi-currency drupal8 drupal-module

commerce_currency_resolver's Introduction

CONTENTS OF THIS FILE

  • Introduction
  • Requirements
  • Installation
  • Configuration
  • Exchange rates
  • Maintainers

INTRODUCTION

Enhancement for handling multi-currency in Drupal 8 for Drupal Commerce.

Drupal Commerce 2 supports multiple currencies out of the box. But only for adding prices, not resolving multiple currency prices/orders based on some criteria.

Commerce currency resolver tries to solve resolving prices per currency, calculating those prices and exchange rates between currencies.

REQUIREMENTS

This module requires Commerce Exchanger, Drupal Commerce 2 and it's submodule price.

INSTALLATION

Install the Commerce Currency Resolver module as you would normally install any Drupal contrib module. Visit https://www.drupal.org/node/1897420 for further information.

CONFIGURATION

1. Navigate to Administration > Extend and enable the Commerce Currency
   Resolver module.
2. Navigate to Home > Administration > Commerce > Configuration
               > Currency resolver.
3. Choose from available options settings to configure how currency should
   be resolved, how prices are calculated and default currency.
4. Navigate to the "Conversion" tab for configuration related
   to Exchange rates.
5. Navigate to the "Mapping" if available and selected which currency
   should be used per language or country.

CACHING

Currency resolver module works with "Internal Dynamic Page Cache" only.

Page Cache module needs to be disabled.

The Drupal core Page Cache module does not work with personalized "content". Dynamic Page Cache is built for that purpose.

Explanation - https://www.drupal.org/project/commerce_currency_resolver/issues/3042307#comment-13046326

EXCHANGE RATES

Handled trough Commerce Exchanger module https://www.drupal.org/project/commerce_exchanger

COMMERCE SHIPPING

If you are using commerce shipping there are two options how shipping methods can be set to work with currency resolver.

  • If you are using condition Order currency and the selected currency matches to the price currency selected under Rate amount then you don't need to do anything.
  • If you need to auto-calculate price or have multiple prices per shipping method you need enable submodule commerce_currency_resolver_shipping.

EXAMPLES

Adding order item programmatically

If you are adding order items programmatically in your code, you need take in account possible conflicts with prices. To avoid that is best that you using resolver to resolve prices for certain item to the cart.

Example below shows entire process in custom add to cart process, where we add item to the cart.

**
@var \Drupal\commerce_cart\CartManagerInterface $cart_manager */
$cart_manager = \Drupal::service('commerce_cart.cart_manager');

/** @var \Drupal\commerce_order\Resolver\OrderTypeResolverInterface $order_type_resolver */
$order_type_resolver = \Drupal::service('commerce_order.chain_order_type_resolver');

/** @var \Drupal\commerce_store\CurrentStoreInterface $current_store */
$current_store = \Drupal::service('commerce_store.current_store');

/** @var \Drupal\commerce_cart\CartProviderInterface $cart_provider */
$cart_provider = \Drupal::service('commerce_cart.cart_provider');

/** @var \Drupal\commerce_order\OrderItemStorage $order_item_storage */
$order_item_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_order_item');
$store = $current_store->getStore();

$context = $context = new Context(\Drupal::currentUser(), $store);
$resolved_price = \Drupal::service('commerce_currency_resolver.price_resolver')->resolve($product, 1, $context);
$order_item = $order_item_storage->createFromPurchasableEntity($product, ['unit_price' => $resolved_price]);

$order_type_id = $order_type_resolver->resolve($order_item);

$cart = $cart_provider->getCart($order_type_id, $store);
if (!$cart) {
  $cart = $cart_provider->createCart($order_type_id, $store);
}

$cart_manager->addOrderItem($cart, $order_item);

MAINTAINERS

The 8.x-1.x branch was created by:

This module was created and sponsored by Foreo, Swedish multi-national beauty brand.

commerce_currency_resolver's People

Contributors

valicm avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

commerce_currency_resolver's Issues

Unable to get this work as shown in the documentation page

Hi valic, sorry to bring this issue here but for some reason, drupal.org was preventing me from replying back to your comment and kept showing error messages.

In response to your message, I did the following.

I have install smart_ip and configure it. Currency Resolver with smart IP

I used VPN to test it and it works. However, the following still happens

Using NordVPN I change to the location to France, in admin/commerce/config/commerce_currency_resolver/mapping I map France to Euro. Mapping

(1) In product page still shows default currency which is "GBP(£)" Product view
(2) On the cart page, it shows the total value of the cart in "EURO" Cart page
(3) On the order summary page, the value is shown in "GBP(£)" Order Summary Page

This is how my product variation is set up. Product variation Structure
I am super confused has to what is going on. Why the product page still defaults to GBP.

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.