Hi guys,
When I try to add one times two products with the same SKU form to allow me (not validation unique SKUs) and after updating node comes an error message.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Test-SKU-1' for key 'sku': INSERT INTO {commerce_product} (revision_id, sku, title, type, language, uid, status, created, changed) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => Test-SKU-1 [:db_insert_placeholder_2] => Test-SKU [:db_insert_placeholder_3] => modifikacia_vahy [:db_insert_placeholder_4] => sk [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1 [:db_insert_placeholder_7] => 1359709875 [:db_insert_placeholder_8] => 1359709875 ) v drupal_write_record() (riadok 7036 z /data/web/coolstranky.sk/sub/devlibrashop/includes/common.inc).

I think the solution would certainly be to add validation after update product in "class CommerceProductInlineEntityFormController" > "public function entityFormValidate" ?

Comments

vasike’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.16 KB

indeed. ugly one when it happens.
so there's should be an extra check against data entered for product in the IEF.
here is a patch that should solve this.

fox mulder’s picture

Issue summary: View changes

It does not work because it validates out existing sku-s. Sorry, but I can not create a patch yet. I think this is the right solution

      // Also check against products data already entered.
      foreach ($form_state['inline_entity_form'][$entity_form['#ief_id']]['entities'] as $key => $entity) {
        if ($entity['entity']->product_id != $product->product_id && $entity['entity']->sku == $sku) {
          form_set_error($parents_path . '][sku', t('This SKU was already entered for other product and must be unique. Please supply another value.'));
        }
      }
fox mulder’s picture

$entity['entity']->product_id and $product->product_id can be NULL, this is better:

  // Also check against products data already entered.
      foreach ($form_state['inline_entity_form'][$entity_form['#ief_id']]['entities'] as $key => $entity) {
        if ($entity['entity']->product_id != $product->product_id && $entity['entity']->sku == $sku) {
          form_set_error($parents_path . '][sku', t('This SKU was already entered for other product and must be unique. Please supply another value.'));
        }
      }

Status: Needs review » Needs work

The last submitted patch, 3: commerce_product_sku_validation-1905170-3.patch, failed testing.

paulbeaney’s picture

The patch from #3 works great for me.

bluegeek9’s picture

Status: Needs work » Closed (outdated)

We appreciate your contributions to Inline Entity Form. Drupal 7 in End-of-Life. We encourage you to upgrade to a supported version of Drupal.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.