Skip to content

Commit

Permalink
Merge pull request #10321 from notbakaneko/feature/remove-address-edit
Browse files Browse the repository at this point in the history
Remove store address editing
  • Loading branch information
nanaya authored Jul 3, 2023
2 parents 23ec67f + 2b8b70c commit 1bfba8e
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 443 deletions.
99 changes: 1 addition & 98 deletions app/Http/Controllers/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use App\Http\Controllers\Store\Controller as Controller;
use App\Models\Store;
use Auth;
use Request;
use Validator;

class StoreController extends Controller
{
Expand All @@ -20,21 +18,16 @@ public function __construct()
{
$this->middleware('auth', ['only' => [
'getInvoice',
'postNewAddress',
'postUpdateAddress',
]]);

if (!$this->isAllowRestrictedUsers()) {
$this->middleware('check-user-restricted', ['only' => [
'getInvoice',
'postNewAddress',
'postUpdateAddress',
]]);
}

$this->middleware('verify-user', ['only' => [
'getInvoice',
'postUpdateAddress',
]]);

parent::__construct();
Expand All @@ -58,96 +51,6 @@ public function getInvoice($id = null)
abort(403);
}

$sentViaAddress = Store\Address::sender();
$forShipping = Auth::user()->isAdmin() && get_bool(Request::input('for_shipping'));
$copies = clamp(get_int(request('copies')), 1, config('store.invoice.max_copies'));

return ext_view('store.invoice', compact('order', 'forShipping', 'copies', 'sentViaAddress'));
}

public function missingMethod($parameters = [])
{
abort(404);
}

public function postUpdateAddress()
{
$address_id = (int) Request::input('id');
$address = Store\Address::find($address_id);
$order = $this->userCart();

if (!$address || $address->user_id !== Auth::user()->user_id) {
return error_popup('invalid address');
}

switch (Request::input('action')) {
default:
case 'use':
$order->address()->associate($address);
$order->save();

return ext_view('layout.ujs-reload', [], 'js');
break;
case 'remove':
if ($order->address_id === $address_id) {
return error_popup('Address is being used for this order!');
}

if ($otherOrders = Store\Order::where('address_id', '=', $address_id)->first()) {
return error_popup('Address was used in a previous order!');
}

Store\Address::destroy($address_id);

return ext_view('store.address-destroy', ['address_id' => $address_id], 'js');
break;
}
}

public function postNewAddress()
{
\Log::info(json_encode([
'tag' => 'NEW_ADDRESS',
'user_id' => Auth::user()->user_id,
'address' => Request::input('address'),
]));

$addressInput = get_params(request()->all(), 'address', [
'first_name',
'last_name',
'street',
'city',
'state',
'zip',
'country_code',
'phone',
]);

$validator = Validator::make($addressInput, [
'first_name' => ['required'],
'last_name' => ['required'],
'street' => ['required', 'mixture'],
'city' => ['required'],
'state' => ['required'],
'zip' => ['required', 'required'],
'country_code' => ['required'],
'phone' => ['required'],
]);

$addressInput['user_id'] = Auth::user()->user_id;

if ($validator->fails()) {
return error_popup($validator->errors()->first());
}

$address = Store\Address::create($addressInput);
$address->user()->associate(Auth::user());
$address->save();

$order = $this->userCart();
$order->address()->associate($address);
$order->save();

return ext_view('layout.ujs-reload', [], 'js');
return ext_view('store.invoice', compact('order'));
}
}
16 changes: 11 additions & 5 deletions app/Libraries/OrderCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,29 @@ public function validate()
$messages[] = $item->validationErrors()->allMessages();
}

$product = $item->product;

