Skip to content

Error 500 when updating discount #398

Description

@geantas

Describe the bug
When updating a discount through an API, it throws an error related to SQL:

"SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`homestead`.`discount_reward_products`, CONSTRAINT `discount_reward_products_discount_reward_id_foreign` FOREIGN KEY (`discount_reward_id`) REFERENCES `discount_rewards` (`id`)) (SQL: delete from `discount_rewards` where `discount_rewards`.`discount_id` = 5 and `discount_rewards`.`discount_id` is not null)"

To Reproduce

  1. Create a discount, fx:
this.$getcandy.on('discounts', 'postDiscounts',
   {
     name: {
       en: 'Buy one get none free',
       da: 'Buy one get none free'
     },
     start_at: '2019-06-04T14:27:02.000Z',
     end_at: '2019-06-04T14:27:02.000Z'
   })
  1. Get status 201
  2. Get the discount ID from server response (fx. wz6d39dj).
  3. Update discount, fx:
this.$getcandy.on('discounts', 'putDiscountsDiscountId', 'wz6d39dj', {
    start_at: '2019-08-24T14:15:22Z',
    end_at: '2022-08-24T14:15:22Z',
    priority: 0,
    stop_rules: true,
    status: true,
    attribute_data: {
      name: {
        webstore: {
          da: 'Buy one get none free',
          en: 'Buy one get none free'
        }
      }
    },
    channels: {
      data: {
        id: 1,
        published_at: '2021-06-14T14:15:22Z'
      }
    },
    rewards: {
      data: {
        products: [
          {
            product_id: 24202,
            quantity: 1
          }
        ]
      }
    },
    sets: {
      data: [
        {
          scope: 'string',
          outcome: true,
          items: {
            data: [
              {
                eligibles: [
                  'string'
                ],
                type: 'string'
              }
            ]
          }
        }
      ]
    }
  })
  1. See error in the server response.

Expected behavior
Server returns a response with status 200.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions