Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. protected function _initItems()
  2. {
  3. parent::_initItems();
  4. foreach ($this->_items as $item) {
  5. $applyValue = $item->getLabel();
  6. if (($valuePos = array_search($applyValue, $this->currentFilterValue)) !== false) {
  7. $item->setIsSelected(true);
  8. $applyValue = $this->currentFilterValue;
  9. unset($applyValue[$valuePos]);
  10. } else {
  11. $applyValue = array_merge($this->currentFilterValue, [$applyValue]);
  12. }
  13. $item->setApplyFilterValue(array_values($applyValue));
  14. }
  15. return $this;
  16. }
  17.  
  18. protected function _getItemsData()
  19. {
  20.  
  21.  
  22. $attribute = $this->getAttributeModel();
  23. /** @var MagentoCatalogSearchModelResourceModelFulltextCollection $productCollection */
  24. $productCollection = $this->getLayer()->getProductCollection();
  25.  
  26. $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
  27.  
  28. $items = [];
  29.  
  30. $attributeCode = $attribute->getAttributeCode();
  31. if ($attribute->getFrontendInput() == 'multiselect') {
  32. //echo '1<br/>';
  33. if($this->_coreRegistry->registry('current_category')) {
  34. // echo '2<br/>';
  35. $catId = $this->_coreRegistry->registry('current_category')->getId();
  36. $facetSession = $this->_catalogSession->getData('multiselect_facets');
  37. if(isset($facetSession[$catId][$attributeCode]) && isset($_GET[$attributeCode])) {;
  38. $optionsFacetedData = $facetSession[$catId][$attributeCode];
  39. } else {
  40. // echo '4<br/>';
  41. $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
  42. // $optionsFacetedData returning all attributes after filter
  43. $facetArray = $facetSession;
  44. $facetArray[$catId][$attributeCode] = $optionsFacetedData;
  45. $this->_catalogSession->setData('multiselect_facets', $facetArray);
  46. }
  47. } else {
  48. $catId = 'search';
  49. $facetSession = $this->_catalogSession->getData('multiselect_facets');
  50.  
  51. if(isset($facetSession[$catId][$attributeCode]) && isset($_GET[$attributeCode])) {
  52.  
  53. $optionsFacetedData = $facetSession[$catId][$attributeCode];
  54. } else {
  55. $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
  56. $facetArray = $facetSession;
  57. $facetArray[$catId][$attributeCode] = $optionsFacetedData;
  58.  
  59. $this->_catalogSession->setData('multiselect_facets', $facetArray);
  60. }
  61. }
  62. }
  63.  
  64. if (isset($optionsFacetedData['__other_docs'])) {
  65. $this->hasMoreItems = $optionsFacetedData['__other_docs']['count'] > 0;
  66. unset($optionsFacetedData['__other_docs']);
  67. }
  68.  
  69. foreach ($optionsFacetedData as $value => $data) {
  70. $items[$value] = [
  71. 'label' => $this->tagFilter->filter($value),
  72. 'value' => $value,
  73. 'count' => $data['count'],
  74. ];
  75. }
  76.  
  77. $items = $this->addOptionsData($items);
  78.  
  79. return $items;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement