You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you press add to cart without selecting a Variant, you will get the following error:
DoubleThreeDigital\SimpleCommerce\Products\Product::variant(): Argument #1 ($optionKey) must be of type string, null given, called in D:\webdev\scommerce\vendor\doublethreedigital\simple-commerce\src\Http\Controllers\CartItemController.php on line 115
This is because in DoubleThreeDigital\SimpleCommerce\Http\Requests\CartItem\StoreRequest.php the validation rule says the variant may be nullable and if its not null it must be a string.
The Product::variant expects a string, so a null value isn't working. I tried making the variant required in the validation rules like this:
$rules = [
'product' => ['required', 'string'],
'variant' => ['nullable', 'string'],
'quantity' => ['required', 'numeric', 'gt:0'],
'email' => ['nullable', 'email', function ($attribute, $value, $fail) {
if (preg_match('/^\S*$/u', $value) === 0) {
return $fail(__('Your email may not contain any spaces.'));
}
}],
'customer.email' => ['nullable', 'email', function ($attribute, $value, $fail) {
if (preg_match('/^\S*$/u', $value) === 0) {
return $fail(__('Your email may not contain any spaces.'));
}
}],
];
if(Product::find($this->get('product'))->purchasableType() == ProductType::Variant){
$rules['variant'][0] = 'required';
}
However, this gives a new error, where i lose track.
D:\webdev\scommerce\vendor\statamic\cms\src\View\Antlers\Language\Runtime\NodeProcessor
.php: 1799```
### Steps to reproduce
1. Install the starter kit from the documentation
2. Log in and create a Variant product
3. View the variant product and press Add to cart without selecting it
### Environment
this command does not work for me
The text was updated successfully, but these errors were encountered:
KingPatje
changed the title
Adding a variant to the cart without selecting is gives an error
Adding a variant to the cart without selecting it gives an error
May 8, 2023
Description
When you press add to cart without selecting a Variant, you will get the following error:
DoubleThreeDigital\SimpleCommerce\Products\Product::variant(): Argument #1 ($optionKey) must be of type string, null given, called in D:\webdev\scommerce\vendor\doublethreedigital\simple-commerce\src\Http\Controllers\CartItemController.php on line 115
This is because in DoubleThreeDigital\SimpleCommerce\Http\Requests\CartItem\StoreRequest.php the validation rule says the variant may be nullable and if its not null it must be a string.
The Product::variant expects a string, so a null value isn't working. I tried making the variant required in the validation rules like this:
However, this gives a new error, where i lose track.
The text was updated successfully, but these errors were encountered: