Skip to content

Commit

Permalink
Hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlinsky committed Sep 22, 2023
1 parent 34209e1 commit f59921a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 58 deletions.
7 changes: 1 addition & 6 deletions app/Listeners/ProductSearchValueListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
namespace App\Listeners;

use App\Events\ProductSearchValueEvent;
use App\Services\Contracts\ProductServiceContract;
use Illuminate\Contracts\Queue\ShouldQueue;

readonly class ProductSearchValueListener implements ShouldQueue
{
public function __construct(
private ProductServiceContract $productService,
) {}

public function handle(ProductSearchValueEvent $event): void
{
$this->productService->updateProductsSearchValues($event->product_ids);
// TODO: remove this listener
}
}
2 changes: 0 additions & 2 deletions app/Services/Contracts/ProductServiceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ public function getMinMaxPrices(Product $product): array;
* Updates minimum and maximum possible product price.
*/
public function updateMinMaxPrices(Product $product): void;

public function updateProductsSearchValues(array $productIds): void;
}
10 changes: 1 addition & 9 deletions app/Services/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

readonly class ProductService implements ProductServiceContract
final readonly class ProductService implements ProductServiceContract
{
public function __construct(
private MediaServiceContract $mediaService,
Expand Down Expand Up @@ -186,14 +186,6 @@ public function updateMinMaxPrices(Product $product): void
$this->discountService->applyDiscountsOnProduct($product);
}

public function updateProductsSearchValues(array $productIds): void
{
Product::query()
->whereIn('id', $productIds)
->with(['tags', 'sets', 'attributes', 'attributes.options'])
->each(fn (Product $product) => $this->prepareProductSearchValues($product)->save());
}

private function assignItems(Product $product, ?array $items): void
{
$items = Collection::make($items)->mapWithKeys(fn (array $item): array => [
Expand Down
41 changes: 0 additions & 41 deletions tests/Feature/Products/ProductSearchValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Models\Product;
use App\Models\ProductSet;
use App\Models\Tag;
use App\Services\Contracts\ProductServiceContract;
use Tests\TestCase;

class ProductSearchValuesTest extends TestCase
Expand Down Expand Up @@ -129,46 +128,6 @@ public function testDeleteProductSetSearchValues(string $user): void
]);
}

/**
* @dataProvider authProvider
*/
public function testDeleteParentProductSetSearchValues(string $user): void
{
$this->{$user}->givePermissionTo('product_sets.remove');

$parent = ProductSet::factory()->create([
'name' => 'Parent set',
]);

$set = ProductSet::factory()->create([
'public' => true,
'name' => 'children set',
'parent_id' => $parent->getKey(),
]);
$this->product->sets()->sync([$parent->getKey(), $set->getKey()]);

app(ProductServiceContract::class)->updateProductsSearchValues([$this->product->getKey()]);

$this->assertDatabaseHas('products', [
'id' => $this->product->getKey(),
'name' => 'Searched product',
'description_html' => 'Lorem ipsum',
'search_values' => 'Parent set children set',
]);

$this
->actingAs($this->{$user})
->json('DELETE', 'product-sets/id:' . $set->getKey())
->assertNoContent();

$this->assertDatabaseHas('products', [
'id' => $this->product->getKey(),
'name' => 'Searched product',
'description_html' => 'Lorem ipsum',
'search_values' => 'Parent set',
]);
}

/**
* @dataProvider authProvider
*/
Expand Down

0 comments on commit f59921a

Please sign in to comment.