Jump to content

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

Prevent Duplicate Product Code Rate Topic   - - - - -

 
  • alaa
  • Senior Member
  • Members
  • Join Date: 18-Mar 18
  • 168 posts

Posted 13 May 2019 - 06:38 PM #21

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

 

You are right, eComLabs. 

 

I get it working finally. The error notification is very handy, thank you very much. 

 

Best Regards, 

Alaa



 

Posted 13 May 2019 - 08:04 PM #22

You are right, eComLabs. 

 

I get it working finally. The error notification is very handy, thank you very much. 

 

Best Regards, 

Alaa

 

If you like to find products with duplicate product codes you can use our addon - Incomplete products.

 

orders_form.png


Only helpful and unique addons https://store.retailfactory.ru


 
  • alaa
  • Senior Member
  • Members
  • Join Date: 18-Mar 18
  • 168 posts

Posted 30 July 2019 - 02:07 PM #23

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

 

Hello, 

I want to add the product id value for the sku. So instead of timestamp, I want to get the value of the id for the same product. 

 

Thanks in advance.



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

Posted 30 July 2019 - 07:07 PM #24

Why wouldn't you just create an index in the products table to make product_code unique?  Cs-cart might even generate an error when it can't update the product because of a unique index violation...  Or it should be in the logs for database.


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
  • 19775 posts

Posted 31 July 2019 - 05:35 AM #25

Hello, 

I want to add the product id value for the sku. So instead of timestamp, I want to get the value of the id for the same product. 

 

Thanks in advance.

 

 

Product ID is not known yet. So you should add product with duplicated sku. Then get product ID and change product code


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
  • Senior Member
  • Members
  • Join Date: 18-Mar 18
  • 168 posts

Posted 01 August 2019 - 03:15 PM #26

Why wouldn't you just create an index in the products table to make product_code unique?  Cs-cart might even generate an error when it can't update the product because of a unique index violation...  Or it should be in the logs for database.

 

 

Product ID is not know yet. So you should add product with duplicated sku. Then get product ID and change product code

 

 

Thank you everybody for your replies. 

 

I did try this: 

if (empty($product_id)) {
    $pid = db_get_field("SELECT MAX(product_id) FROM ?:products");
    $new_pid= $pid +1;
    $product_data['product_code'] = $new_pid;

}

However, the above didn't work when adding new product after deleting one. 

 

I am thinking of having a static value for the product code when creating a product. Then, getting the product id for that specific sku and change the value of the sku to the product id. 

 

Regards, 

Alaa