Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search where('name', 'like', 'abcde%') possible ? #29

Open
piloufaces opened this issue May 7, 2020 · 3 comments
Open

Search where('name', 'like', 'abcde%') possible ? #29

piloufaces opened this issue May 7, 2020 · 3 comments

Comments

@piloufaces
Copy link

Hi,

I have an issue when I try to query the Woocommerce products using Where ... like

Product::where('name', 'like', 'abcde%')->get();

Possible or do we need to setup a filter based on all products ?

@maab16
Copy link
Collaborator

maab16 commented May 7, 2020

Hello @piloufaces

Thanks for creating the issue. Sorry, currently like operator not works. You can simple search using options

try {
    return Product::all([
	'search' => 'abcde'
    ]);
} catch (\Exception $ex) {
    echo $ex->getMesage();
}

Search functionality match your query both Title and Description. If match any result it returns the results. Below I added which filter covered which fields

  • Search

Title (covered by ?search=x)
Description (covered by ?search=x)

  • Sku

SKU (covered by ?sku=x)

  • Type

Type (covered by ?type=x)

  • Category

Category (covered by ?category=1)

  • Tag

Tag (covered by ?tag=1)

  • Date

Date (covered by ?after=YYYY-MM-DD and ?before=YYYY-MM-DD)

  • Attributes

Attributes (covered by attribute=x and attribute_term=1)

  • Stock

Stock: In stock, Out of Stock (covered by ?in_stock=true/false)

  • Featured product

Featured product (covered by ?featured=true/false)

  • Price

Price (covered by ?min_price=1&max_price=10)

  • Shipping classes

Shipping classes (covered by ?shipping_class=1)

  • Tax classes

Tax classes (covered by ?tax_class=x)

I've a plan to add it. I'll notify if I add.

Thanks

@maab16
Copy link
Collaborator

maab16 commented May 8, 2020

Hello @piloufaces

Good news. I added dynamic where clause in version v2.6. Now you can use below example from version 2.6 or above. Make sure your version is 2.6 or above otherwise update it before use.

// The 'title', 'name' and 'description' are same. Don't put any percent or other things. Just put your search value. It will automatically search all Title and Description and find out matching
$products = Product::where('title', 'like', 'hello')->get();
// this one same as previous one
$products = Product::whereTitle('hello')->get();

// When you use camelCase please make sure you used it correct form. If your search field is multi wards or separate by underscore (_) for example your search field is `min_price` then you must call it below format

$products = Product::whereMinPrice(5)->get();

// Here two words min and price for this reason we converted it Min and Price and joined with where

Search

$products = Product::where('name',  'hello')->get();
OR
$products = Product::whereName('hello')->get();
OR
$products = Product::where('title', 'like', 'hello')->get();
OR
$products = Product::whereTitle('hello')->get();
OR
$products = Product::where('description', ''hello')->get();
OR
$products = Product::whereDescription('hello')->get();

Sku

$products = Product::where('sku',  's120')->get();
OR
$products = Product::whereSku('s120')->get();

Type

$products = Product::where('type',  'value')->get();
OR
$products = Product::whereType('value')->get();

Category

$products = Product::where('category',  'value')->get();
OR
$products = Product::whereCategory('value')->get();

Tag

$products = Product::where('tag',  'value')->get();
OR
$products = Product::whereTag('value')->get();

Date before

$products = Product::where('before',  'YYYY-MM-DD')->get();
OR
$products = Product::whereBefore('YYYY-MM-DD')->get();

Date before

$products = Product::where('after',  'YYYY-MM-DD')->get();
OR
$products = Product::whereAfter('YYYY-MM-DD')->get();

Attribute

$products = Product::where('attribute',  'value')->get();
OR
$products = Product::whereAttribute('value')->get();

Attribute Term

$products = Product::where('attribute_term',  1)->get();
OR
$products = Product::whereAttributeTerm(1)->get();

In Stock

$products = Product::where('in_stock',  'true')->get();
OR
$products = Product::whereInStock('true')->get();

Out of Stock

$products = Product::where('in_stock',  'false')->get();
OR
$products = Product::whereInStock('false')->get();

Featured product

$products = Product::where('featured',  'true/false')->get();
OR
$products = Product::whereFeatured('true/false')->get();

Min price

$products = Product::where('min_price',  10)->get();
OR
$products = Product::whereMinPrice(10)->get();

Max price

$products = Product::where('min_price',  100)->get();
OR
$products = Product::whereMaxPrice(100)->get();

Shipping classes

$products = Product::where('shipping_class',  'value')->get();
OR
$products = Product::whereShippingClass('value')->get();

Tax classes

$products = Product::where('tax_class',  'value')->get();
OR
$products = Product::whereTaxClass('value')->get();

I hope you enjoy the code. If you have any other issue you can reply with details.

Thanks

@Codexshaper Codexshaper pinned this issue May 8, 2020
@JacoboMachado
Copy link

Hi @Codexshaper and @maab16
Following this thread, can search orders where used a specific coupon?
Alternatively, can search orders were used any coupon?
hope can you help me!
Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants