dsheiko/magentosearchquerybuilder

Tool to build search criteria query for Magento REST Web API

v1.0.0 2017-12-14 08:34 UTC

This package is not auto-updated.

Last update: 2024-11-10 05:40:27 UTC


README

Latest Stable Version Total Downloads License Build Status

Tool to build search criteria query for Magento REST Web API

Installation

Require as a composer dependency:

composer require "dsheiko/magentosearchquerybuilder"

Building query

<?php
use Dsheiko\SearchCriteria;
$builder = new SearchCriteria();
$builder
    ->filterGroup([
        [ "name", "%25Leggings%25", "like" ],
        [ "name", "%25Parachute%25", "like" ],
    ])
    ->filterGroup([
        [ "price", 30, "lt" ],
    ])
    ->sortOrder( "created_at", "DESC")
    ->limit(1, 10);

Obtaining query string

<?php
$builder->toString();

The result:

"searchCriteria[filter_groups][0][filters][0][field]=name"
  . "&searchCriteria[filter_groups][0][filters][0][value]=%25Leggings%25"
  . "&searchCriteria[filter_groups][0][filters][0][condition_type]=like"
  . "&searchCriteria[filter_groups][0][filters][1][field]=name"
  . "&searchCriteria[filter_groups][0][filters][1][value]=%25Parachute%25"
  . "&searchCriteria[filter_groups][0][filters][1][condition_type]=like"
  . "&searchCriteria[filter_groups][1][filters][1][field]=price"
  . "&searchCriteria[filter_groups][1][filters][1][value]=30"
  . "&searchCriteria[filter_groups][1][filters][1][condition_type]=lt"
  . "&searchCriteria[sort_orders][0][field]=created_at"
  . "&searchCriteria[sort_orders][0][direction]=DESC"
  . "&searchCriteria[current_page]=1"
  . "&searchCriteria[page_size]=10"

Obtaining query array

<?php
$builder->toArray();