Sylius: Exception when trying to add to cart a non found variant

Created on 7 Jan 2017  路  1Comment  路  Source: Sylius/Sylius

Here are the steps to reproduce this issue.

  • Do a fresh install of beta1
  • Go to the admin backend
  • Create a new configurable product with "Mug Type" as only option and "Options Matching" as Variant Selected Method.
  • Create a only variant for this product. Set "Medium mug" as "Mug Type" option
  • Now go to the frontend page of the product you have created
  • You will see the possibly option values for the mug type.
  • If you try to add "medium mug" everything works as expected
  • If you try to add the "monster mug" a exception is thrown that can be seen in the symfony profiler. it reads Expected argument of type "lius\Component\Core\Model\OrderItem::setVariant() must implement interface Sylius\Component\Core\Model\ProductVariantInterface", "NULL" given

Looks to me that we need to control if we have found a match before trying to add the item to the cart.

Potential Bug

Most helpful comment

This one will need 2 fixes:

  • On UI side: when you select a variant that doesn't exist for a product, the text "Unavailable" is displayed instead of the price ; this means there is a JS event that could be used to also disable the "Add to cart" button and prevent the form to be submitted
  • On PHP side: to prevent errors to be returned to the final user (through UI or API), the exception needs to be caught and handled properly

I'll try to work on these fixes today.

>All comments

This one will need 2 fixes:

  • On UI side: when you select a variant that doesn't exist for a product, the text "Unavailable" is displayed instead of the price ; this means there is a JS event that could be used to also disable the "Add to cart" button and prevent the form to be submitted
  • On PHP side: to prevent errors to be returned to the final user (through UI or API), the exception needs to be caught and handled properly

I'll try to work on these fixes today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefandoorn picture stefandoorn  路  3Comments

mikemix picture mikemix  路  3Comments

hmonglee picture hmonglee  路  3Comments

bnd170 picture bnd170  路  3Comments

reyostallenberg picture reyostallenberg  路  3Comments