lunar icon indicating copy to clipboard operation
lunar copied to clipboard

OrderLine expects a not null "identifier" (even if sku requirement is disabled)

Open armezit opened this issue 3 years ago • 0 comments

  • GetCandy version: 2.0-beta11
  • Laravel Version: 9.3.1
  • PHP Version: 8.1.2
  • Database Driver & Version:

Expected Behaviour:

The configuration in config/getcandy-hub/products.php lets us disable sku requirement.

https://github.com/getcandy/getcandy/blob/9bd91d7677759a540856f376ea8d757a3ea4a18e/packages/admin/config/products.php#L26-L29

Disabling sku should disable it's requirement in all places.

Actual Behaviour:

It works fine while saving product variants, but if you try to create an order which contains a product variant without sku, then an exception throws:

    "message": "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'identifier' cannot be null (SQL: insert into `order_lines` (`purchasable_type`, `purchasable_id`, `type`, `description`, `option`, `identifier`, `unit_price`, `unit_quantity`, `quantity`, `sub_total`, `discount_total`, `tax_breakdown`, `tax_total`, `total`, `notes`, `meta`, `order_id`, `updated_at`, `created_at`) values (...))",
    "exception": "Illuminate\\Database\\QueryException",
    ...

ProductVariant::getIdentifier() returns sku (which is null in this case): https://github.com/getcandy/getcandy/blob/9bd91d7677759a540856f376ea8d757a3ea4a18e/packages/core/src/Actions/Carts/CreateOrder.php#L81

But order_lines.identifier column is not nullable.

Steps To Reproduce:

  1. disable sku requirement in config/getcandy-hub/products.php
  2. create a product variant without sku
  3. add the product variant to cart
  4. create order on cart

armezit avatar Apr 02 '22 16:04 armezit