Skip to content

Commit

Permalink
Hotfix remove product association (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslam97 authored Dec 2, 2022
1 parent 0d438ea commit f5bbb9b
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ abstract class AbstractProduct extends Component

protected function getListeners()
{
return array_merge([
'useProductOptions' => 'setOptions',
'productOptionCreated' => 'resetOptionView',
'option-manager.selectedValues' => 'setOptionValues',
'urlSaved' => 'refreshUrls',
'product-search.selected' => 'updateAssociations',
'collectionSearch.selected' => 'selectCollections',
'productOptionSelectorPanelToggled' => 'setVariantsEnabled',
],
return array_merge(
[
'useProductOptions' => 'setOptions',
'productOptionCreated' => 'resetOptionView',
'option-manager.selectedValues' => 'setOptionValues',
'urlSaved' => 'refreshUrls',
'product-search.selected' => 'updateAssociations',
'collectionSearch.selected' => 'selectCollections',
'productOptionSelectorPanelToggled' => 'setVariantsEnabled',
],
$this->getHasImagesListeners(),
$this->getHasSlotsListeners()
);
Expand Down Expand Up @@ -712,6 +713,7 @@ public function updateAssociations($selectedIds)
{
$selectedProducts = Product::findMany($selectedIds)->map(function ($product) {
return [
'is_temp' => true,
'inverse' => (bool) $this->showInverseAssociations,
'target_id' => $product->id,
'thumbnail' => optional($product->thumbnail)->getUrl('small'),
Expand Down Expand Up @@ -747,9 +749,16 @@ public function openAssociationBrowser($type)
*/
public function removeAssociation($index)
{
$this->associationsToRemove[] = $this->associations[$index]['id'];
$association = $this->associations[$index];

$this->associations->forget($index);
if (isset($association['is_temp'])) {
$this->associations->forget($index);
} else {
$this->associationsToRemove[] = $this->associations[$index]['id'];
$this->associations->forget($index);
}

$this->emit('updatedExistingProductAssociations', $this->associatedProductIds);
}

/**
Expand Down Expand Up @@ -894,7 +903,6 @@ public function getSideMenuProperty()
'title' => __('adminhub::menu.product.inventory'),
'id' => 'inventory',
'error_check' => [],
'hidden' => $this->getVariantsCount() > 1,
'has_errors' => $this->errorBag->hasAny([]),
],
[
Expand Down

1 comment on commit f5bbb9b

@vercel
Copy link

@vercel vercel bot commented on f5bbb9b Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.