bazar
bazar copied to clipboard
Cannot add items to cart
- Bazar Version: ^0.8.2
- Laravel Version: 8
- PHP Version: 8.1
- Database Driver & Version: MySQL 8
Description:
Following the docs trying to add an item to the cart and I get this error back:
Column 'price' cannot be null
$item = Cart::addItem($variant->product, 1, [
'price' => $variant->prices->format('USD.default')
]);
```
Also note I initially tried adding the variant to the cart which failed because `addItem` expects an instance of `Product` to be passed. This is strange to me but nevertheless I can work around it.
I'm not exactly sure how or where to pass the price?
Also, I cannot seem to find where the logic for `addItem` actually lives?
@iamgergo I just upgraded to v0.9 and am having the same issue with the exception I can pass an instance of Variant to addItem. Still have the error about null price.
@iamgergo Related to another ticket I commented on about array to string conversion error, addItem is now failing if the item is added with an empty array of properties:
$item = Cart::addItem($variant, 1, []);
This will insert an item into the database with [] as the properties. Later, the InteractsWithItems trait will throw an error here:
return $this->items->first(static function (Item $item) use ($attributes): bool {
return empty(array_diff(
Arr::dot($attributes),
Arr::dot($item->withoutRelations()->toArray())
));
});
```
This is because of how `array_diff` handles empty arrays for some reason.