Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
- Add a product to the store without a price.
- Visit that that product page, click "Add to cart"
Unexpected Error:
TypeError: Argument 1 passed to Drupal\commerce_order\Entity\OrderItem::setUnitPrice() must be an instance of Drupal\commerce_price\Price, null given, called in /Applications/MAMP/htdocs/d8/web/modules/contrib/commerce/modules/cart/src/Form/AddToCartForm.php on line 217 in /Applications/MAMP/htdocs/d8/web/modules/contrib/commerce/modules/order/src/Entity/OrderItem.php on line 12
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedWe need to make that price field required, it seems.
Comment #3
Thomas CysCopied from ProductionVariation class baseFieldDefinitions method:
// The price is not required because it's not guaranteed to be used
// for storage (there might be a price per currency, role, country, etc).
I accidentally forgot to add to price and ran into this issue but are there use cases where you don't want to add a price to a product? If there are the price should be 0 not null imo.
Comment #4
Thomas CysAdded PR for this issue: https://github.com/drupalcommerce/commerce/pull/735
Comment #5
Thomas CysComment #6
luizsgpetri CreditAttribution: luizsgpetri commentedI had the same issue and creating products with price fix it. Thanks for sharing this issue, it saved me some time to figure out it was my fault =p
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedCommitted, thanks!