conedevelopment / bazar

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

[Cart] Array to string conversion #167

Closed dd10-e closed 1 year ago

dd10-e commented 3 years ago

Description:

https://github.com/conedevelopment/bazar/blob/3f6c9ea957c22d56a9f716dc25dc44846779b5b4/src/Concerns/InteractsWithItems.php#L310-L316

This code is causing error is causing an error : "Array to string conversion".

Steps To Reproduce:

use Bazar\Support\Facades\Cart;

$item = Cart::addItem($product);
iamgergo commented 3 years ago

@dd10-e Hi,

Sorry for the late answer. How does your product look like?

dd10-e commented 3 years ago

Hello! My product looks like that $product->toArray() :

array:12 [▼
  "id" => 7
  "name" => "Lorem ipsum dolor sit amet"
  "slug" => "Lorem ipsum dolor sit amet"
  "description" => "<p>test - test</p>"
  "prices" => array:1 [▼
    "eur" => array:1 [▼
      "default" => 250
    ]
  ]
  "properties" => []
  "inventory" => array:9 [▼
    "files" => []
    "sku" => null
    "width" => null
    "height" => null
    "length" => null
    "weight" => null
    "quantity" => null
    "virtual" => false
    "downloadable" => false
  ]
  "created_at" => "2021-06-23T22:41:23.000000Z"
  "updated_at" => "2021-06-24T20:55:20.000000Z"
  "deleted_at" => null
  "price" => 250.0
  "formatted_price" => "250.00 EUR"
]

Note : The slug is not slugified because I modified from the Bazar Admin web-app.

LarryBarker commented 2 years ago

@dd10-e I ran into this same issue. The problem is with properties being empty. array_diff cannot handle multi-dimensional arrays, which Arr:dot() is supposed to flatten for us. However, I believe it is not handling empty arrays.

I was able to work around this but it requires a custom driver to override addItem:

$item = $this->getModel()->findItemOrNew([
            'price' => $price,
            'properties' => empty($properties) ? null : $properties,
            'product_id' => $product->id,
            'itemable_id' => $this->getModel()->id,
            'itemable_type' => get_class($this->getModel()),
        ]);

That being said, I'm now having issues saving item prices. Have you ran into this as well? See my issue here: https://github.com/conedevelopment/bazar/issues/199

cc: @iamgergo