Skip to content

Commit

Permalink
[Updated: readme.md file and support for multi currency and locale.]
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-webkul committed Dec 15, 2022
1 parent 1f514ab commit 52b3262
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This changelog consists of the bug & security fixes and new features included in the releases listed below.

## **v1.4.4 (15th of December, 2022)** - *Release*

* [enhancement] - Currency and Locale converter functionality should be work, (use x-currency and x-locale in request header).

* [Fix] - Getting issue in notifications (https://prnt.sc/c2Oj8RZQktCR).

## **v1.4.3 (12th of December, 2022)** - *Release*

* [enhancement] - Order Cancellation API query added for log-in customer.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ composer require bagisto/graphql-api
php artisan bagisto_graphql:install
~~~

* add the below-line inside the **modules** index in **config/concord.php** file:

~~~
\Webkul\GraphQLAPI\Providers\ModuleServiceProvider::class,
~~~

##### Find a file config/lighthouse.php from root and do the following changes:

* change the **guard** index value from **api** to **admin-api** like below mentioned:
Expand Down
49 changes: 49 additions & 0 deletions src/Http/Middleware/CurrencyMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Webkul\GraphQLAPI\Http\Middleware;

use Closure;
use Webkul\Core\Repositories\CurrencyRepository;

class CurrencyMiddleware
{
/**
* Currency repository.
*
* @var \Webkul\Core\Repositories\CurrencyRepository
*/
protected $currencyRepository;

/**
* Create a middleware instance.
*
* @param \Webkul\Core\Repositories\CurrencyRepository $locale
* @return void
*/
public function __construct(CurrencyRepository $currencyRepository)
{
$this->currencyRepository = $currencyRepository;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$currencyCode = $request->header('x-currency');

if ($currencyCode && $this->currencyRepository->findOneByField('code', $currencyCode)) {
core()->setCurrency($currencyCode);

return $next($request);
}

core()->setCurrency(core()->getChannelBaseCurrencyCode());

return $next($request);
}
}
50 changes: 50 additions & 0 deletions src/Http/Middleware/LocaleMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Webkul\GraphQLAPI\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Webkul\Core\Repositories\LocaleRepository;

class LocaleMiddleware
{
/**
* Locale repository.
*
* @var \Webkul\Core\Repositories\LocaleRepository
*/
protected $localeRepository;

/**
* Create a middleware instance.
*
* @param \Webkul\Core\Repositories\LocaleRepository $localeRepository
* @return void
*/
public function __construct(LocaleRepository $localeRepository)
{
$this->localeRepository = $localeRepository;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$localeCode = $request->header('x-locale');

if ($localeCode && $this->localeRepository->findOneByField('code', $localeCode)) {
app()->setLocale($localeCode);

return $next($request);
}

app()->setLocale(core()->getDefaultChannel()->default_locale->code);

return $next($request);
}
}
9 changes: 8 additions & 1 deletion src/Providers/GraphQLAPIServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Webkul\GraphQLAPI\Providers;

use Illuminate\Routing\Router;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Webkul\BookingProduct\Type\Booking as BaseBookingType;
use Webkul\GraphQLAPI\BagistoGraphql;
use Webkul\GraphQLAPI\Console\Commands\Install;
use Webkul\GraphQLAPI\Facades\BagistoGraphql as BagistoGraphqlFacade;
use Webkul\GraphQLAPI\Type\Booking as GraphQLAPIBookingType;
use Webkul\GraphQLAPI\Http\Middleware\LocaleMiddleware;
use Webkul\GraphQLAPI\Http\Middleware\CurrencyMiddleware;

class GraphQLAPIServiceProvider extends ServiceProvider
{
Expand All @@ -18,7 +21,7 @@ class GraphQLAPIServiceProvider extends ServiceProvider
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function boot()
public function boot(Router $router)
{
include __DIR__ . '/../Http/helpers.php';

Expand All @@ -35,6 +38,10 @@ public function boot()

$this->publishesDefault();

/* aliases */
$router->aliasMiddleware('locale', LocaleMiddleware::class);
$router->aliasMiddleware('currency', CurrencyMiddleware::class);

if (request()->hasHeader('authorization')) {
$headerValue = explode('Bearer ', request()->header('authorization'));

Expand Down
4 changes: 4 additions & 0 deletions src/graphql/catalog/product.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ type Product {
type: String!
attributeFamilyId: Int! @rename(attribute: "attribute_family_id")
sku: String!
url_key: String!
name: String!
description: String!
shortDescription: String! @rename(attribute: "short_description")
parentId: ID @rename(attribute: "parent_id")
createdAt: DateTime @rename(attribute: "created_at")
updatedAt: DateTime @rename(attribute: "updated_at")
Expand Down

0 comments on commit 52b3262

Please sign in to comment.