Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Search For Pcode In Product Api Returns Wrong Product Rate Topic   - - - - -

 

Posted 23 August 2018 - 01:11 PM #1

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

Attached Thumbnails

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


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3501 posts

Posted 28 August 2018 - 06:30 AM #2

 

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"


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11796 posts

Posted 28 August 2018 - 08:18 PM #3

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 35 posts

Posted 02 October 2020 - 06:01 AM #4

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

https://prnt.sc/urocmf



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21048 posts

Posted 02 October 2020 - 01:18 PM #5

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-car...ry/#entry332066


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)