// Checkout process level validations, should not be part of OrderItem validation.
if ($item->product === null || !$item->product->isAvailable()) {
if ($product === null || !$product->isAvailable()) {
$messages[] = osu_trans('model_validation/store/product.not_available');
}

if (!$item->product->inStock($item->quantity)) {
if (!$product->inStock($item->quantity)) {
$messages[] = osu_trans('model_validation/store/product.insufficient_stock');
}

if ($item->quantity > $item->product->max_quantity) {
$messages[] = osu_trans('model_validation/store/product.too_many', ['count' => $item->product->max_quantity]);
if ($item->quantity > $product->max_quantity) {
$messages[] = osu_trans('model_validation/store/product.too_many', ['count' => $product->max_quantity]);
}

if ($shouldShopify && !$item->product->isShopify()) {
if ($shouldShopify && !$product->isShopify()) {
$messages[] = osu_trans('model_validation/store/product.must_separate');
}

if ($product->requiresShipping() && !$product->isShopify()) {
$messages[] = osu_trans('model_validation/store/product.not_available');
}

$customClass = $item->getCustomClassInstance();
if ($customClass !== null) {
$messages[] = $customClass->validate()->allMessages();
Expand Down
31 changes: 0 additions & 31 deletions app/Models/Store/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use App\Models\Country;
use App\Models\User;
use Auth;

/**
* @property int $address_id
Expand Down Expand Up @@ -55,34 +54,4 @@ public function countryName()
return $this->country->name;
}
}

public static function sender()
{
//todo: move to database
switch (Auth::user()->user_id) {
default:
case 4916903:
return new self([
'first_name' => 'osu!store',
'last_name' => '',
'street' => 'Room 304, Build 700 Nishijin 7-7-1',
'city' => 'Sawara',
'state' => 'Fukuoka',
'zip' => '814-0002',
'country' => Country::find('JP'),
'phone' => '+819064201305',
]);
case 2:
return new self([
'first_name' => 'osu!store',
'last_name' => '',
'street' => 'Nishi-Ooi 4-21-3 Birdie House A',
'city' => 'Shinagawa',
'state' => 'Tokyo',
'zip' => '140-0015',
'country' => Country::find('JP'),
'phone' => '+818013811430',
]);
}
}
}
6 changes: 1 addition & 5 deletions app/Models/Store/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,10 @@ public function getProviderReference(): ?string
return static::splitTransactionId($this->transaction_id)[1] ?? null;
}

public function getSubtotal($forShipping = false)
public function getSubtotal()
{
$total = 0;
foreach ($this->items as $i) {
if ($forShipping && !$i->product->requiresShipping()) {
continue;
}

$total += $i->subtotal();
}

Expand Down
3 changes: 0 additions & 3 deletions config/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

return [
'allow_restricted_users' => get_bool(env('STORE_ALLOW_RESTRICTED_USERS')) ?? false,
'invoice' => [
'max_copies' => get_int(env('STORE_INVOICE_MAX_COPIES')) ?? 10,
],
'mail' => [
'donation_thanks' => [
'sender_address' => env('STORE_THANKS_SENDER_ADDRESS', 'osu@ppy.sh'),
Expand Down
9 changes: 9 additions & 0 deletions database/factories/Store/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ public function masterTshirt(): static
'weight' => 100,
]);
}

public function virtual(): static
{
return $this->state([
'base_shipping' => 0.00,
'next_shipping' => 0.00,
'weight' => null,
]);
}
}
1 change: 0 additions & 1 deletion resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@import "bem/account-edit-status";
@import "bem/account-verification-message";
@import "bem/address";
@import "bem/address-list";
@import "bem/admin-contest";
@import "bem/admin-contest-entry";
@import "bem/admin-menu";
Expand Down
12 changes: 0 additions & 12 deletions resources/css/bem/address-list.less

This file was deleted.

43 changes: 0 additions & 43 deletions resources/css/bem/address.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,4 @@

.address {
margin-bottom: 20px;

&--card {
.default-box-shadow();
.default-border-radius();
background: @osu-colour-b4;
padding: 20px;
margin: 0;
}

&--card-active {
.default-box-shadow();
box-shadow: 0 0 0 3px @osu-colour-l4;
}

&--card-hover {
&:hover {
.default-box-shadow();
box-shadow: 0 0 0 3px @osu-colour-l4;
}
}

&__button-delete {
.reset-input();
color: @osu-colour-c1;
position: absolute;
padding: 10px;
top: 0;
right: 0;
font-size: 20px; // icon size

&:hover {
color: @osu-colour-red-2;
}
}

&__button-select {
position: absolute;
top: 0;
left: 0;
width: 1px;
height: 1px;
opacity: 0;
}
}
6 changes: 0 additions & 6 deletions resources/css/utilities.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
}
}

.print-page-break {
@media print {
page-break-before: always;
}
}

.u-blackout-visible {
z-index: @z-index--blackout-visible !important;
}
Expand Down
16 changes: 0 additions & 16 deletions resources/views/store/_shipping_germany_warning.blade.php

This file was deleted.

8 changes: 0 additions & 8 deletions resources/views/store/address-destroy.blade.php

This file was deleted.

Loading

0 comments on commit 1bfba8e

Please sign in to comment.