conedevelopment / bazar

Bazar is an e-commerce package for Laravel applications.
https://root.conedevelopment.com
MIT License
421 stars 56 forks source link

Cannot add items to cart #199

Closed LarryBarker closed 11 months ago

LarryBarker commented 2 years ago

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?

LarryBarker commented 2 years ago

@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.

LarryBarker commented 2 years ago

@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.