Produced by Araxis Merge on 2022-09-08 08:48:55 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | /Volumes/Data 1/Ampps/www/Porto v4.0.2/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/Search/Helper | Data.php | 2022-04-29 10:43:13 +0000 |
| 2 | Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/Search/Helper | Data.php | 2022-06-10 10:42:23 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 1562 |
| Changed | 1 | 2 |
| Inserted | 1 | 1 |
| Removed | 0 | 0 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | 1 | <?php | |||
| 2 | /** | 2 | /** | |||
| 3 | * Mageplaza | 3 | * Mageplaza | |||
| 4 | * | 4 | * | |||
| 5 | * NOTICE OF LICENSE | 5 | * NOTICE OF LICENSE | |||
| 6 | * | 6 | * | |||
| 7 | * This source file is subject to the Mageplaza.com license that is | 7 | * This source file is subject to the Mageplaza.com license that is | |||
| 8 | * available through the world-wide-web at this URL: | 8 | * available through the world-wide-web at this URL: | |||
| 9 | * https://www.mageplaza.com/LICENSE.txt | 9 | * https://www.mageplaza.com/LICENSE.txt | |||
| 10 | * | 10 | * | |||
| 11 | * DISCLAIMER | 11 | * DISCLAIMER | |||
| 12 | * | 12 | * | |||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | |||
| 14 | * version in the future. | 14 | * version in the future. | |||
| 15 | * | 15 | * | |||
| 16 | * @category Mageplaza | 16 | * @category Mageplaza | |||
| 17 | * @package Mageplaza_Search | 17 | * @package Mageplaza_Search | |||
| 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | |||
| 19 | * @license https://www.mageplaza.com/LICENSE.txt | 19 | * @license https://www.mageplaza.com/LICENSE.txt | |||
| 20 | */ | 20 | */ | |||
| 21 | 21 | |||||
| 22 | namespace Mageplaza\Search\Helper; | 22 | namespace Mageplaza\Search\Helper; | |||
| 23 | 23 | |||||
| 24 | use Exception; | 24 | use Exception; | |||
| 25 | use Magento\Catalog\Model\CategoryFactory; | 25 | use Magento\Catalog\Model\CategoryFactory; | |||
| 26 | use Magento\Catalog\Model\Config; | 26 | use Magento\Catalog\Model\Config; | |||
| 27 | use Magento\Catalog\Model\Product; | 27 | use Magento\Catalog\Model\Product; | |||
| 28 | use Magento\Catalog\Model\Product\Visibility; | 28 | use Magento\Catalog\Model\Product\Visibility; | |||
| 29 | use Magento\Catalog\Model\ResourceModel\Product\Collection as CatalogCollection; | 29 | use Magento\Catalog\Model\ResourceModel\Product\Collection as CatalogCollection; | |||
| 30 | use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as CatalogCollectionFactory; | 30 | use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as CatalogCollectionFactory; | |||
| 31 | use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable; | 31 | use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable; | |||
| 32 | use Magento\Customer\Model\ResourceModel\Group\CollectionFactory; | 32 | use Magento\Customer\Model\ResourceModel\Group\CollectionFactory; | |||
| 33 | use Magento\Customer\Model\Session; | 33 | use Magento\Customer\Model\Session; | |||
| 34 | use Magento\Directory\Model\Currency; | 34 | use Magento\Directory\Model\Currency; | |||
| 35 | use Magento\Framework\App\Helper\Context; | 35 | use Magento\Framework\App\Helper\Context; | |||
| 36 | use Magento\Framework\DataObject; | 36 | use Magento\Framework\DataObject; | |||
| 37 | use Magento\Framework\Escaper; | 37 | use Magento\Framework\Escaper; | |||
| 38 | use Magento\Framework\Exception\LocalizedException; | 38 | use Magento\Framework\Exception\LocalizedException; | |||
| 39 | use Magento\Framework\Exception\NoSuchEntityException; | 39 | use Magento\Framework\Exception\NoSuchEntityException; | |||
| 40 | use Magento\Framework\Locale\FormatInterface; | 40 | use Magento\Framework\Locale\FormatInterface; | |||
| 41 | use Magento\Framework\ObjectManagerInterface; | 41 | use Magento\Framework\ObjectManagerInterface; | |||
| 42 | use Magento\Framework\Pricing\Helper\Data as PricingHelper; | 42 | use Magento\Framework\Pricing\Helper\Data as PricingHelper; | |||
| 43 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | 43 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | |||
| 44 | use Magento\Reports\Model\ResourceModel\Product\Collection as ReportsCollection; | 44 | use Magento\Reports\Model\ResourceModel\Product\Collection as ReportsCollection; | |||
| 45 | use Magento\Reports\Model\ResourceModel\Product\CollectionFactory as ReportsCollectionFactory; | 45 | use Magento\Reports\Model\ResourceModel\Product\CollectionFactory as ReportsCollectionFactory; | |||
| 46 | use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellerProduct; | 46 | use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellerProduct; | |||
| 47 | use Magento\Store\Model\Store; | 47 | use Magento\Store\Model\Store; | |||
| 48 | use Magento\Store\Model\StoreManagerInterface; | 48 | use Magento\Store\Model\StoreManagerInterface; | |||
| 49 | use Mageplaza\Core\Helper\AbstractData; | 49 | use Mageplaza\Core\Helper\AbstractData; | |||
| 50 | use Mageplaza\Search\Model\Config\Source\Search; | 50 | use Mageplaza\Search\Model\Config\Source\Search; | |||
| 51 | 51 | |||||
| 52 | /** | 52 | /** | |||
| 53 | * Class Data | 53 | * Class Data | |||
| 54 | * @package Mageplaza\Search\Helper | 54 | * @package Mageplaza\Search\Helper | |||
| 55 | */ | 55 | */ | |||
| 56 | class Data extends AbstractData | 56 | class Data extends AbstractData | |||
| 57 | { | 57 | { | |||
| 58 | const CONFIG_MODULE_PATH = 'mpsearch'; | 58 | const CONFIG_MODULE_PATH = 'mpsearch'; | |||
| 59 | const MAX_QUERY_RESULT = 'max_query_results'; | 59 | const MAX_QUERY_RESULT = 'max_query_results'; | |||
| 60 | 60 | |||||
| 61 | /** | 61 | /** | |||
| 62 | * @var Visibility | 62 | * @var Visibility | |||
| 63 | */ | 63 | */ | |||
| 64 | protected $productVisibility; | 64 | protected $productVisibility; | |||
| 65 | 65 | |||||
| 66 | /** | 66 | /** | |||
| 67 | * @var Config | 67 | * @var Config | |||
| 68 | */ | 68 | */ | |||
| 69 | protected $catalogConfig; | 69 | protected $catalogConfig; | |||
| 70 | 70 | |||||
| 71 | /** | 71 | /** | |||
| 72 | * @var PricingHelper | 72 | * @var PricingHelper | |||
| 73 | */ | 73 | */ | |||
| 74 | protected $_priceHelper; | 74 | protected $_priceHelper; | |||
| 75 | 75 | |||||
| 76 | /** | 76 | /** | |||
| 77 | * @var Escaper | 77 | * @var Escaper | |||
| 78 | */ | 78 | */ | |||
| 79 | protected $_escaper; | 79 | protected $_escaper; | |||
| 80 | 80 | |||||
| 81 | /** | 81 | /** | |||
| 82 | * @var Session | 82 | * @var Session | |||
| 83 | */ | 83 | */ | |||
| 84 | protected $_customerSession; | 84 | protected $_customerSession; | |||
| 85 | 85 | |||||
| 86 | /** | 86 | /** | |||
| 87 | * @var CollectionFactory | 87 | * @var CollectionFactory | |||
| 88 | */ | 88 | */ | |||
| 89 | protected $_customerGroupFactory; | 89 | protected $_customerGroupFactory; | |||
| 90 | 90 | |||||
| 91 | /** | 91 | /** | |||
| 92 | * @var FormatInterface | 92 | * @var FormatInterface | |||
| 93 | */ | 93 | */ | |||
| 94 | protected $localeFormat; | 94 | protected $localeFormat; | |||
| 95 | 95 | |||||
| 96 | /** | 96 | /** | |||
| 97 | * @var CategoryFactory | 97 | * @var CategoryFactory | |||
| 98 | */ | 98 | */ | |||
| 99 | 99 | |||||
| 100 | /** | 100 | /** | |||
| 101 | * @var CategoryFactory | 101 | * @var CategoryFactory | |||
| 102 | */ | 102 | */ | |||
| 103 | protected $categoryFactory; | 103 | protected $categoryFactory; | |||
| 104 | 104 | |||||
| 105 | /** | 105 | /** | |||
| 106 | * @var CatalogCollectionFactory | 106 | * @var CatalogCollectionFactory | |||
| 107 | */ | 107 | */ | |||
| 108 | protected $_productsFactory; | 108 | protected $_productsFactory; | |||
| 109 | 109 | |||||
| 110 | /** | 110 | /** | |||
| 111 | * @var BestSellerProduct | 111 | * @var BestSellerProduct | |||
| 112 | */ | 112 | */ | |||
| 113 | protected $bestsellersCollection; | 113 | protected $bestsellersCollection; | |||
| 114 | 114 | |||||
| 115 | /** | 115 | /** | |||
| 116 | * @var TimezoneInterface | 116 | * @var TimezoneInterface | |||
| 117 | */ | 117 | */ | |||
| 118 | protected $_localeDate; | 118 | protected $_localeDate; | |||
| 119 | /** | 119 | /** | |||
| 120 | * @var ReportsCollectionFactory | 120 | * @var ReportsCollectionFactory | |||
| 121 | */ | 121 | */ | |||
| 122 | protected $reportCollectionFactory; | 122 | protected $reportCollectionFactory; | |||
| 123 | /** | 123 | /** | |||
| 124 | * @var Currency | 124 | * @var Currency | |||
| 125 | */ | 125 | */ | |||
| 126 | protected $_currency; | 126 | protected $_currency; | |||
| 127 | /** | 127 | /** | |||
| 128 | * @var Configurable | 128 | * @var Configurable | |||
| 129 | */ | 129 | */ | |||
| 130 | protected $_catalogProductTypeConfigurable; | 130 | protected $_catalogProductTypeConfigurable; | |||
| 131 | 131 | |||||
| 132 | /** | 132 | /** | |||
| 133 | * Data constructor. | 133 | * Data constructor. | |||
| 134 | * | 134 | * | |||
| 135 | * @param Context $context | 135 | * @param Context $context | |||
| 136 | * @param StoreManagerInterface $storeManager | 136 | * @param StoreManagerInterface $storeManager | |||
| 137 | * @param ObjectManagerInterface $objectManager | 137 | * @param ObjectManagerInterface $objectManager | |||
| 138 | * @param CollectionFactory $customerGroupCollectionFactory | 138 | * @param CollectionFactory $customerGroupCollectionFactory | |||
| 139 | * @param Escaper $escaper | 139 | * @param Escaper $escaper | |||
| 140 | * @param PricingHelper $priceHelper | 140 | * @param PricingHelper $priceHelper | |||
| 141 | * @param Visibility $catalogProductVisibility | 141 | * @param Visibility $catalogProductVisibility | |||
| 142 | * @param Config $catalogConfig | 142 | * @param Config $catalogConfig | |||
| 143 | * @param Session $customerSession | 143 | * @param Session $customerSession | |||
| 144 | * @param FormatInterface $localeFormat | 144 | * @param FormatInterface $localeFormat | |||
| 145 | * @param CategoryFactory $categoryFactory | 145 | * @param CategoryFactory $categoryFactory | |||
| 146 | * @param CatalogCollectionFactory $productsFactory | 146 | * @param CatalogCollectionFactory $productsFactory | |||
| 147 | * @param ReportsCollectionFactory $reportCollectionFactory | 147 | * @param ReportsCollectionFactory $reportCollectionFactory | |||
| 148 | * @param BestSellerProduct $bestsellersCollection | 148 | * @param BestSellerProduct $bestsellersCollection | |||
| 149 | * @param TimezoneInterface $localDate | 149 | * @param TimezoneInterface $localDate | |||
| 150 | * @param Currency $currency | 150 | * @param Currency $currency | |||
| 151 | * @param Configurable $catalogProductTypeConfigurable | 151 | * @param Configurable $catalogProductTypeConfigurable | |||
| 152 | */ | 152 | */ | |||
| 153 | public function __construct( | 153 | public function __construct( | |||
| 154 | Context $context, | 154 | Context $context, | |||
| 155 | StoreManagerInterface $storeManager, | 155 | StoreManagerInterface $storeManager, | |||
| 156 | ObjectManagerInterface $objectManager, | 156 | ObjectManagerInterface $objectManager, | |||
| 157 | CollectionFactory $customerGroupCollectionFactory, | 157 | CollectionFactory $customerGroupCollectionFactory, | |||
| 158 | Escaper $escaper, | 158 | Escaper $escaper, | |||
| 159 | PricingHelper $priceHelper, | 159 | PricingHelper $priceHelper, | |||
| 160 | Visibility $catalogProductVisibility, | 160 | Visibility $catalogProductVisibility, | |||
| 161 | Config $catalogConfig, | 161 | Config $catalogConfig, | |||
| 162 | Session $customerSession, | 162 | Session $customerSession, | |||
| 163 | FormatInterface $localeFormat, | 163 | FormatInterface $localeFormat, | |||
| 164 | CategoryFactory $categoryFactory, | 164 | CategoryFactory $categoryFactory, | |||
| 165 | CatalogCollectionFactory $productsFactory, | 165 | CatalogCollectionFactory $productsFactory, | |||
| 166 | ReportsCollectionFactory $reportCollectionFactory, | 166 | ReportsCollectionFactory $reportCollectionFactory, | |||
| 167 | BestSellerProduct $bestsellersCollection, | 167 | BestSellerProduct $bestsellersCollection, | |||
| 168 | TimezoneInterface $localDate, | 168 | TimezoneInterface $localDate, | |||
| 169 | Currency $currency, | 169 | Currency $currency, | |||
| 170 | Configurable $catalogProductTypeConfigurable | 170 | Configurable $catalogProductTypeConfigurable | |||
| 171 | ) | 171 | ) | |||
| 172 | { | 172 | { | |||
| 173 | $this->_customerGroupFactory = $customerGroupCollectionFactory; | 173 | $this->_customerGroupFactory = $customerGroupCollectionFactory; | |||
| 174 | $this->_escaper = $escaper; | 174 | $this->_escaper = $escaper; | |||
| 175 | $this->_priceHelper = $priceHelper; | 175 | $this->_priceHelper = $priceHelper; | |||
| 176 | $this->productVisibility = $catalogProductVisibility; | 176 | $this->productVisibility = $catalogProductVisibility; | |||
| 177 | $this->catalogConfig = $catalogConfig; | 177 | $this->catalogConfig = $catalogConfig; | |||
| 178 | $this->_customerSession = $customerSession; | 178 | $this->_customerSession = $customerSession; | |||
| 179 | $this->localeFormat = $localeFormat; | 179 | $this->localeFormat = $localeFormat; | |||
| 180 | $this->categoryFactory = $categoryFactory; | 180 | $this->categoryFactory = $categoryFactory; | |||
| 181 | $this->_productsFactory = $productsFactory; | 181 | $this->_productsFactory = $productsFactory; | |||
| 182 | $this->bestsellersCollection = $bestsellersCollection; | 182 | $this->bestsellersCollection = $bestsellersCollection; | |||
| 183 | $this->_localeDate = $localDate; | 183 | $this->_localeDate = $localDate; | |||
| 184 | $this->reportCollectionFactory = $reportCollectionFactory; | 184 | $this->reportCollectionFactory = $reportCollectionFactory; | |||
| 185 | $this->_currency = $currency; | 185 | $this->_currency = $currency; | |||
| 186 | $this->_catalogProductTypeConfigurable = $catalogProductTypeConfigurable; | 186 | $this->_catalogProductTypeConfigurable = $catalogProductTypeConfigurable; | |||
| 187 | 187 | |||||
| 188 | parent::__construct($context, $objectManager, $storeManager); | 188 | parent::__construct($context, $objectManager, $storeManager); | |||
| 189 | } | 189 | } | |||
| 190 | 190 | |||||
| 191 | /** | 191 | /** | |||
| 192 | * @param null $store | 192 | * @param null $store | |||
| 193 | * | 193 | * | |||
| 194 | * @return string | 194 | * @return string | |||
| 195 | */ | 195 | */ | |||
| 196 | public function getSearchBy($store = null) | 196 | public function getSearchBy($store = null) | |||
| 197 | { | 197 | { | |||
| 198 | $searchBy = $this->getConfigGeneral('search_by', $store); | 198 | $searchBy = $this->getConfigGeneral('search_by', $store); | |||
| 199 | 199 | |||||
| 200 | return self::jsonEncode(explode(',', $searchBy)); | 200 | return self::jsonEncode(explode(',', $searchBy)); | |||
| 201 | } | 201 | } | |||
| 202 | 202 | |||||
| 203 | /** | 203 | /** | |||
| 204 | * @return mixed | 204 | * @return mixed | |||
| 205 | * @throws NoSuchEntityException | 205 | * @throws NoSuchEntityException | |||
| 206 | */ | 206 | */ | |||
| 207 | public function getCurrentCurrencyRate() | 207 | public function getCurrentCurrencyRate() | |||
| 208 | { | 208 | { | |||
| 209 | $currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode(); | 209 | $currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode(); | |||
| 210 | 210 | |||||
| 211 | return $this->storeManager->getStore()->getBaseCurrency()->getRate($currencyCode); | 211 | return $this->storeManager->getStore()->getBaseCurrency()->getRate($currencyCode); | |||
| 212 | } | 212 | } | |||
| 213 | 213 | |||||
| 214 | /** | 214 | /** | |||
| 215 | * @param null $store | 215 | * @param null $store | |||
| 216 | * | 216 | * | |||
| 217 | * @return string | 217 | * @return string | |||
| 218 | */ | 218 | */ | |||
| 219 | public function getDisplay($store = null) | 219 | public function getDisplay($store = null) | |||
| 220 | { | 220 | { | |||
| 221 | $searchBy = $this->getConfigGeneral('display', $store); | 221 | $searchBy = $this->getConfigGeneral('display', $store); | |||
| 222 | 222 | |||||
| 223 | return self::jsonEncode(explode(',', $searchBy)); | 223 | return self::jsonEncode(explode(',', $searchBy)); | |||
| 224 | } | 224 | } | |||
| 225 | 225 | |||||
| 226 | /** | 226 | /** | |||
| 227 | * @param null $storeId | 227 | * @param null $storeId | |||
| 228 | * | 228 | * | |||
| 229 | * @return bool | 229 | * @return bool | |||
| 230 | */ | 230 | */ | |||
| 231 | public function isEnableSuggestion($storeId = null) | 231 | public function isEnableSuggestion($storeId = null) | |||
| 232 | { | 232 | { | |||
| 233 | return $this->getConfigGeneral('search_by/enable', $storeId); | 233 | return $this->getConfigGeneral('search_by/enable', $storeId); | |||
| 234 | } | 234 | } | |||
| 235 | 235 | |||||
| 236 | /** | 236 | /** | |||
| 237 | * @param null $storeId | 237 | * @param null $storeId | |||
| 238 | * | 238 | * | |||
| 239 | * @return mixed | 239 | * @return mixed | |||
| 240 | */ | 240 | */ | |||
| 241 | public function getSortBy($storeId = null) | 241 | public function getSortBy($storeId = null) | |||
| 242 | { | 242 | { | |||
| 243 | return $this->getConfigGeneral('search_by/sort_by', $storeId); | 243 | return $this->getConfigGeneral('search_by/sort_by', $storeId); | |||
| 244 | } | 244 | } | |||
| 245 | 245 | |||||
| 246 | /** | 246 | /** | |||
| 247 | * Create json file to contain product data | 247 | * Create json file to contain product data | |||
| 248 | * @return array | 248 | * @return array | |||
| 249 | */ | 249 | */ | |||
| 250 | public function createJsonFile() | 250 | public function createJsonFile() | |||
| 251 | { | 251 | { | |||
| 252 | $errors = []; | 252 | $errors = []; | |||
| 253 | $customerGroups = $this->_customerGroupFactory->create(); | 253 | $customerGroups = $this->_customerGroupFactory->create(); | |||
| 254 | foreach ($this->storeManager->getStores() as $store) { | 254 | foreach ($this->storeManager->getStores() as $store) { | |||
| 255 | foreach ($customerGroups as $group) { | 255 | foreach ($customerGroups as $group) { | |||
| 256 | try { | 256 | try { | |||
| 257 | $this->createJsonFileForStore($store, $group->getId()); | 257 | $this->createJsonFileForStore($store, $group->getId()); | |||
| 258 | } catch (Exception $e) { | 258 | } catch (Exception $e) { | |||
| 259 | $errors[] = __( | 259 | $errors[] = __( | |||
| 260 | 'Cannot generate data for store %1 and customer group %2, %3', | 260 | 'Cannot generate data for store %1 and customer group %2, %3', | |||
| 261 | $store->getCode(), | 261 | $store->getCode(), | |||
| 262 | $group->getCode(), | 262 | $group->getCode(), | |||
| 263 | $e->getMessage() | 263 | $e->getMessage() | |||
| 264 | ); | 264 | ); | |||
| 265 | } | 265 | } | |||
| 266 | } | 266 | } | |||
| 267 | } | 267 | } | |||
| 268 | 268 | |||||
| 269 | return $errors; | 269 | return $errors; | |||
| 270 | } | 270 | } | |||
| 271 | 271 | |||||
| 272 | /** | 272 | /** | |||
| 273 | * @param $store | 273 | * @param $store | |||
| 274 | * @param $group | 274 | * @param $group | |||
| 275 | * | 275 | * | |||
| 276 | * @return $this | 276 | * @return $this | |||
| 277 | */ | 277 | */ | |||
| 278 | public function createJsonFileForStore($store, $group) | 278 | public function createJsonFileForStore($store, $group) | |||
| 279 | { | 279 | { | |||
| 280 | if (!$this->isEnabled($store->getId())) { | 280 | if (!$this->isEnabled($store->getId())) { | |||
| 281 | return $this; | 281 | return $this; | |||
| 282 | } | 282 | } | |||
| 283 | 283 | |||||
| 284 | $products = $this->createJsonFileProduct($store, $this->getProducts($store, $group), Search::PRODUCT_SEARCH); | 284 | $products = $this->createJsonFileProduct($store, $this->getProducts($store, $group), Search::PRODUCT_SEARCH); | |||
| 285 | 285 | |||||
| 286 | $newProducts = $this->createJsonFileProduct( | 286 | $newProducts = $this->createJsonFileProduct( | |||
| 287 | $store, | 287 | $store, | |||
| 288 | $this->getNewProducts($store, $group), | 288 | $this->getNewProducts($store, $group), | |||
| 289 | Search::NEW_PRODUCTS | 289 | Search::NEW_PRODUCTS | |||
| 290 | ); | 290 | ); | |||
| 291 | 291 | |||||
| 292 | $mostViewedProducts = $this->createJsonFileProduct( | 292 | $mostViewedProducts = $this->createJsonFileProduct( | |||
| 293 | $store, | 293 | $store, | |||
| 294 | $this->getMostViewedProducts($store), | 294 | $this->getMostViewedProducts($store), | |||
| 295 | Search::MOST_VIEWED_PRODUCTS | 295 | Search::MOST_VIEWED_PRODUCTS | |||
| 296 | ); | 296 | ); | |||
| 297 | 297 | |||||
| 298 | $bestsellers = $this->createJsonFileProduct($store, $this->getBestSellers($store, $group), Search::BESTSELLERS); | 298 | $bestsellers = $this->createJsonFileProduct($store, $this->getBestSellers($store, $group), Search::BESTSELLERS); | |||
| 299 | 299 | |||||
| 300 | $this->getMediaHelper()->createJsFile( | 300 | $this->getMediaHelper()->createJsFile( | |||
| 301 | $this->getJsFilePath($group, $store), | 301 | $this->getJsFilePath($group, $store), | |||
| 302 | ';var mp_products_search = ' . $products . ';' | 302 | ';var mp_products_search = ' . $products . ';' | |||
| 303 | ); | 303 | ); | |||
| 304 | $this->getMediaHelper()->createJsFile( | 304 | $this->getMediaHelper()->createJsFile( | |||
| 305 | $this->getAdditionJsFilePath($group, $store), | 305 | $this->getAdditionJsFilePath($group, $store), | |||
| 306 | ';var mp_new_product_search = ' . $newProducts . '; | 306 | ';var mp_new_product_search = ' . $newProducts . '; | |||
| 307 | var mp_most_viewed_products = ' . $mostViewedProducts . '; | 307 | var mp_most_viewed_products = ' . $mostViewedProducts . '; | |||
| 308 | var mp_bestsellers = ' . $bestsellers . ';' | 308 | var mp_bestsellers = ' . $bestsellers . ';' | |||
| 309 | ); | 309 | ); | |||
| 310 | 310 | |||||
| 311 | return $this; | 311 | return $this; | |||
| 312 | } | 312 | } | |||
| 313 | 313 | |||||
| 314 | /** | 314 | /** | |||
| 315 | * @param null $storeId | 315 | * @param null $storeId | |||
| 316 | * | 316 | * | |||
| 317 | * @return bool | 317 | * @return bool | |||
| 318 | */ | 318 | */ | |||
| 319 | public function isEnabled($storeId = null) | 319 | public function isEnabled($storeId = null) | |||
| 320 | { | 320 | { | |||
| 321 | return $this->getConfigGeneral('enabled', $storeId) && $this->isModuleOutputEnabled(); | 321 | return $this->getConfigGeneral('enabled', $storeId) && $this->isModuleOutputEnabled(); | |||
| 322 | } | 322 | } | |||
| 323 | 323 | |||||
| 324 | /** | 324 | /** | |||
| 325 | * @param $store | 325 | * @param $store | |||
| 326 | * @param $collection | 326 | * @param $collection | |||
| 327 | * @param $option | 327 | * @param $option | |||
| 328 | * | 328 | * | |||
| 329 | * @return $this|string | 329 | * @return $this|string | |||
| 330 | */ | 330 | */ | |||
| 331 | public function createJsonFileProduct($store, $collection, $option) | 331 | public function createJsonFileProduct($store, $collection, $option) | |||
| 332 | { | 332 | { | |||
| 333 | if (!$this->isEnabled($store->getId())) { | 333 | if (!$this->isEnabled($store->getId())) { | |||
| 334 | return $this; | 334 | return $this; | |||
| 335 | } | 335 | } | |||
| 336 | 336 | |||||
| 337 | $productList = []; | 337 | $productList = []; | |||
| 338 | $maxQueryResults = $this->getConfigGeneral(self::MAX_QUERY_RESULT); | 338 | $maxQueryResults = $this->getConfigGeneral(self::MAX_QUERY_RESULT); | |||
| 339 | $resultCount = 0; | 339 | $resultCount = 0; | |||
| 340 | 340 | |||||
| 341 | /** @var Product $product */ | 341 | /** @var Product $product */ | |||
| 342 | foreach ($collection as $product) { | 342 | foreach ($collection as $product) { | |||
| 343 | /** The maximum results of [Most Viewed | New Products| Bestsellers] is $maxQueryResults*/ | 343 | /** The maximum results of [Most Viewed | New Products| Bestsellers] is $maxQueryResults*/ | |||
| 344 | if ($option === Search::PRODUCT_SEARCH | 344 | if ($option === Search::PRODUCT_SEARCH | |||
| 345 | || ($option !== Search::PRODUCT_SEARCH && $resultCount < $maxQueryResults) | 345 | || ($option !== Search::PRODUCT_SEARCH && $resultCount < $maxQueryResults) | |||
| 346 | ) { | 346 | ) { | |||
| 347 | if (!$product->getId() || !$product->getName()) { | 347 | if (!$product->getId() || !$product->getName()) { | |||
| 348 | continue; | 348 | continue; | |||
| 349 | } | 349 | } | |||
| 350 | 350 | |||||
| 351 | $productPrice = $product->getFinalPrice(); | 351 | $productPrice = $product->getFinalPrice(); | |||
| 352 | if ($product->getTypeId() === 'bundle') { | 352 | if ($product->getTypeId() === 'bundle') { | |||
| 353 | $productPrice = $product->getMinPrice() . '-' . $product->getMaxPrice(); | 353 | $productPrice = $product->getMinPrice() . '-' . $product->getMaxPrice(); | |||
| 354 | $currencySymbol = $this->_currency->getCurrencySymbol(); | 354 | $currencySymbol = $this->_currency->getCurrencySymbol(); | |||
| 355 | $productPrice = str_replace($currencySymbol, '', $productPrice); | 355 | $productPrice = str_replace($currencySymbol, '', $productPrice); | |||
| 356 | } elseif ($product->getTypeId() === 'grouped') { | 356 | } elseif ($product->getTypeId() === 'grouped') { | |||
| 357 | $productPrice = $product->getMinimalPrice(); | 357 | $productPrice = $product->getMinimalPrice(); | |||
| 358 | } | 358 | } | |||
| 359 | 359 | |||||
| 360 | $parentIds = []; | 360 | $parentIds = []; | |||
| 361 | $categories = $this->categoryFactory->create(); | 361 | $categories = $this->categoryFactory->create(); | |||
| 362 | foreach ($product->getCategoryIds() as $id) { | 362 | foreach ($product->getCategoryIds() as $id) { | |||
| 363 | $parentIds[] = $id; | 363 | $parentIds[] = $id; | |||
| 364 | $categoryCollection = $categories->load($id); | 364 | $categoryCollection = $categories->load($id); | |||
| 365 | foreach ($categoryCollection->getParentIds() as $parentId) { | 365 | foreach ($categoryCollection->getParentIds() as $parentId) { | |||
| 366 | $parentIds[] = $parentId; | 366 | $parentIds[] = $parentId; | |||
| 367 | } | 367 | } | |||
| 368 | } | 368 | } | |||
| 369 | 369 | |||||
| 370 | $productList[] = [ | 370 | $productList[] = [ | |||
| 371 | 'value' => $product->getName(), | 371 | 'value' => $product->getName(), | |||
| 372 | //sku | 372 | //sku | |||
| 373 | 's' => $product->getSku(), | 373 | 's' => $product->getSku(), | |||
| 374 | //categoryIds | 374 | //categoryIds | |||
| 375 | 'c' => $parentIds, | 375 | 'c' => $parentIds, | |||
| 376 | //short description | 376 | //short description | |||
| 377 | 'd' => $this->getProductDescription($product, $store), | 377 | 'd' => $this->getProductDescription($product, $store), | |||
| 378 | //price | 378 | //price | |||
| 379 | 'p' => $productPrice, | 379 | 'p' => $productPrice, | |||
| 380 | //image | 380 | //image | |||
| 381 | 'i' => $this->getMediaHelper()->getProductImage($product), | 381 | 'i' => $this->getMediaHelper()->getProductImage($product), | |||
| 382 | //product url | 382 | //product url | |||
| 383 | 'u' => $this->getProductUrl($product), | 383 | 'u' => $this->getProductUrl($product), | |||
| 384 | 'o' => $option | 384 | 'o' => $option | |||
| 385 | ]; | 385 | ]; | |||
| 386 | } | 386 | } | |||
| 387 | 387 | |||||
| 388 | $resultCount++; | 388 | $resultCount++; | |||
| 389 | } | 389 | } | |||
| 390 | 390 | |||||
| 391 | return self::jsonEncode($productList); | 391 | return self::jsonEncode($productList); | |||
| 392 | } | 392 | } | |||
| 393 | 393 | |||||
| 394 | /** | 394 | /** | |||
| 395 | * @param $product | 395 | * @param $product | |||
| 396 | * @param $store | 396 | * @param $store | |||
| 397 | * | 397 | * | |||
| 398 | * @return array|bool|string | 398 | * @return array|bool|string | |||
| 399 | */ | 399 | */ | |||
| 400 | protected function getProductDescription($product, $store) | 400 | protected function getProductDescription($product, $store) | |||
| 401 | { | 401 | { | |||
| 402 | $attributeHtml = strip_tags($product->getShortDescription( | 402 | $attributeHtml = strip_tags( | |||
| 403 | $attributeHtml = trim($this->_escaper->escapeHtml($attributeHtml)); | 403 | $attributeHtml = trim($this->_escaper->escapeHtml($attributeHtml)); | |||
| 404 | 404 | |||||
| 405 | $limitDesLetter = (int) $this->getConfigGeneral('max_letter_numbers', $store->getId()); | 405 | $limitDesLetter = (int) $this->getConfigGeneral('max_letter_numbers', $store->getId()); | |||
| 406 | if ($limitDesLetter > 0 && strlen($attributeHtml) > $limitDesLetter) { | 406 | if ($limitDesLetter > 0 && strlen($attributeHtml) > $limitDesLetter) { | |||
| 407 | $attributeHtml = mb_substr($attributeHtml, 0, $limitDesLetter, mb_detect_encoding($attributeHtml)); | 407 | $attributeHtml = mb_substr($attributeHtml, 0, $limitDesLetter, mb_detect_encoding($attributeHtml)); | |||
| 408 | $attributeHtml .= '...'; | 408 | $attributeHtml .= '...'; | |||
| 409 | } | 409 | } | |||
| 410 | 410 | |||||
| 411 | return $attributeHtml; | 411 | return $attributeHtml; | |||
| 412 | } | 412 | } | |||
| 413 | 413 | |||||
| 414 | /** | 414 | /** | |||
| 415 | * @return Media | 415 | * @return Media | |||
| 416 | */ | 416 | */ | |||
| 417 | public function getMediaHelper() | 417 | public function getMediaHelper() | |||
| 418 | { | 418 | { | |||
| 419 | return $this->objectManager->get(Media::class); | 419 | return $this->objectManager->get(Media::class); | |||
| 420 | } | 420 | } | |||
| 421 | 421 | |||||
| 422 | /** | 422 | /** | |||
| 423 | * @param Product $product | 423 | * @param Product $product | |||
| 424 | * | 424 | * | |||
| 425 | * @return bool|string | 425 | * @return bool|string | |||
| 426 | */ | 426 | */ | |||
| 427 | protected function getProductUrl($product) | 427 | protected function getProductUrl($product) | |||
| 428 | { | 428 | { | |||
| 429 | $requestPath = $product->getRequestPath(); | 429 | $requestPath = $product->getRequestPath(); | |||
| 430 | if (!$requestPath) { | 430 | if (!$requestPath) { | |||
| 431 | $productUrl = $product->getProductUrl(); | 431 | $productUrl = $product->getProductUrl(); | |||
| 432 | $pos = strpos($productUrl, 'catalog/product/view'); | 432 | $pos = strpos($productUrl, 'catalog/product/view'); | |||
| 433 | if ($pos !== false) { | 433 | if ($pos !== false) { | |||
| 434 | $requestPath = substr($productUrl, $pos + 20); | 434 | $requestPath = substr($productUrl, $pos + 20); | |||
| 435 | } | 435 | } | |||
| 436 | } | 436 | } | |||
| 437 | 437 | |||||
| 438 | return $requestPath; | 438 | return $requestPath; | |||
| 439 | } | 439 | } | |||
| 440 | 440 | |||||
| 441 | /** | 441 | /** | |||
| 442 | * @param $store | 442 | * @param $store | |||
| 443 | * @param $group | 443 | * @param $group | |||
| 444 | * | 444 | * | |||
| 445 | * @return CatalogCollection | 445 | * @return CatalogCollection | |||
| 446 | */ | 446 | */ | |||
| 447 | public function getProducts($store, $group) | 447 | public function getProducts($store, $group) | |||
| 448 | { | 448 | { | |||
| 449 | /** @var CatalogCollection $collection */ | 449 | /** @var CatalogCollection $collection */ | |||
| 450 | $collection = $this->_productsFactory->create(); | 450 | $collection = $this->_productsFactory->create(); | |||
| 451 | $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | 451 | $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | |||
| 452 | ->setStore($store) | 452 | ->setStore($store) | |||
| 453 | ->addPriceData($group) | 453 | ->addPriceData($group) | |||
| 454 | ->addMinimalPrice() | 454 | ->addMinimalPrice() | |||
| 455 | ->addFinalPrice() | 455 | ->addFinalPrice() | |||
| 456 | ->addTaxPercents() | 456 | ->addTaxPercents() | |||
| 457 | ->addStoreFilter() | 457 | ->addStoreFilter() | |||
| 458 | ->addUrlRewrite() | 458 | ->addUrlRewrite() | |||
| 459 | ->setVisibility($this->productVisibility->getVisibleInSearchIds()); | 459 | ->setVisibility($this->productVisibility->getVisibleInSearchIds()); | |||
| 460 | 460 | |||||
| 461 | return $collection; | 461 | return $collection; | |||
| 462 | } | 462 | } | |||
| 463 | 463 | |||||
| 464 | /** | 464 | /** | |||
| 465 | * @param $store | 465 | * @param $store | |||
| 466 | * @param $group | 466 | * @param $group | |||
| 467 | * | 467 | * | |||
| 468 | * @return CatalogCollection | 468 | * @return CatalogCollection | |||
| 469 | */ | 469 | */ | |||
| 470 | public function getNewProducts($store, $group) | 470 | public function getNewProducts($store, $group) | |||
| 471 | { | 471 | { | |||
| 472 | $collection = $this->_productsFactory->create(); | 472 | $collection = $this->_productsFactory->create(); | |||
| 473 | $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s'); | 473 | $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s'); | |||
| 474 | $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s'); | 474 | $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s'); | |||
| 475 | $ids = []; | 475 | $ids = []; | |||
| 476 | 476 | |||||
| 477 | $collectionBoth = clone $collection; | 477 | $collectionBoth = clone $collection; | |||
| 478 | $collectionBoth->addAttributeToFilter('news_from_date', ['date' => true, 'to' => $todayStartOfDayDate]) | 478 | $collectionBoth->addAttributeToFilter('news_from_date', ['date' => true, 'to' => $todayStartOfDayDate]) | |||
| 479 | ->addAttributeToFilter('news_to_date', ['date' => true, 'from' => $todayEndOfDayDate]); | 479 | ->addAttributeToFilter('news_to_date', ['date' => true, 'from' => $todayEndOfDayDate]); | |||
| 480 | 480 | |||||
| 481 | if ($collectionBoth->getSize() !== 0) { | 481 | if ($collectionBoth->getSize() !== 0) { | |||
| 482 | foreach ($collectionBoth->getData() as $v) { | 482 | foreach ($collectionBoth->getData() as $v) { | |||
| 483 | $ids[] = $v['entity_id']; | 483 | $ids[] = $v['entity_id']; | |||
| 484 | } | 484 | } | |||
| 485 | } | 485 | } | |||
| 486 | $collectionBoth->clear(); | 486 | $collectionBoth->clear(); | |||
| 487 | 487 | |||||
| 488 | $collectionFrom = clone $collection; | 488 | $collectionFrom = clone $collection; | |||
| 489 | $collectionFrom->addAttributeToFilter('news_from_date', ['date' => true, 'to' => $todayStartOfDayDate]); | 489 | $collectionFrom->addAttributeToFilter('news_from_date', ['date' => true, 'to' => $todayStartOfDayDate]); | |||
| 490 | 490 | |||||
| 491 | if ($collectionFrom->getSize() !== 0) { | 491 | if ($collectionFrom->getSize() !== 0) { | |||
| 492 | foreach ($collectionFrom->getData() as $v) { | 492 | foreach ($collectionFrom->getData() as $v) { | |||
| 493 | $ids[] = $v['entity_id']; | 493 | $ids[] = $v['entity_id']; | |||
| 494 | } | 494 | } | |||
| 495 | } | 495 | } | |||
| 496 | $collectionFrom->clear(); | 496 | $collectionFrom->clear(); | |||
| 497 | 497 | |||||
| 498 | $collectionTo = clone $collection; | 498 | $collectionTo = clone $collection; | |||
| 499 | $collectionTo->addAttributeToFilter('news_to_date', ['date' => true, 'from' => $todayEndOfDayDate]); | 499 | $collectionTo->addAttributeToFilter('news_to_date', ['date' => true, 'from' => $todayEndOfDayDate]); | |||
| 500 | 500 | |||||
| 501 | if ($collectionTo->getSize() !== 0) { | 501 | if ($collectionTo->getSize() !== 0) { | |||
| 502 | foreach ($collectionTo->getData() as $v) { | 502 | foreach ($collectionTo->getData() as $v) { | |||
| 503 | $ids[] = $v['entity_id']; | 503 | $ids[] = $v['entity_id']; | |||
| 504 | } | 504 | } | |||
| 505 | } | 505 | } | |||
| 506 | $collectionTo->clear(); | 506 | $collectionTo->clear(); | |||
| 507 | 507 | |||||
| 508 | $ids = array_unique($ids); | 508 | $ids = array_unique($ids); | |||
| 509 | $entityId = implode(',', $ids); | 509 | $entityId = implode(',', $ids); | |||
| 510 | 510 | |||||
| 511 | $collection->addAttributeToFilter('entity_id', ['in' => $entityId]) | 511 | $collection->addAttributeToFilter('entity_id', ['in' => $entityId]) | |||
| 512 | ->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | 512 | ->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | |||
| 513 | ->setStore($store) | 513 | ->setStore($store) | |||
| 514 | ->addPriceData($group) | 514 | ->addPriceData($group) | |||
| 515 | ->addMinimalPrice() | 515 | ->addMinimalPrice() | |||
| 516 | ->addFinalPrice() | 516 | ->addFinalPrice() | |||
| 517 | ->addTaxPercents() | 517 | ->addTaxPercents() | |||
| 518 | ->addStoreFilter() | 518 | ->addStoreFilter() | |||
| 519 | ->addUrlRewrite() | 519 | ->addUrlRewrite() | |||
| 520 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | 520 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | |||
| 521 | 521 | |||||
| 522 | return $collection; | 522 | return $collection; | |||
| 523 | } | 523 | } | |||
| 524 | 524 | |||||
| 525 | /** | 525 | /** | |||
| 526 | * @param $store | 526 | * @param $store | |||
| 527 | * | 527 | * | |||
| 528 | * @return DataObject[] | 528 | * @return DataObject[] | |||
| 529 | */ | 529 | */ | |||
| 530 | public function getMostViewedProducts($store) | 530 | public function getMostViewedProducts($store) | |||
| 531 | { | 531 | { | |||
| 532 | $productIds = []; | 532 | $productIds = []; | |||
| 533 | /** @var ReportsCollection $collection */ | 533 | /** @var ReportsCollection $collection */ | |||
| 534 | $mostViewedProducts = $this->reportCollectionFactory->create()->addViewsCount(); | 534 | $mostViewedProducts = $this->reportCollectionFactory->create()->addViewsCount(); | |||
| 535 | 535 | |||||
| 536 | foreach ($mostViewedProducts as $product) { | 536 | foreach ($mostViewedProducts as $product) { | |||
| 537 | $productIds[] = $product->getData()['entity_id']; | 537 | $productIds[] = $product->getData()['entity_id']; | |||
| 538 | } | 538 | } | |||
| 539 | 539 | |||||
| 540 | $collection = $this->_productsFactory->create()->addIdFilter($productIds); | 540 | $collection = $this->_productsFactory->create()->addIdFilter($productIds); | |||
| 541 | $collection->addMinimalPrice() | 541 | $collection->addMinimalPrice() | |||
| 542 | ->addFinalPrice() | 542 | ->addFinalPrice() | |||
| 543 | ->addTaxPercents() | 543 | ->addTaxPercents() | |||
| 544 | ->addAttributeToSelect('*') | 544 | ->addAttributeToSelect('*') | |||
| 545 | ->addUrlRewrite() | 545 | ->addUrlRewrite() | |||
| 546 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | 546 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | |||
| 547 | $collection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$productIds)."')"); | |||||
| 547 | 548 | |||||
| 548 | return $collection->getItems(); | 549 | return $collection->getItems(); | |||
| 549 | } | 550 | } | |||
| 550 | 551 | |||||
| 551 | /** | 552 | /** | |||
| 552 | * @param $store | 553 | * @param $store | |||
| 553 | * @param $group | 554 | * @param $group | |||
| 554 | * | 555 | * | |||
| 555 | * @return DataObject[] | 556 | * @return DataObject[] | |||
| 556 | */ | 557 | */ | |||
| 557 | public function getBestSellers($store, $group) | 558 | public function getBestSellers($store, $group) | |||
| 558 | { | 559 | { | |||
| 559 | $productIds = []; | 560 | $productIds = []; | |||
| 560 | $bestSellers = $this->bestsellersCollection->create() | 561 | $bestSellers = $this->bestsellersCollection->create() | |||
| 561 | ->setModel('Magento\Catalog\Model\Product') | 562 | ->setModel('Magento\Catalog\Model\Product') | |||
| 562 | ->addStoreFilter($store->getId()) | 563 | ->addStoreFilter($store->getId()) | |||
| 563 | ->setPeriod('year')->addOrder('product_id'); | 564 | ->setPeriod('year')->addOrder('product_id'); | |||
| 564 | foreach ($bestSellers as $product) { | 565 | foreach ($bestSellers as $product) { | |||
| 565 | $productParent = $this->_catalogProductTypeConfigurable->getParentIdsByChild($product->getProductId()); | 566 | $productParent = $this->_catalogProductTypeConfigurable->getParentIdsByChild($product->getProductId()); | |||
| 566 | if (isset($productParent[0])) { | 567 | if (isset($productParent[0])) { | |||
| 567 | $productIds[]= $productParent[0]; | 568 | $productIds[]= $productParent[0]; | |||
| 568 | } else | 569 | } else | |||
| 569 | $productIds[] = $product->getProductId(); | 570 | $productIds[] = $product->getProductId(); | |||
| 570 | } | 571 | } | |||
| 571 | 572 | |||||
| 572 | $collection = $this->_productsFactory->create()->addIdFilter($productIds); | 573 | $collection = $this->_productsFactory->create()->addIdFilter($productIds); | |||
| 573 | $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | 574 | $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes()) | |||
| 574 | ->setStore($store) | 575 | ->setStore($store) | |||
| 575 | ->addPriceData($group) | 576 | ->addPriceData($group) | |||
| 576 | ->addMinimalPrice() | 577 | ->addMinimalPrice() | |||
| 577 | ->addFinalPrice() | 578 | ->addFinalPrice() | |||
| 578 | ->addTaxPercents() | 579 | ->addTaxPercents() | |||
| 579 | ->addStoreFilter() | 580 | ->addStoreFilter() | |||
| 580 | ->addUrlRewrite() | 581 | ->addUrlRewrite() | |||
| 581 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | 582 | ->setVisibility($this->productVisibility->getVisibleInSiteIds()); | |||
| 582 | $collection->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $productIds).')')); | 583 | $collection->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $productIds).')')); | |||
| 583 | 584 | |||||
| 584 | return $collection->getItems(); | 585 | return $collection->getItems(); | |||
| 585 | } | 586 | } | |||
| 586 | 587 | |||||
| 587 | /** | 588 | /** | |||
| 588 | * @param $customerGroupId | 589 | * @param $customerGroupId | |||
| 589 | * @param $store | 590 | * @param $store | |||
| 590 | * | 591 | * | |||
| 591 | * @return string | 592 | * @return string | |||
| 592 | */ | 593 | */ | |||
| 593 | public function getJsFilePath($customerGroupId, $store) | 594 | public function getJsFilePath($customerGroupId, $store) | |||
| 594 | { | 595 | { | |||
| 595 | return Media::TEMPLATE_MEDIA_PATH . '/' . $store->getCode() . '_' . $customerGroupId . '.js'; | 596 | return Media::TEMPLATE_MEDIA_PATH . '/' . $store->getCode() . '_' . $customerGroupId . '.js'; | |||
| 596 | } | 597 | } | |||
| 597 | 598 | |||||
| 598 | /** | 599 | /** | |||
| 599 | * @param $customerGroupId | 600 | * @param $customerGroupId | |||
| 600 | * @param $store | 601 | * @param $store | |||
| 601 | * | 602 | * | |||
| 602 | * @return string | 603 | * @return string | |||
| 603 | */ | 604 | */ | |||
| 604 | public function getAdditionJsFilePath($customerGroupId, $store) | 605 | public function getAdditionJsFilePath($customerGroupId, $store) | |||
| 605 | { | 606 | { | |||
| 606 | return Media::TEMPLATE_MEDIA_PATH . '/' . $store->getCode() . '_' . $customerGroupId . '_addition.js'; | 607 | return Media::TEMPLATE_MEDIA_PATH . '/' . $store->getCode() . '_' . $customerGroupId . '_addition.js'; | |||
| 607 | } | 608 | } | |||
| 608 | 609 | |||||
| 609 | /** | 610 | /** | |||
| 610 | * Create json file to contain new product, most viewed, bestsellers data | 611 | * Create json file to contain new product, most viewed, bestsellers data | |||
| 611 | * @return array | 612 | * @return array | |||
| 612 | */ | 613 | */ | |||
| 613 | public function createAdditionJsonFile() | 614 | public function createAdditionJsonFile() | |||
| 614 | { | 615 | { | |||
| 615 | $errors = []; | 616 | $errors = []; | |||
| 616 | $customerGroups = $this->_customerGroupFactory->create(); | 617 | $customerGroups = $this->_customerGroupFactory->create(); | |||
| 617 | foreach ($this->storeManager->getStores() as $store) { | 618 | foreach ($this->storeManager->getStores() as $store) { | |||
| 618 | foreach ($customerGroups as $group) { | 619 | foreach ($customerGroups as $group) { | |||
| 619 | try { | 620 | try { | |||
| 620 | $this->createAdditionJsonFileForStore($store, $group->getId()); | 621 | $this->createAdditionJsonFileForStore($store, $group->getId()); | |||
| 621 | } catch (Exception $e) { | 622 | } catch (Exception $e) { | |||
| 622 | $errors[] = __( | 623 | $errors[] = __( | |||
| 623 | 'Cannot generate data for store %1 and customer group %2, %3', | 624 | 'Cannot generate data for store %1 and customer group %2, %3', | |||
| 624 | $store->getCode(), | 625 | $store->getCode(), | |||
| 625 | $group->getCode(), | 626 | $group->getCode(), | |||
| 626 | $e->getMessage() | 627 | $e->getMessage() | |||
| 627 | ); | 628 | ); | |||
| 628 | } | 629 | } | |||
| 629 | } | 630 | } | |||
| 630 | } | 631 | } | |||
| 631 | 632 | |||||
| 632 | return $errors; | 633 | return $errors; | |||
| 633 | } | 634 | } | |||
| 634 | 635 | |||||
| 635 | /** | 636 | /** | |||
| 636 | * A cron job will run this function everyday | 637 | * A cron job will run this function everyday | |||
| 637 | * | 638 | * | |||
| 638 | * @param $store | 639 | * @param $store | |||
| 639 | * @param $group | 640 | * @param $group | |||
| 640 | * | 641 | * | |||
| 641 | * @return $this | 642 | * @return $this | |||
| 642 | */ | 643 | */ | |||
| 643 | public function createAdditionJsonFileForStore($store, $group) | 644 | public function createAdditionJsonFileForStore($store, $group) | |||
| 644 | { | 645 | { | |||
| 645 | $newProducts = $this->createJsonFileProduct( | 646 | $newProducts = $this->createJsonFileProduct( | |||
| 646 | $store, | 647 | $store, | |||
| 647 | $this->getNewProducts($store, $group), | 648 | $this->getNewProducts($store, $group), | |||
| 648 | Search::NEW_PRODUCTS | 649 | Search::NEW_PRODUCTS | |||
| 649 | ); | 650 | ); | |||
| 650 | 651 | |||||
| 651 | $mostViewedProducts = $this->createJsonFileProduct( | 652 | $mostViewedProducts = $this->createJsonFileProduct( | |||
| 652 | $store, | 653 | $store, | |||
| 653 | $this->getMostViewedProducts($store), | 654 | $this->getMostViewedProducts($store), | |||
| 654 | Search::MOST_VIEWED_PRODUCTS | 655 | Search::MOST_VIEWED_PRODUCTS | |||
| 655 | ); | 656 | ); | |||
| 656 | 657 | |||||
| 657 | $bestsellers = $this->createJsonFileProduct($store, $this->getBestSellers($store, $group), Search::BESTSELLERS); | 658 | $bestsellers = $this->createJsonFileProduct($store, $this->getBestSellers($store, $group), Search::BESTSELLERS); | |||
| 658 | 659 | |||||
| 659 | $this->getMediaHelper()->createJsFile( | 660 | $this->getMediaHelper()->createJsFile( | |||
| 660 | $this->getAdditionJsFilePath($group, $store), | 661 | $this->getAdditionJsFilePath($group, $store), | |||
| 661 | ';var mp_new_product_search = ' . $newProducts . '; | 662 | ';var mp_new_product_search = ' . $newProducts . '; | |||
| 662 | var mp_most_viewed_products = ' . $mostViewedProducts . '; | 663 | var mp_most_viewed_products = ' . $mostViewedProducts . '; | |||
| 663 | var mp_bestsellers = ' . $bestsellers . ';' | 664 | var mp_bestsellers = ' . $bestsellers . ';' | |||
| 664 | ); | 665 | ); | |||
| 665 | 666 | |||||
| 666 | return $this; | 667 | return $this; | |||
| 667 | } | 668 | } | |||
| 668 | 669 | |||||
| 669 | /** | 670 | /** | |||
| 670 | * @return string | 671 | * @return string | |||
| 671 | * @throws NoSuchEntityException | 672 | * @throws NoSuchEntityException | |||
| 672 | * @throws LocalizedException | 673 | * @throws LocalizedException | |||
| 673 | */ | 674 | */ | |||
| 674 | public function getJsFileUrl() | 675 | public function getJsFileUrl() | |||
| 675 | { | 676 | { | |||
| 676 | $customerGroupId = $this->_customerSession->getCustomerGroupId(); | 677 | $customerGroupId = $this->_customerSession->getCustomerGroupId(); | |||
| 677 | 678 | |||||
| 678 | /** @var Store $store */ | 679 | /** @var Store $store */ | |||
| 679 | $store = $this->storeManager->getStore(); | 680 | $store = $this->storeManager->getStore(); | |||
| 680 | 681 | |||||
| 681 | $mediaDirectory = $this->getMediaHelper()->getMediaDirectory(); | 682 | $mediaDirectory = $this->getMediaHelper()->getMediaDirectory(); | |||
| 682 | $filePath = $this->getJsFilePath($customerGroupId, $store); | 683 | $filePath = $this->getJsFilePath($customerGroupId, $store); | |||
| 683 | if (!$mediaDirectory->isFile($filePath)) { | 684 | if (!$mediaDirectory->isFile($filePath)) { | |||
| 684 | $this->createJsonFileForStore($store, $customerGroupId); | 685 | $this->createJsonFileForStore($store, $customerGroupId); | |||
| 685 | } | 686 | } | |||
| 686 | 687 | |||||
| 687 | return $this->getMediaHelper()->getMediaUrl($filePath); | 688 | return $this->getMediaHelper()->getMediaUrl($filePath); | |||
| 688 | } | 689 | } | |||
| 689 | 690 | |||||
| 690 | /** | 691 | /** | |||
| 691 | * @return string | 692 | * @return string | |||
| 692 | * @throws NoSuchEntityException | 693 | * @throws NoSuchEntityException | |||
| 693 | * @throws LocalizedException | 694 | * @throws LocalizedException | |||
| 694 | */ | 695 | */ | |||
| 695 | public function getAdditionJsFileUrl() | 696 | public function getAdditionJsFileUrl() | |||
| 696 | { | 697 | { | |||
| 697 | $customerGroupId = $this->_customerSession->getCustomerGroupId(); | 698 | $customerGroupId = $this->_customerSession->getCustomerGroupId(); | |||
| 698 | 699 | |||||
| 699 | /** @var Store $store */ | 700 | /** @var Store $store */ | |||
| 700 | $store = $this->storeManager->getStore(); | 701 | $store = $this->storeManager->getStore(); | |||
| 701 | 702 | |||||
| 702 | $mediaDirectory = $this->getMediaHelper()->getMediaDirectory(); | 703 | $mediaDirectory = $this->getMediaHelper()->getMediaDirectory(); | |||
| 703 | $filePath = $this->getAdditionJsFilePath($customerGroupId, $store); | 704 | $filePath = $this->getAdditionJsFilePath($customerGroupId, $store); | |||
| 704 | if (!$mediaDirectory->isFile($filePath)) { | 705 | if (!$mediaDirectory->isFile($filePath)) { | |||
| 705 | $this->createJsonFileForStore($store, $customerGroupId); | 706 | $this->createJsonFileForStore($store, $customerGroupId); | |||
| 706 | } | 707 | } | |||
| 707 | 708 | |||||
| 708 | return $this->getMediaHelper()->getMediaUrl($filePath); | 709 | return $this->getMediaHelper()->getMediaUrl($filePath); | |||
| 709 | } | 710 | } | |||
| 710 | 711 | |||||
| 711 | /** | 712 | /** | |||
| 712 | * @return array | 713 | * @return array | |||
| 713 | * @throws NoSuchEntityException | 714 | * @throws NoSuchEntityException | |||
| 714 | */ | 715 | */ | |||
| 715 | public function getCategoryTree() | 716 | public function getCategoryTree() | |||
| 716 | { | 717 | { | |||
| 717 | $categoriesOptions = [0 => __('All Categories')]; | 718 | $categoriesOptions = [0 => __('All Categories')]; | |||
| 718 | 719 | |||||
| 719 | $maxLevel = max(0, (int) $this->getConfigGeneral('category/max_depth')) ?: 2; | 720 | $maxLevel = max(0, (int) $this->getConfigGeneral('category/max_depth')) ?: 2; | |||
| 720 | $parent = $this->storeManager->getStore()->getRootCategoryId(); | 721 | $parent = $this->storeManager->getStore()->getRootCategoryId(); | |||
| 721 | $categories = $this->categoryFactory->create(); | 722 | $categories = $this->categoryFactory->create(); | |||
| 722 | $categoryCollection = $categories->getCategories($parent, 1, false, true); | 723 | $categoryCollection = $categories->getCategories($parent, 1, false, true); | |||
| 723 | if ($categories->getUseFlatResource()) { | 724 | if ($categories->getUseFlatResource()) { | |||
| 724 | foreach ($categoryCollection as $category) { | 725 | foreach ($categoryCollection as $category) { | |||
| 725 | if ($category->getParentId() == $parent) { | 726 | if ($category->getParentId() == $parent) { | |||
| 726 | $this->getCategoryOptions($category, $categoriesOptions, $maxLevel); | 727 | $this->getCategoryOptions($category, $categoriesOptions, $maxLevel); | |||
| 727 | } | 728 | } | |||
| 728 | } | 729 | } | |||
| 729 | } else { | 730 | } else { | |||
| 730 | foreach ($categoryCollection as $category) { | 731 | foreach ($categoryCollection as $category) { | |||
| 731 | $this->getCategoryOptions($category, $categoriesOptions, $maxLevel); | 732 | $this->getCategoryOptions($category, $categoriesOptions, $maxLevel); | |||
| 732 | } | 733 | } | |||
| 733 | } | 734 | } | |||
| 734 | 735 | |||||
| 735 | return $categoriesOptions; | 736 | return $categoriesOptions; | |||
| 736 | } | 737 | } | |||
| 737 | 738 | |||||
| 738 | /** | 739 | /** | |||
| 739 | * @param $category | 740 | * @param $category | |||
| 740 | * @param $options | 741 | * @param $options | |||
| 741 | * @param $level | 742 | * @param $level | |||
| 742 | * @param string $htmlPrefix | 743 | * @param string $htmlPrefix | |||
| 743 | * | 744 | * | |||
| 744 | * @return $this | 745 | * @return $this | |||
| 745 | */ | 746 | */ | |||
| 746 | protected function getCategoryOptions($category, &$options, $level, $htmlPrefix = '') | 747 | protected function getCategoryOptions($category, &$options, $level, $htmlPrefix = '') | |||
| 747 | { | 748 | { | |||
| 748 | if ($level <= 0) { | 749 | if ($level <= 0) { | |||
| 749 | return $this; | 750 | return $this; | |||
| 750 | } | 751 | } | |||
| 751 | $level--; | 752 | $level--; | |||
| 752 | 753 | |||||
| 753 | $options[$category->getId()] = $htmlPrefix . $category->getName(); | 754 | $options[$category->getId()] = $htmlPrefix . $category->getName(); | |||
| 754 | 755 | |||||
| 755 | $htmlPrefix .= '- '; | 756 | $htmlPrefix .= '- '; | |||
| 756 | if (!empty($this->getChildCategories($category))) { | 757 | if (!empty($this->getChildCategories($category))) { | |||
| 757 | foreach ($this->getChildCategories($category) as $childCategory) { | 758 | foreach ($this->getChildCategories($category) as $childCategory) { | |||
| 758 | $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix); | 759 | $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix); | |||
| 759 | } | 760 | } | |||
| 760 | } | 761 | } | |||
| 761 | 762 | |||||
| 762 | return $this; | 763 | return $this; | |||
| 763 | } | 764 | } | |||
| 764 | 765 | |||||
| 765 | /** | 766 | /** | |||
| 766 | * @param $category | 767 | * @param $category | |||
| 767 | * | 768 | * | |||
| 768 | * @return mixed | 769 | * @return mixed | |||
| 769 | */ | 770 | */ | |||
| 770 | public function getChildCategories($category) | 771 | public function getChildCategories($category) | |||
| 771 | { | 772 | { | |||
| 772 | return $category->getChildrenCategories(); | 773 | return $category->getChildrenCategories(); | |||
| 773 | } | 774 | } | |||
| 774 | 775 | |||||
| 775 | /** | 776 | /** | |||
| 776 | * @return string | 777 | * @return string | |||
| 777 | */ | 778 | */ | |||
| 778 | public function getPriceFormat() | 779 | public function getPriceFormat() | |||
| 779 | { | 780 | { | |||
| 780 | return self::jsonEncode($this->localeFormat->getPriceFormat()); | 781 | return self::jsonEncode($this->localeFormat->getPriceFormat()); | |||
| 781 | } | 782 | } | |||
| 782 | } | 783 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.