Skip to content

Commit

Permalink
product index hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlinsky committed Sep 22, 2023
1 parent 9c16ef4 commit 34209e1
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 28 deletions.
4 changes: 0 additions & 4 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Events\ProductSearchValueEvent;
use App\Http\Requests\TagCreateRequest;
use App\Http\Requests\TagIndexRequest;
use App\Http\Requests\TagUpdateRequest;
Expand Down Expand Up @@ -35,16 +34,13 @@ public function store(TagCreateRequest $request): JsonResource
public function update(Tag $tag, TagUpdateRequest $request): JsonResource
{
$tag->update($request->validated());
ProductSearchValueEvent::dispatch($tag->products->pluck('id')->toArray());

return TagResource::make($tag);
}

public function destroy(Tag $tag): HttpResponse
{
$products = $tag->products->pluck('id')->toArray();
$tag->delete();
ProductSearchValueEvent::dispatch($products);

return Response::noContent();
}
Expand Down
5 changes: 0 additions & 5 deletions app/Services/AttributeOptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Services;

use App\Dtos\AttributeOptionDto;
use App\Events\ProductSearchValueEvent;
use App\Models\AttributeOption;
use App\Services\Contracts\AttributeOptionServiceContract;
use App\Services\Contracts\MetadataServiceContract;
Expand Down Expand Up @@ -42,8 +41,6 @@ public function updateOrCreate(string $attributeId, AttributeOptionDto $dto): At
$attributeOption = AttributeOption::query()->findOrFail($dto->id);
$attributeOption->update($dto->toArray());

ProductSearchValueEvent::dispatch($attributeOption->productAttributes->pluck('product_id')->toArray());

return $attributeOption;
}

Expand All @@ -52,9 +49,7 @@ public function updateOrCreate(string $attributeId, AttributeOptionDto $dto): At

public function delete(AttributeOption $attributeOption): void
{
$productIds = $attributeOption->productAttributes->pluck('product_id')->toArray();
$attributeOption->delete();
ProductSearchValueEvent::dispatch($productIds);
}

public function deleteAll(string $attributeId): void
Expand Down
4 changes: 0 additions & 4 deletions app/Services/AttributeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Dtos\AttributeDto;
use App\Enums\AttributeType;
use App\Events\ProductSearchValueEvent;
use App\Models\Attribute;
use App\Models\Product;
use App\Services\Contracts\AttributeOptionServiceContract;
Expand Down Expand Up @@ -35,18 +34,15 @@ public function create(AttributeDto $dto): Attribute
public function update(Attribute $attribute, AttributeDto $dto): Attribute
{
$attribute->update($dto->toArray());
ProductSearchValueEvent::dispatch($attribute->products->pluck('id')->toArray());

return $attribute;
}

public function delete(Attribute $attribute): void
{
$products = $attribute->products->pluck('id')->toArray();
$this->attributeOptionService->deleteAll($attribute->getKey());

$attribute->delete();
ProductSearchValueEvent::dispatch($products);
}

public function sync(Product $product, array $data): void
Expand Down
15 changes: 0 additions & 15 deletions app/Services/ProductSetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Dtos\ProductSetDto;
use App\Dtos\ProductSetUpdateDto;
use App\Dtos\ProductsReorderDto;
use App\Events\ProductSearchValueEvent;
use App\Events\ProductSetCreated;
use App\Events\ProductSetDeleted;
use App\Events\ProductSetUpdated;
Expand Down Expand Up @@ -117,8 +116,6 @@ public function create(ProductSetDto $dto): ProductSet
$this->metadataService->sync($set, $dto->metadata);
}

ProductSearchValueEvent::dispatch($set->allProductsIds()->toArray());

// searchable is handled by the event listener
ProductSetCreated::dispatch($set);

Expand Down Expand Up @@ -204,7 +201,6 @@ public function update(ProductSet $set, ProductSetUpdateDto $dto): ProductSet
'slug' => $slug,
'public_parent' => $publicParent,
]);
ProductSearchValueEvent::dispatch($productIds->toArray());

if (!($dto->getAttributesIds() instanceof Missing)) {
$attributes = Collection::make($dto->getAttributesIds());
Expand Down Expand Up @@ -233,23 +229,13 @@ public function reorder(array $sets, ProductSet|null $parent = null): void

public function attach(ProductSet $set, array $productsIds): Collection
{
$currentProducts = $set->products()->pluck('id');

$set->products()->sync($productsIds);

ProductSearchValueEvent::dispatch(
array_merge(
$currentProducts->diff($productsIds)->toArray(),
collect($productsIds)->diff($currentProducts)->toArray(),
),
);

return $set->products;
}

public function delete(ProductSet $set): void
{
$productIds = $set->allProductsIds()->merge($set->relatedProducts->pluck('id'));
if ($set->children()->count() > 0) {
$set->children->each(fn ($subset) => $this->delete($subset));
}
Expand All @@ -259,7 +245,6 @@ public function delete(ProductSet $set): void
if ($set->seo !== null) {
$this->seoMetadataService->delete($set->seo);
}
ProductSearchValueEvent::dispatch($productIds->toArray());
}
}

Expand Down

0 comments on commit 34209e1

Please sign in to comment.