Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SearchTermManager.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Model;
7 
15 {
19  private $searchTerms;
20 
24  private $searchTermsUseRate;
25 
29  private $totalProductsCount;
30 
35  public function __construct(array $searchTerms, $totalProductsCount)
36  {
37  $this->searchTerms = $searchTerms;
38  $this->totalProductsCount = (int) $totalProductsCount;
39  }
40 
49  public function applySearchTermsToDescription(&$description, $currentProductIndex)
50  {
51  if ($this->searchTermsUseRate === null) {
52  $this->calculateSearchTermsUseRate();
53  }
54 
55  foreach ($this->searchTerms as &$searchTerm) {
56  if ($this->searchTermsUseRate[$searchTerm['term']]['use_rate'] > 0
57  && $currentProductIndex % $this->searchTermsUseRate[$searchTerm['term']]['use_rate'] === 0
58  && $this->searchTermsUseRate[$searchTerm['term']]['used'] < $searchTerm['count']
59  ) {
60  $description .= ' ' . $searchTerm['term'];
61  $this->searchTermsUseRate[$searchTerm['term']]['used'] += 1;
62  }
63  }
64  }
65 
73  private function calculateSearchTermsUseRate()
74  {
75  foreach ($this->searchTerms as $searchTerm) {
76  $this->searchTermsUseRate[$searchTerm['term']] = [
77  'use_rate' => floor($this->totalProductsCount / $searchTerm['count']),
78  'used' => 0
79  ];
80  }
81  }
82 }
__construct(array $searchTerms, $totalProductsCount)
applySearchTermsToDescription(&$description, $currentProductIndex)