Jump to content

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

Prevent Duplicate Product Code Rate Topic   - - - - -

 
  • abresmos
  • Newbie
  • Trial users
  • Join Date: 19-Jul 16
  • 9 posts

Posted 08 August 2016 - 06:37 PM #1

hi  :grin:

i have more than 10000 products :shock:  in my cs-cart website ,each one of them has product code :confused:  , i want to prevent duplicate product code when admin insert new product with product code already used with other product    :confused: ????
 



 

Posted 08 August 2016 - 06:41 PM #2

Hello abresmos,

You can check unique sku add-on https://store.webkul...KU-Or-Code.html


Thank you
Himansu Dangwal

 
  • Alt-team
  • CS-Cart Developer
  • Authorized Reseller
  • Join Date: 18-Jan 11
  • 2651 posts

Posted 08 August 2016 - 08:21 PM #3

Hello abresmos,
 

If the question is still relevant, we will be glad to develop this modification for you. Please, contact us.

 

Best regards,

Alt-team


ADD-ONS  Web development service  | CS-Cart dedicated developers

Buy MULTIVENDOR - USD 1250 (14% off)   Buy CS-CART LICENCE - USD 345 (13% off)

 Email - manager@alt-team.com | Skype - Altteam    


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

Posted 09 August 2016 - 07:05 AM #4

Please use the update_product_pre hook (app/functions/fn.catalog.php) and the following code:

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $can_update = false;
    }
}

or add this code after the following line:

fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);

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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • abresmos
  • Newbie
  • Trial users
  • Join Date: 19-Jul 16
  • 9 posts

Posted 11 August 2016 - 10:27 AM #5

 

Please use the update_product_pre hook (app/functions/fn.catalog.php) and the following code:

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $can_update = false;
    }
}

or add this code after the following line:

fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);

thanks so much , it's working perfectly



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

Posted 11 August 2016 - 01:52 PM #6

You are welcome!


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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • termalert
  • Senior Member
  • Members
  • Join Date: 14-Jan 09
  • 947 posts

Posted 23 October 2016 - 02:20 AM #7

Same requirement here. Just to clarify.

If the code below is not present in app/functions/fn.catalog.php 

 

if (empty($product_id)) {
$pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
if (!empty($pid)) {
$can_update = false;
}
}

 

then I should I simply add it under

fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);

 

so result should be:-

fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);
if (empty($product_id)) {
$pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
if (!empty($pid)) {
$can_update = false;
}
}

 



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

Posted 23 October 2016 - 08:28 PM #8

The above won't work for import.

Why not just make an index in the cscart_products table making product_code unique?  I.e. any new insert (or update of a product) using a duplicate product_code would simply fail at the SQL level.


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.


 
  • termalert
  • Senior Member
  • Members
  • Join Date: 14-Jan 09
  • 947 posts

Posted 23 October 2016 - 11:07 PM #9

Would I then get an error message if I tried to save a duplicate product code ?



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

Posted 24 October 2016 - 06:31 PM #10

The SQL INSERT/UPDATE would fail.  However, for import/export, cs-cart ignores SQL errors and does not report them. In the UI, you'd get the failure.  Try it.  If you don't like how it behaves (versus silently setting "$can_update = false") then you can simply drop the index and go back to how you are or using the hook above.


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.


 
  • Poseidonas
  • Advanced Member
  • Trial users
  • Join Date: 01-Feb 16
  • 55 posts

Posted 28 September 2018 - 02:00 PM #11

Same issue here! When Im trying to clone a product im gettin error page 'SERVICE

UNAVAILABLE', So what I have to do? We need a lot of times to clone products but atm we create new products with diif pid
 
 
 
Thanks! :)


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

Posted 28 September 2018 - 06:47 PM #12

Note that if you have made the product_code column unique, you will have to make adjustments to the clone code to alter the product code like it does for page titles, product names, etc. by probably adding "[CLONE}" to it.


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.


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

Posted 01 October 2018 - 07:25 AM #13

Please try

 

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $product_data['product_code'] .= ('_' . TIME);
    }
}

 

In this case timestamp value will be added to products with duplicated sku


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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • alaa
  • Advanced Member
  • Members
  • Join Date: 18-Mar 18
  • 132 posts

Posted 03 May 2019 - 10:55 PM #14

 

Please use the update_product_pre hook (app/functions/fn.catalog.php) and the following code:

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $can_update = false;
    }
}

or add this code after the following line:

fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);

 

 

Thanks eCom-Labs for your contribution. However, this doens't work on my store - MV. Is it no longer working for latest MV editions? Or would it be a cache issue (I don't know if PHP files are being cached).



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

Posted 04 May 2019 - 05:25 AM #15

Hmm.. It works on my local installation with the latest Multi-Vendor version


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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • crazyshark20
  • Junior Member
  • Members
  • Join Date: 19-Aug 09
  • 262 posts

Posted 04 May 2019 - 08:51 AM #16

Yes i try mv.4.9.3.sp1 in local. it works. if you try clone the product it don't works yess you are right alaa

 

Maybe you add a new product in store this works when import products if you want to see live you test TIME code not the other

 

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $product_data['product_code'] .= ('_' . TIME);
    }
}



 
  • alaa
  • Advanced Member
  • Members
  • Join Date: 18-Mar 18
  • 132 posts

Posted 04 May 2019 - 10:17 AM #17

Hmm.. It works on my local installation with the latest Multi-Vendor version

That's weired! I tried updating the fn.catalog.php directly with no luck. The results are the same as I have NOT added any code. In fact, I have set the variable $can_update in the beginning of the function (line 2495) from true to false just for checking. Still everthing works as I have dont nothing! 

    $can_update = false;


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

Posted 04 May 2019 - 01:29 PM #18

 

That's weired! I tried updating the fn.catalog.php directly with no luck. The results are the same as I have NOT added any code. In fact, I have set the variable $can_update in the beginning of the function (line 2495) from true to false just for checking. Still everthing works as I have dont nothing! 

 

Did you set the code after hook? 3rd party addons can override it and set to true somewhere 


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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • alaa
  • Advanced Member
  • Members
  • Join Date: 18-Mar 18
  • 132 posts

Posted 04 May 2019 - 01:39 PM #19

Did you set the code after hook? 3rd party addons can override it and set to true somewhere 

 

Things I have done: 

 

1- Disabled all third party addons. 

2- Added return false; just after the original function, like this: 

function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE)
{
    return false;
    $can_update = false;

3- Restarted NGINX

4- Block cache is disabled and cleared. 

5- Tried on both production server; where I am using redis and apcu, and developement server (no redis and no apcu). Both are not working either.

6- I tried to clear OPcache by executing this command opcache_reset(); in a new php file in CS-Cart root folder, still no good results.

 

Maybe I tried other things but cannot remember. 

 

 

It must be cache, but which and where I don't know!! these trivial issues make me crazy. 



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

Posted 06 May 2019 - 05:13 AM #20

I made the same action and see that the product was not created. If you want to add error notification, use the following code

 

if (empty($product_id)) {
    $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_code = ?s", $product_data['product_code']);
    if (!empty($pid)) {
        $can_update = false;
        fn_set_notification('E', __('error'), __('unique_sku_error'));
    }
}

Then add unique_sku_error language variable with the required value


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    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.