Skip to content

Commit

Permalink
Update CollectionShow.php (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Dec 21, 2022
1 parent 4ac92ff commit 814e20e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class CollectionShow extends Component
*/
public \Illuminate\Support\Collection $products;

/**
* Whether products have been loaded.
*
* @var bool
*/
public bool $productsLoaded = false;

protected function getListeners()
{
return array_merge([
Expand Down Expand Up @@ -83,6 +90,8 @@ public function loadProducts()
$this->products = $this->mapProducts(
$this->collection->load('products.variants.basePrices.currency')->products
);

$this->productsLoaded = true;
}

/**
Expand Down Expand Up @@ -293,7 +302,7 @@ public function save()
});

DB::transaction(function () {
if ($this->productCount <= 30) {
if ($this->productsLoaded) {
$this->collection->products()->sync(
$this->products->mapWithKeys(function ($product, $index) {
return [
Expand Down

0 comments on commit 814e20e

Please sign in to comment.