Smile-SA / magento2-module-product-label

Module to handle custom labels with images on products
Open Software License 3.0
53 stars 34 forks source link

SQL error on adding a new product label for some attributes #29

Closed yutv closed 9 months ago

yutv commented 4 years ago

Preconditions (*)

  1. Magento Cloud 2.3.4 or Magento Open Source 2.3.4
  2. PHP 7.2
  3. "Taxable Goods" Tax Class with class_id = 2 (important)
    SELECT * FROM `tax_class` ORDER BY class_id LIMIT 1;
    +----------+---------------+------------+
    | class_id | class_name    | class_type |
    +----------+---------------+------------+
    |        2 | Taxable Goods | PRODUCT    |
    +----------+---------------+------------+
  4. No record in the eav_attribute_option with option_id = 2. (important)
    SELECT * FROM `eav_attribute_option` ORDER BY option_id LIMIT 10;
    +-----------+--------------+------------+
    | option_id | attribute_id | sort_order |
    +-----------+--------------+------------+
    |         1 |           58 |          0 |
    |         4 |           58 |          1 |
    |         7 |           58 |          3 |
    |        10 |          493 |          0 |
    |        13 |          493 |          1 |
    |        16 |          493 |          2 |
    |        19 |          496 |          0 |
    |        22 |          496 |          1 |
    |        25 |          496 |          2 |
    |        28 |          499 |          0 |
    +-----------+--------------+------------+

Steps to reproduce (*)

Case 1

  1. Go to the "New product label" form
  2. Set the following fields to:
    Attribute: Tax Class
    Option: Taxable Goods
  3. Fill in other required fields and hit the "Save Product Label" button

Case 2

  1. Go to the "New product label" form
  2. Set the following fields to:
    Attribute: Country of Manufacture
    Option: France
  3. Fill in other required fields and hit the "Save Product Label" button

Expected result (*)

  1. New product label added
  2. OR Absence of unsupported attributes in the Attribute field.

Actual result (*)

  1. SQL Error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db_name.smile_productlabel, CONSTRAINT SMILE_PRODUCTLABEL_OPTION_ID_EAV_ATTRIBUTE_OPTION_OPTION_ID FOREIGN KEY (option_id) REFERENCES eav_attribute_option (option_id) ON ), query was: INSERT INTO smile_productlabel (product_label_id, is_active, name, attribute_id, option_id, image, position_category_list, position_product_view, alt, display_on) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

image

Technical details

The problem is the smile_productlabel.option_id field is a foreign key to eav_attribute_option.option_id so attribute values which stored in other tables (e.g. tax_class, directory_country, etc.) can't be saved.

In the Case 1 the option_id = 2, in the Case 2 the option_id = 0 (seems FR converted to 0).

indunie commented 2 years ago

Hey guys, I am having the same issue. Did anyone find a solution? Thanks.

Best Regards, Indunie Florence