Skip to content

Commit

Permalink
hide "Add to Cart" button in search popup for unavailable products
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey committed Dec 18, 2019
1 parent 5d7e105 commit 9dcca7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
25 changes: 14 additions & 11 deletions Model/Search/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,25 @@ protected function getProductCollection($queryText)
*/
protected function getProductData($product)
{
/** @var \MageWorx\SearchSuiteAutocomplete\Block\Autocomplete\Product $product */
$product = $this->objectManager->create('MageWorx\SearchSuiteAutocomplete\Block\Autocomplete\ProductAgregator')
/** @var \MageWorx\SearchSuiteAutocomplete\Block\Autocomplete\ProductAgregator $productAgregator */
$productAgregator = $this->objectManager->create('MageWorx\SearchSuiteAutocomplete\Block\Autocomplete\ProductAgregator')
->setProduct($product);

$data = [
ProductFields::NAME => $product->getName(),
ProductFields::SKU => $product->getSku(),
ProductFields::IMAGE => $product->getSmallImage(),
ProductFields::REVIEWS_RATING => $product->getReviewsRating(),
ProductFields::SHORT_DESCRIPTION => $product->getShortDescription(),
ProductFields::DESCRIPTION => $product->getDescription(),
ProductFields::PRICE => $product->getPrice(),
ProductFields::ADD_TO_CART => $product->getAddToCartData(),
ProductFields::URL => $product->getUrl()
ProductFields::NAME => $productAgregator->getName(),
ProductFields::SKU => $productAgregator->getSku(),
ProductFields::IMAGE => $productAgregator->getSmallImage(),
ProductFields::REVIEWS_RATING => $productAgregator->getReviewsRating(),
ProductFields::SHORT_DESCRIPTION => $productAgregator->getShortDescription(),
ProductFields::DESCRIPTION => $productAgregator->getDescription(),
ProductFields::PRICE => $productAgregator->getPrice(),
ProductFields::URL => $productAgregator->getUrl()
];

if ($product->getData('is_salable')) {
$data[ProductFields::ADD_TO_CART] = $productAgregator->getAddToCartData();
}

return $data;
}

Expand Down
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

### Version 2.1.4

- **Fix**: Update locale file
- **Fix**: Update locale file

### Version 2.1.4

- **Fix**: Hide "Add to Cart" button in search popup for unavailable products
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"magento/module-search": ">=100.0.0 <102"
},
"type": "magento2-module",
"version": "2.1.8",
"version": "2.1.9",
"license": "GPL-3.0",
"authors": [
{
Expand All @@ -25,4 +25,4 @@
"MageWorx\\SearchSuiteAutocomplete\\": ""
}
}
}
}

0 comments on commit 9dcca7a

Please sign in to comment.