Search For Pcode In Product Api Returns Wrong Product

Good Morning.
We're having a problem fetching product information using the Product API.
The return of the search is bringing information from the TR-8S code product, and we're actually looking for the TR-8 product in this way: "/api/products?Pcode=TR-8".
Does anyone have the solution?
Regards,
Richard Felix

cc27f3ea-c0ac-4b6a-8bf0-ff2e716b7cc7.png

Good Morning.
We're having a problem fetching product information using the Product API.
The return of the search is bringing information from the TR-8S code product, and we're actually looking for the TR-8 product in this way: "/api/products?Pcode=TR-8".
Does anyone have the solution?
Regards,
Richard Felix

Hello!

There are 2 ways to solve it:

1. In app/functions/fn.catalog.php file you can see such code in fn_get_products function:

if (!empty($params['pcode'])) {
    $pcode = trim($params['pcode']);
    $condition .= db_quote(" AND (inventory.product_code LIKE ?l OR products.product_code LIKE ?l)",
        "%{$pcode}%", "%{$pcode}%"
    );
    $fields['combination'] = 'inventory.combination';
}

If you change $condition to be like this:

$condition .= db_quote(" AND (inventory.product_code = ?s OR products.product_code = ?s)",
    $pcode, $pcode
);

This will find exact match of product code, BUT it will affect other product search in the store (admin panel, storefront).

2. You can add your own parameter, for example, custom_pcode and add such code in a hook or app/functions/fn.catalog.php file:

if (!empty($params['custom_pcode'])) {
    $custom_pcode = trim($params['custom_pcode']);
    $condition .= db_quote(" AND (inventory.product_code = ?s OR products.product_code = ?s)",
        $custom_pcode, $custom_pcode
    );
    $fields['combination'] = 'inventory.combination';
}

Then your API request will be "/api/products?custom_pcode=TR-8"

Strongly suggest option #2 and that you use the 'additional_fields_in_search' hook to implement your custom parameter and to remove the original condition if your new parameter was passed.

You can also use that same hook to strip out the '%' characters surrounding the product_code if you choose option #1.

The trouble with option #1 is that it makes product_code be an exact match in all product searches which may not be what you want.

In product API how I can get thumbnails of products. Its missing in product API. Please help ASAP

https://prnt.sc/urocmf

In product API how I can get thumbnails of products. Its missing in product API. Please help ASAP

https://prnt.sc/urocmf

Please try the following solution

https://forum.cs-cart.com/topic/44910-api-product-query/#entry332066