File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/SiteConfig/MemberPriceComposer.php
<?php
namespace App\KommaApp\SiteConfig;
use App\KommaApp\WeFact\WeFactService;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
class MemberPriceComposer
{
public static $memberPrice;
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
// Only load the magazines if the static isn't filled yet
if(!static::$memberPrice){
// Preload the member price from the db
$dbMemberPrice = DB::table('site_config')->where('code_name', 'memberPrice')->first();
try {
/** @var WeFactService $weFactService */
$weFactService = app()->make(WeFactService::class);
// Get member product
$product = $weFactService->getProduct(config('site.membershipProductCode'));
self::$memberPrice = $product->PriceExcl;
// Log::info(self::class. ': Price loaded from WeFact');
// Check if we need to update the database value
if($dbMemberPrice->value != $product->PriceExcl) {
DB::table('site_config')->where('code_name','memberPrice')->update(['value' => $product->PriceExcl]);
}
}
catch (\Exception $e) {
Log::error(self::class. ': Something went wrong when loading the membership price');
// Set the member price from the db value
self::$memberPrice = $dbMemberPrice->value;
}
}
$view->with('composedMemberPrice', static::$memberPrice);
}
}