craftcms / digital-products

Sell digital products with Craft Commerce.
https://plugins.craftcms.com/digital-products
MIT License
18 stars 9 forks source link

TypeError attempting to save new product without price #58

Closed mattstein closed 4 years ago

mattstein commented 4 years ago

Description

When attempting to save a new product without entering its price, a type error is returned instead of the validation error I’d expect:

TypeError Return value of craft\digitalproducts\elements\Product::getPrice() must be of the type float, string returned

Looks like it needs to be cast as a float for MySQL or that a null value needs to be accounted for.

Steps to reproduce

  1. Install Craft with Craft Commerce + Digital Products plugins and create a Product Type.
  2. Choose Digital ProductsProducts+ New Product.
  3. Enter some garbage input, specifically leaving Price empty, and choose Save.
  4. Observe the resulting type error.
  5. Go back and add a numeric value for Price, then choose Save.
  6. Observe the element detail view (as expected) where the empty SKU has a validation error (“Sku cannot be blank.”) as expected.
  7. Add the SKU and save, just for good feels and a sense of completion.

Additional info

mattstein commented 4 years ago

^ Tested + submitted a stunning PR.