Skip to content

Commit 6fe8521

Browse files
committed
[TASK] add is_enabled on currency, see #7 + [TASK] stylings on settings page, see #10 + [FIX]
1 parent 2d001c8 commit 6fe8521

24 files changed

+347
-144
lines changed

classes/index/ProductEntry.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function withData(array $data): Entry
6161
protected function mapPrices(Product $product): Collection
6262
{
6363
return $product->withForcedPriceInheritance(function() use ($product) {
64-
return Currency::getAll()->mapWithKeys(function ($currency) use ($product) {
64+
return Currency::enabled()->getAll()->mapWithKeys(function ($currency) use ($product) {
6565
return [$currency->code => $product->price($currency)->integer];
6666
});
6767
});
@@ -71,7 +71,7 @@ protected function mapCustomerGroupPrices($model): Collection
7171
{
7272
return CustomerGroup::get()->mapWithKeys(function ($group) use ($model) {
7373
return [
74-
$group->id => Currency::getAll()->mapWithKeys(function ($currency) use ($model, $group) {
74+
$group->id => Currency::enabled()->getAll()->mapWithKeys(function ($currency) use ($model, $group) {
7575
$price = $model->groupPrice($group, $currency);
7676
if ($price) {
7777
return [$price->currency->code => $price->integer];

classes/index/VariantEntry.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function withData(array $data): Entry
6969
protected function mapPrices($variant): Collection
7070
{
7171
return $variant->withForcedPriceInheritance(function () use ($variant) {
72-
return Currency::getAll()->mapWithKeys(function ($currency) use ($variant) {
72+
return Currency::enabled()->getAll()->mapWithKeys(function ($currency) use ($variant) {
7373
return [$currency->code => $variant->price($currency)->integer];
7474
});
7575
});
@@ -79,7 +79,7 @@ protected function mapCustomerGroupPrices($model): Collection
7979
{
8080
return CustomerGroup::get()->mapWithKeys(function ($group) use ($model) {
8181
return [
82-
$group->id => Currency::getAll()->mapWithKeys(function ($currency) use ($model, $group) {
82+
$group->id => Currency::enabled()->getAll()->mapWithKeys(function ($currency) use ($model, $group) {
8383
$price = $model->groupPrice($group, $currency);
8484
if ($price) {
8585
return [$price->currency->code => $price->integer];

classes/traits/CustomFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait CustomFields
2121
*/
2222
public function priceIncludingCustomFieldValues(?Collection $values = null): array
2323
{
24-
$currencies = Currency::get();
24+
$currencies = Currency::enabled()->get();
2525
if ( ! $values || count($values) < 1) {
2626
return $currencies->mapWithKeys(function (Currency $currency) {
2727
return [$currency->code => $this->price($currency)->integer];

classes/traits/HashIds.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getHashIdAttribute()
2222
*/
2323
public function decode($value)
2424
{
25-
$value = app(Hasher::class)->decode($value);
25+
$value = app(Hasher::class)->decode($value ?? '');
2626

2727
return $value[0] ?? null;
2828
}
@@ -32,6 +32,6 @@ public function decode($value)
3232
*/
3333
public function encode($value)
3434
{
35-
return app(Hasher::class)->encode($value);
35+
return app(Hasher::class)->encode($value ?? '');
3636
}
3737
}

classes/traits/JsonPrice.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(...$args)
2424
parent::__construct(...$args);
2525

2626
$currencies = Currency::hydrate(Cache::rememberForever(Currency::JSON_PRICE_CACHE_KEY, function () {
27-
return Currency::orderBy('is_default', 'DESC')->get()->toArray();
27+
return Currency::enabled()->orderBy('is_default', 'DESC')->get()->toArray();
2828
}));
2929

3030
$this->currencies = $currencies->keyBy('code');
@@ -100,7 +100,7 @@ public function price($currency = null)
100100
$currency = Currency::activeCurrency();
101101
}
102102
if (is_string($currency)) {
103-
$currency = Currency::whereCode($currency)->firstOrFail();
103+
$currency = Currency::enabled()->whereCode($currency)->firstOrFail();
104104
}
105105

106106
return new Price([

classes/traits/PriceAccessors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function updatePrices($value, $field = null)
138138
Price::updateOrCreate([
139139
'priceable_id' => $this->id,
140140
'priceable_type' => self::MORPH_KEY,
141-
'currency_id' => Currency::where('code', $currency)->firstOrFail()->id,
141+
'currency_id' => Currency::enabled()->where('code', $currency)->firstOrFail()->id,
142142
'field' => $field,
143143
], [
144144
'price' => $price,

classes/traits/ProductPriceTable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ protected function preparePriceTable()
6161
}
6262

6363
$this->vars['pricetable'] = $widget;
64-
$this->vars['currencies'] = Currency::orderBy('is_default', 'DESC')->orderBy('sort_order', 'ASC')->get();
64+
$this->vars['currencies'] = Currency::enabled()->orderBy('is_default', 'DESC')->orderBy('sort_order', 'ASC')->get();
6565
$this->vars['pricetableState'] = $this->processTableData($tableData)->toJson();
6666
}
6767

6868
public function onPriceTablePersist()
6969
{
7070
\DB::transaction(function () {
7171
$state = post('state', []);
72-
$currencies = Currency::get()->keyBy('code');
72+
$currencies = Currency::enabled()->get()->keyBy('code');
7373
$hasPriceInDefaultCurrency = false;
7474

7575
$this->removeOldPricingInformation($state, $currencies);

components/CurrencyPicker.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function defineProperties()
5353
*/
5454
public function onRun()
5555
{
56-
$this->setVar('currencies', Currency::orderBy('sort_order', 'ASC')->get());
56+
$this->setVar('currencies', Currency::enabled()->orderBy('sort_order', 'ASC')->get());
5757
$this->setVar('activeCurrency', Currency::activeCurrency());
5858
}
5959

@@ -68,7 +68,7 @@ public function onSwitchCurrency()
6868
return;
6969
}
7070

71-
Currency::setActiveCurrency(Currency::findOrFail($currency));
71+
Currency::setActiveCurrency(Currency::enabled()->findOrFail($currency));
7272

7373
$pageUrl = $this->getUrl();
7474

components/ProductsFilter.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php namespace OFFLINE\Mall\Components;
22

3-
use DB;
43
use Illuminate\Database\Eloquent\ModelNotFoundException;
54
use Illuminate\Support\Collection;
65
use OFFLINE\Mall\Classes\CategoryFilter\Filter;
@@ -15,8 +14,6 @@
1514
use OFFLINE\Mall\Models\Currency;
1615
use OFFLINE\Mall\Models\Property;
1716
use OFFLINE\Mall\Models\PropertyGroup;
18-
use Session;
19-
use Validator;
2017

2118
/**
2219
* The ProductsFilter component is used to filter items of
@@ -33,120 +30,140 @@ class ProductsFilter extends MallComponent
3330
* @var Category
3431
*/
3532
public $category;
33+
3634
/**
3735
* A Collection of all subcategories.
3836
*
3937
* @var Collection
4038
*/
4139
public $categories;
40+
4241
/**
4342
* All items in this category.
4443
*
4544
* @var Collection<Product|Variant>
4645
*/
4746
public $items;
47+
4848
/**
4949
* All available property values.
5050
*
5151
* @var Collection
5252
*/
5353
public $values;
54+
5455
/**
5556
* All available property filters.
5657
*
5758
* @var Collection
5859
*/
5960
public $propertyGroups;
61+
6062
/**
6163
* A collection of available Property models.
6264
*
6365
* @var Collection
6466
*/
6567
public $props;
68+
6669
/**
6770
* All active Filters.
6871
*
6972
* @var Collection
7073
*/
7174
public $filter;
75+
7276
/**
7377
* Query string representation of the active filter.
7478
*
7579
* @var string
7680
*/
7781
public $queryString;
82+
7883
/**
7984
* Show the price range filter.
8085
*
8186
* @var boolean
8287
*/
8388
public $showPriceFilter;
89+
8490
/**
8591
* Show the brand filter.
8692
*
8793
* @var boolean
8894
*/
8995
public $showBrandFilter;
96+
9097
/**
9198
* Show the on sale filter.
9299
*
93100
* @var boolean
94101
*/
95102
public $showOnSaleFilter;
103+
96104
/**
97105
* All available brands.
98106
*
99107
* @var Collection<Brand>
100108
*/
101109
public $brands;
110+
102111
/**
103112
* Include all items from child categories.
104113
*
105114
* @var boolean
106115
*/
107116
public $includeChildren;
117+
108118
/**
109119
* Also filter Variant properties.
110120
*
111121
* @var boolean
112122
*/
113123
public $includeVariants;
124+
114125
/**
115126
* The min and max values of the price range.
116127
*
117128
* @var array
118129
*/
119130
public $priceRange;
131+
120132
/**
121133
* The active Currency.
122134
*
123135
* @var Currency
124136
*/
125137
public $currency;
138+
126139
/**
127140
* The active sort order.
128141
*
129142
* @var string
130143
*/
131144
public $sortOrder;
145+
132146
/**
133147
* All available sort Options.
134148
*
135149
* @var array
136150
*/
137151
public $sortOptions;
152+
138153
/**
139154
* Sort order of the products component.
140155
*
141156
* @var string
142157
*/
143158
public $productsComponentSort;
159+
144160
/**
145161
* Category of the products component.
146162
*
147163
* @var Category
148164
*/
149165
public $productsComponentCategory;
166+
150167
/**
151168
* An instance of the money formatter class.
152169
*

console/SystemCheck.php

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use OFFLINE\Mall\Models\GeneralSettings;
66
use OFFLINE\Mall\Models\Product;
77
use OFFLINE\Mall\Models\ShippingMethod;
8-
use Symfony\Component\Console\Input\InputOption;
9-
use Symfony\Component\Console\Input\InputArgument;
108

119
class SystemCheck extends Command
1210
{

controllers/PriceCategories.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php namespace OFFLINE\Mall\Controllers;
22

3-
use Backend\Classes\Controller;
43
use BackendMenu;
5-
use October\Rain\Exception\ValidationException;
6-
use OFFLINE\Mall\Models\Currency;
7-
use OFFLINE\Mall\Models\PriceCategory;
8-
use System\Classes\SettingsManager;
94
use Backend\Behaviors\ListController;
105
use Backend\Behaviors\FormController;
116
use Backend\Behaviors\ReorderController;
7+
use Backend\Classes\Controller;
8+
use October\Rain\Exception\ValidationException;
9+
use OFFLINE\Mall\Models\PriceCategory;
10+
use System\Classes\SettingsManager;
1211

1312
class PriceCategories extends Controller
1413
{

controllers/currencies/config_form.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Currencies
1+
name: offline.mall::lang.currency_settings.label
22
modelClass: OFFLINE\Mall\Models\Currency
33
form: $/offline/mall/models/currency/fields.yaml
44
defaultRedirect: offline/mall/currencies

controllers/currencies/config_list.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Currencies
1+
title: offline.mall::lang.currency_settings.label
22
modelClass: OFFLINE\Mall\Models\Currency
33
list: $/offline/mall/models/currency/columns.yaml
44
recordUrl: 'offline/mall/currencies/update/:id'

controllers/currencies/config_reorder.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Currencies
1+
title: offline.mall::lang.currency_settings.label
22
modelClass: OFFLINE\Mall\Models\Currency
33
nameFrom: code
44
toolbar:

0 commit comments

Comments
 (0)