mirror of
https://github.com/openclassify/openclassify.git
synced 2026-03-11 18:55:29 -05:00
#1013 Remove Currency conventer when you posting ad
This commit is contained in:
parent
65be49c5aa
commit
3a40d90595
@ -13,6 +13,7 @@ return [
|
||||
'decline' => 'Decline',
|
||||
'extend' => 'Extend',
|
||||
'extend_all' => 'Extend All',
|
||||
'convert_currency' => 'Convert Currency',
|
||||
'categories' => 'Categories',
|
||||
'sub_category' => 'Sub Categories',
|
||||
'add_sub_category' => 'Add Sub Category',
|
||||
|
||||
@ -28,4 +28,5 @@ return [
|
||||
'pending_ad_status' => 'Your ad is pending approval by the Editor.',
|
||||
'extended' => ':number ad(s) has been extended successfully.',
|
||||
'category_not_exist' => 'This category does not exist anymore!',
|
||||
'currency_converted' => 'Currency Converted Successfully.',
|
||||
];
|
||||
|
||||
@ -116,9 +116,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function foreignCurrency($currency, $price, $curencies, $isUpdate, $settings)
|
||||
public function foreignCurrency($currency, $price, $isUpdate, $settings)
|
||||
{
|
||||
$currencies = explode(',', $curencies);
|
||||
$currencies = setting_value('visiosoft.module.advs::enabled_currencies');
|
||||
$foreign_currency = array();
|
||||
|
||||
$client = new Client();
|
||||
@ -128,18 +128,19 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
$foreign_currency[$currency] = (int)$price;
|
||||
} else {
|
||||
try {
|
||||
|
||||
$url = $currency . "_" . $currencyIn;
|
||||
$freecurrencykey = $settings->value('visiosoft.module.advs::free_currencyconverterapi_key');
|
||||
$response = $client->get('http://free.currencyconverterapi.com/api/v6/convert?q=' . $url . '&compact=y&apiKey=' . $freecurrencykey);
|
||||
|
||||
} catch (RequestException $e) {
|
||||
|
||||
if ($e->getResponse()->getStatusCode() == '200') {
|
||||
$response = \GuzzleHttp\json_decode($e->getResponse()->getBody()->getContents());
|
||||
$rate = $response->$url->val;
|
||||
$foreign_currency[$currencyIn] = $price * $rate;
|
||||
$freeCurrencyKey = $settings->value('visiosoft.module.advs::free_currencyconverterapi_key');
|
||||
$response = $client->get('http://free.currencyconverterapi.com/api/v6/convert?q='
|
||||
. $url . '&compact=y&apiKey=' . $freeCurrencyKey);
|
||||
if ($response->getStatusCode() == '200') {
|
||||
$response = (array)\GuzzleHttp\json_decode($response->getBody()->getContents());
|
||||
if (!empty($response)) {
|
||||
$rate = $response[$url]->val;
|
||||
$foreign_currency[$currencyIn] = $price * $rate;
|
||||
}
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->messages->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,7 +151,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
}
|
||||
$adv->foreign_currencies = json_encode($foreign_currency);
|
||||
$adv->save();
|
||||
|
||||
}
|
||||
|
||||
public function popularAdvs()
|
||||
|
||||
@ -77,6 +77,10 @@ class AdvTableBuilder extends TableBuilder
|
||||
'handler' => \Visiosoft\AdvsModule\Adv\Table\Handler\Extend::class,
|
||||
'class' => 'btn btn-info'
|
||||
],
|
||||
'convert_currency' => [
|
||||
'handler' => \Visiosoft\AdvsModule\Adv\Table\Handler\ConvertCurrency::class,
|
||||
'class' => 'btn btn-warning'
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv\Table\Handler;
|
||||
|
||||
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
|
||||
use Visiosoft\AdvsModule\Adv\Table\AdvTableBuilder;
|
||||
|
||||
|
||||
class ConvertCurrency extends ActionHandler
|
||||
{
|
||||
public function handle(AdvTableBuilder $builder, array $selected, SettingRepositoryInterface $settingRepository)
|
||||
{
|
||||
$model = $builder->getTableModel();
|
||||
|
||||
foreach ($selected as $id) {
|
||||
$entry = $model->newQuery()->find($id);
|
||||
$model->foreignCurrency($entry->currency, $entry->price, $id, $settingRepository);
|
||||
}
|
||||
if ($selected) {
|
||||
$this->messages->success(trans('visiosoft.module.advs::message.currency_converted'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -613,17 +613,21 @@ class AdvsController extends PublicController
|
||||
return redirect('/advs/edit_advs/' . $request->update_id)->with('cats_d', $cats_d)->with('request', $request);
|
||||
}
|
||||
|
||||
$foreign_currencies = new AdvModel();
|
||||
$isUpdate = $request->update_id;
|
||||
$foreign_currencies->foreignCurrency($request->currency, $request->price, $request->currencies, $isUpdate, $settings);
|
||||
|
||||
if ($adv->slug == "") {
|
||||
$events->dispatch(new CreateAd($request->update_id, $settings));//Create Notify
|
||||
} else {
|
||||
$events->dispatch(new EditAd($request->update_id, $settings, $adv));//Update Notify
|
||||
}
|
||||
|
||||
return redirect(route('advs_preview', [$request->update_id]));
|
||||
if ($adv->slug == "") { // Only preview when new
|
||||
return redirect(route('advs_preview', [$request->update_id]));
|
||||
} else {
|
||||
if ($isActiveDopings) {
|
||||
return redirect(route('add_doping', [$request->update_id]));
|
||||
} else {
|
||||
return redirect('/advs/adv/' . $request->update_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* New Create Adv */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user