Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/Actions/CRM/Customer/UI/GetProductsForPortfolioSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\InertiaTable\InertiaTable;
use App\Models\Catalogue\Product;
use App\Models\Dropshipping\CustomerSalesChannel;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
Expand All @@ -19,6 +20,7 @@
class GetProductsForPortfolioSelect extends OrgAction
{
use WithCRMEditAuthorisation;
use HasSearchableText;

public function handle(CustomerSalesChannel $customerSalesChannel, $prefix = null): LengthAwarePaginator
{
Expand Down Expand Up @@ -52,8 +54,17 @@
default:
// Search products by their own attributes (name, code, etc.)
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 60 in app/Actions/CRM/Customer/UI/GetProductsForPortfolioSelect.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/CRM/Customer/UI/GetProductsForPortfolioSelect.php#L60

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
break;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/CRM/Customer/UI/IndexCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public function handle(Group|Organisation|Shop|Product|TrafficSource $parent, $p
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) use ($parent) {
$query->where(function ($query) use ($value, $parent) {
$value = $this->normalizeSearchableText($value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(
explode(' ', trim($value)),
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

Expand Down
16 changes: 13 additions & 3 deletions app/Actions/Catalogue/Product/Json/GetOrderProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Http\Resources\Catalogue\OrderProductsResource;
use App\Models\Catalogue\Product;
use App\Models\Ordering\Order;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -23,14 +24,23 @@
class GetOrderProducts extends OrgAction
{
use WithCatalogueAuthorisation;

use HasSearchableText;

public function handle(Order $order, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 36 in app/Actions/Catalogue/Product/Json/GetOrderProducts.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetOrderProducts.php#L36

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Http\Resources\Catalogue\OrderProductsForModifyResource;
use App\Models\Catalogue\Product;
use App\Models\Ordering\Order;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -23,14 +24,23 @@
class GetOrderProductsForModification extends OrgAction
{
use WithCatalogueAuthorisation;

use HasSearchableText;

public function handle(Order $order, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 36 in app/Actions/Catalogue/Product/Json/GetOrderProductsForModification.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetOrderProductsForModification.php#L36

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Http\Resources\Catalogue\ProductsWebpageResource;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\ProductCategory;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -21,12 +22,23 @@

class GetOutOfStockProductsInProductCategory extends OrgAction
{
use HasSearchableText;

public function handle(ProductCategory $parent, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 34 in app/Actions/Catalogue/Product/Json/GetOutOfStockProductsInProductCategory.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetOutOfStockProductsInProductCategory.php#L34

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
15 changes: 13 additions & 2 deletions app/Actions/Catalogue/Product/Json/GetProductsForVolGrGift.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Http\Resources\Discounts\ProductsForVolGrGiftResource;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\Shop;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -24,15 +25,25 @@
class GetProductsForVolGrGift extends OrgAction
{
use WithCatalogueAuthorisation;
use HasSearchableText;

private Shop $parent;

public function handle(Shop $parent, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 39 in app/Actions/Catalogue/Product/Json/GetProductsForVolGrGift.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsForVolGrGift.php#L39

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
16 changes: 14 additions & 2 deletions app/Actions/Catalogue/Product/Json/GetProductsInCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\InertiaTable\InertiaTable;
use App\Models\Catalogue\Collection;
use App\Models\Catalogue\Product;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -23,12 +24,23 @@

class GetProductsInCollection extends OrgAction
{
use HasSearchableText;

public function handle(Collection $collection, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 36 in app/Actions/Catalogue/Product/Json/GetProductsInCollection.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsInCollection.php#L36

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Http\Resources\Catalogue\ProductsWebpageResource;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\ProductCategory;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -22,12 +23,23 @@

class GetProductsInProductCategory extends OrgAction
{
use HasSearchableText;

public function handle(ProductCategory $parent, $prefix = null, $seeAlso = false): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 35 in app/Actions/Catalogue/Product/Json/GetProductsInProductCategory.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsInProductCategory.php#L35

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
15 changes: 13 additions & 2 deletions app/Actions/Catalogue/Product/Json/GetProductsInWorkshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Http\Resources\Catalogue\ProductsWebpageResource;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\Shop;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -23,15 +24,25 @@
class GetProductsInWorkshop extends OrgAction
{
use WithCatalogueAuthorisation;
use HasSearchableText;

private Shop $parent;

public function handle(Shop $parent, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 38 in app/Actions/Catalogue/Product/Json/GetProductsInWorkshop.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsInWorkshop.php#L38

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Models\Catalogue\Collection;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\Shop;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -23,15 +24,25 @@
class GetProductsNotAttachedToACollection extends OrgAction
{
use WithCatalogueAuthorisation;
use HasSearchableText;

private Shop $parent;

public function handle(Shop $parent, Collection $collection, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 38 in app/Actions/Catalogue/Product/Json/GetProductsNotAttachedToACollection.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsNotAttachedToACollection.php#L38

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
16 changes: 14 additions & 2 deletions app/Actions/Catalogue/Product/Json/GetProductsWithNoWebpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\InertiaTable\InertiaTable;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\Shop;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -22,12 +23,23 @@

class GetProductsWithNoWebpage extends OrgAction
{
use HasSearchableText;

public function handle(Shop $shop, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 35 in app/Actions/Catalogue/Product/Json/GetProductsWithNoWebpage.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetProductsWithNoWebpage.php#L35

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\InertiaTable\InertiaTable;
use App\Models\Catalogue\Product;
use App\Models\Catalogue\ProductCategory;
use App\Models\Traits\HasSearchableText;
use App\Services\QueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
Expand All @@ -22,12 +23,23 @@

class GetTopProductsInProductCategory extends OrgAction
{
use HasSearchableText;

public function handle(ProductCategory $productCategory, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereAnyWordStartWith('products.name', $value)
->orWhereStartWith('products.code', $value);
$normalizedValue = $this->normalizeSearchableText($value);

// Ignore if search token is less than 2 words
$searchTokens = array_values(array_filter(

Check warning on line 35 in app/Actions/Catalogue/Product/Json/GetTopProductsInProductCategory.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/Actions/Catalogue/Product/Json/GetTopProductsInProductCategory.php#L35

Function array_filter() that supports callback detected
explode(' ', trim($normalizedValue)),
fn ($t) => strlen($t) >= 2
));

foreach ($searchTokens as $searchToken) {
$query->where('searchable_text', 'ILIKE', "% {$searchToken}%");
}
});
});

Expand Down
Loading