diff --git a/Model/ConfigProvider.php b/Model/ConfigProvider.php index b31bf66..33abc5a 100644 --- a/Model/ConfigProvider.php +++ b/Model/ConfigProvider.php @@ -838,6 +838,14 @@ public function canSendProductFeedInAnyScope() return $this->areAllConfigsEnabledInAnyScopeId(['general/enable_bv', 'feeds/enable_product_feed'], $configScope); } + /** + * @return string + */ + public function getImageAttributeCode($storeId = null, $scope = ScopeInterface::SCOPE_STORE) + { + return (string) $this->getConfig('indexer/image_attribute_code', $storeId, $scope); + } + /** * @param string $feedGenerationScope * diff --git a/Model/Dcc/CatalogData/CatalogProductBuilder.php b/Model/Dcc/CatalogData/CatalogProductBuilder.php index 1255445..9191ff7 100644 --- a/Model/Dcc/CatalogData/CatalogProductBuilder.php +++ b/Model/Dcc/CatalogData/CatalogProductBuilder.php @@ -266,9 +266,9 @@ private function getCustomAttributeData($product, $attributeCode) */ private function getProductImageUrl($product, $parentProduct = null) { - if ($product && $product->getData('small_image')) { + if ($product && $product->getData($this->configProvider->getImageAttributeCode())) { $imageUrl = $this->mediaConfigFactory->create()->getMediaUrl($product->getSmallImage()); - } else if ($parentProduct && $parentProduct->getData('small_image')) { + } else if ($parentProduct && $parentProduct->getData($this->configProvider->getImageAttributeCode())) { $imageUrl = $this->mediaConfigFactory->create()->getMediaUrl($parentProduct->getSmallImage()); } else { $imageUrl = $this->mediaConfigFactory->create()->getMediaUrl($product->getSmallImage()); @@ -347,7 +347,7 @@ private function getBrandAttribute($product) private function prepareOutput($object) { /** - * @var \Magento\Framework\Model\AbstractModel $object + * @var \Magento\Framework\Model\AbstractModel $object */ return $this->stringFormatter->stripEmptyValues($object->getData()); } diff --git a/Model/Indexer/Eav.php b/Model/Indexer/Eav.php index 3b2144c..23938fe 100644 --- a/Model/Indexer/Eav.php +++ b/Model/Indexer/Eav.php @@ -5,7 +5,7 @@ */ /** - * @noinspection DuplicatedCode + * @noinspection DuplicatedCode */ declare(strict_types=1); @@ -162,7 +162,7 @@ public function canIndex(): bool public function executeFull() { /** - * @var Collection $incompleteIndex + * @var Collection $incompleteIndex */ if (!$this->canIndex()) { @@ -198,7 +198,7 @@ public function executeFull() public function execute($ids = []) { /** - * @var $idCollection \Bazaarvoice\Connector\Model\ResourceModel\Index\Collection + * @var $idCollection \Bazaarvoice\Connector\Model\ResourceModel\Index\Collection */ if (!$this->canIndex()) { @@ -217,12 +217,12 @@ public function execute($ids = []) $this->logger->debug('Found '.count($ids).' products to update.'); /** - * Break ids into pages + * Break ids into pages */ $productIdSets = array_chunk($ids, 50); /** - * Time throttling + * Time throttling */ $limit = ($this->configProvider->getCronjobDurationLimit() * 60) - 10; $stop = time() + $limit; @@ -279,7 +279,7 @@ protected function reindexProducts(array $productIds) case Scope::WEBSITE: $websites = $this->storeManager->getWebsites(); /** - * @var \Magento\Store\Model\Website $website + * @var \Magento\Store\Model\Website $website */ foreach ($websites as $website) { $defaultStore = $website->getDefaultStore(); @@ -295,7 +295,7 @@ protected function reindexProducts(array $productIds) case Scope::STORE_GROUP: $groups = $this->storeManager->getGroups(); /** - * @var \Magento\Store\Model\Group $group + * @var \Magento\Store\Model\Group $group */ foreach ($groups as $group) { $defaultStore = $group->getDefaultStore(); @@ -311,7 +311,7 @@ protected function reindexProducts(array $productIds) case Scope::STORE_VIEW: $stores = $this->storeManager->getStores(); /** - * @var \Magento\Store\Model\Store $store + * @var \Magento\Store\Model\Store $store */ foreach ($stores as $store) { if ($store->getId()) { @@ -337,14 +337,14 @@ protected function flushIndex() { $this->canIndex(); /** - * Set indexer to use mview + * Set indexer to use mview */ $this->indexer->setScheduled(true); $writeAdapter = $this->resourceConnection->getConnection('core_write'); /** - * Flush all old data + * Flush all old data */ $indexTable = $this->resourceConnection->getTableName('bazaarvoice_index_product'); $writeAdapter->truncateTable($indexTable); @@ -352,14 +352,14 @@ protected function flushIndex() $writeAdapter->truncateTable($changelogTable); /** - * Setup dummy rows + * Setup dummy rows */ $productTable = $this->resourceConnection->getTableName('catalog_product_entity'); $writeAdapter->query("INSERT INTO `$indexTable` (`product_id`, `version_id`) SELECT DISTINCT `entity_id`, '0' FROM `$productTable`;"); $writeAdapter->query("INSERT INTO `$changelogTable` (`entity_id`) SELECT DISTINCT `entity_id` FROM `$productTable`;"); /** - * Reset mview version + * Reset mview version */ $mviewTable = $this->resourceConnection->getTableName('mview_state'); $writeAdapter->query("UPDATE `$mviewTable` SET `version_id` = NULL, `status` = 'idle' WHERE `view_id` = 'bazaarvoice_product';"); @@ -490,7 +490,7 @@ private function populateIndexStoreData($productIds, Store $store) } /** - * Version + * Version */ $select->joinLeft( ['cl' => $res->getTableName('bazaarvoice_product_cl')], @@ -538,7 +538,7 @@ private function populateIndexStoreData($productIds, Store $store) } /** - * Use parent URLs/categories if appropriate + * Use parent URLs/categories if appropriate */ if ($indexData['visibility'] == Visibility::VISIBILITY_NOT_VISIBLE) { $this->logger->debug('Not visible'); @@ -571,7 +571,7 @@ private function populateIndexStoreData($productIds, Store $store) $standardUrl = $this->getStandardUrl($indexData['product_id']); /** - * Add Store base to URLs + * Add Store base to URLs */ if ($storeId == Store::DEFAULT_STORE_ID) { $urlStore = $this->storeManager->getStore($indexData['url_store_id']); @@ -603,7 +603,7 @@ private function populateIndexStoreData($productIds, Store $store) } /** - * @var \Bazaarvoice\Connector\Model\Index $index + * @var \Bazaarvoice\Connector\Model\Index $index */ $index = $this->bvIndexFactory->create(); $index->setData($indexData); @@ -627,11 +627,11 @@ private function populateIndexLocaleData($productIds, Store $store): void $read = $res->getConnection('core_read'); /** - * @var Store $localeStore + * @var Store $localeStore */ foreach ($locales[$storeId] as $locale => $localeStore) { /** - * Core Data + * Core Data */ $select = $this->getBaseSelect($read, $localeStore, $res); @@ -648,7 +648,7 @@ private function populateIndexLocaleData($productIds, Store $store): void $rows = $select->query(); while (($indexData = $rows->fetch()) !== false) { /** - * @var Index $productIndex + * @var Index $productIndex */ foreach ($this->productIndexes as $productIndex) { @@ -660,7 +660,7 @@ private function populateIndexLocaleData($productIds, Store $store): void } /** - * Use parent URLs/categories if appropriate + * Use parent URLs/categories if appropriate */ if ($indexData['visibility'] == Visibility::VISIBILITY_NOT_VISIBLE) { $this->logger->debug('Locale not visible'); @@ -674,7 +674,7 @@ private function populateIndexLocaleData($productIds, Store $store): void } /** - * @var Store $localeStore + * @var Store $localeStore */ if ($storeId == Store::DEFAULT_STORE_ID && $localeStore->getId() == Store::DEFAULT_STORE_ID) { $urlStore = $this->storeManager->getStore($indexData['url_store_id']); @@ -735,19 +735,20 @@ private function populateIndexLocaleData($productIds, Store $store): void */ private function getBaseSelect($read, $store, ResourceConnection $res) { + $imageAttributeCode = $this->configProvider->getImageAttributeCode(); $storeId = $store->getId(); $select = $read->select()->from(['p' => $res->getTableName('catalog_product_entity')], []); $select->columns(['product_type' => 'p.type_id', 'product_id' => 'p.entity_id', 'external_id' => 'p.sku']); $this->addFieldToJoin($select, 'name', $storeId); $this->addFieldToJoin($select, 'short_description', $storeId); - $this->addFieldToJoin($select, 'small_image', $storeId); + $this->addFieldToJoin($select, $imageAttributeCode, $storeId); $this->addFieldToJoin($select, 'visibility', $storeId); $this->addFieldToJoin($select, ProductFeed::INCLUDE_IN_FEED_FLAG, $storeId); $this->addFieldToJoin($select, 'status', $storeId); $this->addFieldToSelect($select, 'name', 'name'); $this->addFieldToSelect($select, 'description', 'short_description'); - $this->addFieldToSelect($select, 'image_url', 'small_image'); + $this->addFieldToSelect($select, 'image_url', $imageAttributeCode); $this->addFieldToSelect($select, 'visibility', 'visibility'); $this->addFieldToSelect($select, ProductFeed::INCLUDE_IN_FEED_FLAG, ProductFeed::INCLUDE_IN_FEED_FLAG); @@ -777,6 +778,8 @@ private function joinParent(Select $select, $storeId, ResourceConnection $res): '' ); + $imageAttributeCode = $this->configProvider->getImageAttributeCode(); + $families = $parentFamilies = ''; if ($this->configProvider->isFamiliesEnabled($storeId)) { $familyAttributes = $this->configProvider->getFamilyAttributesArray($storeId); @@ -803,8 +806,8 @@ private function joinParent(Select $select, $storeId, ResourceConnection $res): $select->columns(['family' => "GROUP_CONCAT(DISTINCT CONCAT_WS(',', {$families}p.sku))"]); $select->columns(['parent_bvfamily' => "GROUP_CONCAT(DISTINCT CONCAT_WS(',', {$parentFamilies}parent.sku))"]); - $this->addFieldToJoin($select, 'small_image', $storeId, 'parent'); - $this->addFieldToSelect($select, 'parent_image', 'small_image', 'parent'); + $this->addFieldToJoin($select, $imageAttributeCode, $storeId, 'parent'); + $this->addFieldToSelect($select, 'parent_image', $imageAttributeCode, 'parent'); } /** @@ -817,7 +820,7 @@ private function joinParent(Select $select, $storeId, ResourceConnection $res): private function joinUrlRewrite(Select $select, $storeId, ResourceConnection $res): void { /** - * urls + * urls */ if ($storeId == Store::DEFAULT_STORE_ID) { $select @@ -875,7 +878,7 @@ private function filterByProducts(Select $select, array $productIds) private function getStandardUrl($productId): string { /** - * Handle missing rewrites + * Handle missing rewrites */ return 'catalog/product/view/id/'.$productId; } @@ -903,7 +906,7 @@ private function getStoreUrl(string $storeUrl, string $urlPath, $storeCode = nul private function _purgeUnversioned(array $productIds) { /** - * Database Resources + * Database Resources */ $write = $this->resourceConnection->getConnection('core_write'); @@ -976,7 +979,7 @@ public function executeRow($id): bool private function getImageUrl($store, $indexData) { /** - * Use parent image if appropriate + * Use parent image if appropriate */ if ($indexData['image_url'] == '' || $indexData['image_url'] == 'no_selection') { if (!empty($indexData['parent_image'])) { @@ -1009,10 +1012,10 @@ private function getImageUrl($store, $indexData) public function getPlaceholderUrl($store) { /** - * @var Store $localeStore + * @var Store $localeStore */ /** - * @var string $locale + * @var string $locale */ @@ -1075,7 +1078,7 @@ protected function getProductIdFieldName(): string private function saveProductIndexes() { /** - * @var \Bazaarvoice\Connector\Model\Index $bvIndex + * @var \Bazaarvoice\Connector\Model\Index $bvIndex */ foreach ($this->productIndexes as $bvIndex) { try { diff --git a/Model/Indexer/Flat.php b/Model/Indexer/Flat.php index 5bc75fb..e165de3 100644 --- a/Model/Indexer/Flat.php +++ b/Model/Indexer/Flat.php @@ -176,7 +176,7 @@ public function canIndex() public function executeFull() { /** - * @var Collection $incompleteIndex + * @var Collection $incompleteIndex */ if (!$this->canIndex()) { @@ -213,7 +213,7 @@ public function executeFull() public function execute($ids = []) { /** - * @var $idCollection \Bazaarvoice\Connector\Model\ResourceModel\Index\Collection + * @var $idCollection \Bazaarvoice\Connector\Model\ResourceModel\Index\Collection */ if (!$this->canIndex()) { @@ -232,12 +232,12 @@ public function execute($ids = []) $this->logger->debug('Found '.count($ids).' products to update.'); /** - * Break ids into pages + * Break ids into pages */ $productIdSets = array_chunk($ids, 50); /** - * Time throttling + * Time throttling */ $limit = ($this->configProvider->getCronjobDurationLimit() * 60) - 10; $stop = time() + $limit; @@ -290,7 +290,7 @@ protected function reindexProducts($productIds) $stores = $this->storeManager->getStores(); ksort($stores); /** - * @var \Magento\Store\Model\Store $store + * @var \Magento\Store\Model\Store $store */ foreach ($stores as $store) { if ($this->configProvider->canSendProductFeed($store->getId())) { @@ -302,7 +302,7 @@ protected function reindexProducts($productIds) case Scope::WEBSITE: $websites = $this->storeManager->getWebsites(); /** - * @var \Magento\Store\Model\Website $website + * @var \Magento\Store\Model\Website $website */ foreach ($websites as $website) { $defaultStore = $website->getDefaultStore(); @@ -318,7 +318,7 @@ protected function reindexProducts($productIds) case Scope::STORE_GROUP: $groups = $this->storeManager->getGroups(); /** - * @var \Magento\Store\Model\Group $group + * @var \Magento\Store\Model\Group $group */ foreach ($groups as $group) { $defaultStore = $group->getDefaultStore(); @@ -334,7 +334,7 @@ protected function reindexProducts($productIds) case Scope::STORE_VIEW: $stores = $this->storeManager->getStores(); /** - * @var \Magento\Store\Model\Store $store + * @var \Magento\Store\Model\Store $store */ foreach ($stores as $store) { if ($store->getId()) { @@ -360,14 +360,14 @@ protected function flushIndex() { $this->canIndex(); /** - * Set indexer to use mview + * Set indexer to use mview */ $this->indexer->setScheduled(true); $writeAdapter = $this->resourceConnection->getConnection('core_write'); /** - * Flush all old data + * Flush all old data */ $indexTable = $this->resourceConnection->getTableName('bazaarvoice_index_product'); $writeAdapter->truncateTable($indexTable); @@ -375,14 +375,14 @@ protected function flushIndex() $writeAdapter->truncateTable($changelogTable); /** - * Setup dummy rows + * Setup dummy rows */ $productTable = $this->resourceConnection->getTableName('catalog_product_entity'); $writeAdapter->query("INSERT INTO `$indexTable` (`product_id`, `version_id`) SELECT DISTINCT `entity_id`, '0' FROM `$productTable`;"); $writeAdapter->query("INSERT INTO `$changelogTable` (`entity_id`) SELECT DISTINCT `entity_id` FROM `$productTable`;"); /** - * Reset mview version + * Reset mview version */ $mviewTable = $this->resourceConnection->getTableName('mview_state'); $writeAdapter->query("UPDATE `$mviewTable` SET `version_id` = NULL, `status` = 'idle' WHERE `view_id` = 'bazaarvoice_product';"); @@ -428,7 +428,7 @@ private function populateIndexStoreData($productIds, $store) $storeId = $store->getId(); /** - * Database Resources + * Database Resources */ $res = $this->resourceConnection; $read = $res->getConnection('core_read'); @@ -469,7 +469,7 @@ private function populateIndexStoreData($productIds, $store) $this->joinUrlRewrite($select, $storeId, $res); /** - * category + * category */ if ($this->configProvider->isCategoryIdUseUrlPathEnabled($storeId)) { $select->joinLeft( @@ -516,7 +516,7 @@ private function populateIndexStoreData($productIds, $store) } /** - * Brands and other Attributes + * Brands and other Attributes */ $columnResults = $read->query('DESCRIBE `'.$res->getTableName('catalog_product_flat').'_'.$storeId.'`;'); $flatColumns = []; @@ -559,7 +559,7 @@ private function populateIndexStoreData($productIds, $store) } /** - * Version + * Version */ $select->joinLeft( ['cl' => $res->getTableName('bazaarvoice_product_cl')], @@ -610,7 +610,7 @@ private function populateIndexStoreData($productIds, $store) } /** - * categories + * categories */ if ($indexData['bv_category_external_id']) { $indexData['category_external_id'] = $indexData['bv_category_external_id']; @@ -620,7 +620,7 @@ private function populateIndexStoreData($productIds, $store) } /** - * Use parent URLs/categories if appropriate + * Use parent URLs/categories if appropriate */ if ($indexData['visibility'] == Visibility::VISIBILITY_NOT_VISIBLE) { $this->logger->debug('Not visible'); @@ -650,7 +650,7 @@ private function populateIndexStoreData($productIds, $store) $standardUrl = $this->getStandardUrl($indexData['product_id']); /** - * Add Store base to URLs + * Add Store base to URLs */ $indexData['product_page_url'] = $this->getStoreUrl( $store->getBaseUrl(), @@ -673,7 +673,7 @@ private function populateIndexStoreData($productIds, $store) } /** - * @var \Bazaarvoice\Connector\Model\Index $index + * @var \Bazaarvoice\Connector\Model\Index $index */ $index = $this->bvIndexFactory->create(); $index->setData($indexData); @@ -694,24 +694,24 @@ private function populateIndexLocaleData($productIds, $store) $locales = $this->configProvider->getLocales(); if (isset($locales[$storeId])) { /** - * Locale Data + * Locale Data */ $localeColumns = [ 'entity_id' => 'entity_id', 'name' => 'name', 'description' => 'short_description', - 'image_url' => 'small_image', + 'image_url' => $this->configProvider->getImageAttributeCode(), ]; $res = $this->resourceConnection; $read = $res->getConnection('core_read'); /** - * @var Store $localeStore + * @var Store $localeStore */ foreach ($locales[$storeId] as $locale => $localeStore) { /** - * Core Data + * Core Data */ $select = $this->getBaseSelect($read, $localeStore->getId(), $res); @@ -725,14 +725,14 @@ private function populateIndexLocaleData($productIds, $store) } $columns["product_page_url"] = 'url.request_path'; $columns["parent_url"] = 'max(parent_url.request_path)'; - $columns["parent_image"] = 'parent.small_image'; + $columns["parent_image"] = 'parent.' . $this->configProvider->getImageAttributeCode(); $select->columns($columns); try { $rows = $select->query(); while (($indexData = $rows->fetch()) !== false) { /** - * @var Index $productIndex + * @var Index $productIndex */ foreach ($this->productIndexes as $productIndex) { @@ -744,7 +744,7 @@ private function populateIndexLocaleData($productIds, $store) } /** - * @var Store $localeStore + * @var Store $localeStore */ $urlPath = isset($indexData['product_page_url']) ? $indexData['product_page_url'] @@ -764,7 +764,7 @@ private function populateIndexLocaleData($productIds, $store) $indexData['image_url'] = $this->getImageUrl($localeStore, $indexData); /** - * Use parent URLs/categories if appropriate + * Use parent URLs/categories if appropriate */ if ($indexData['visibility'] == Visibility::VISIBILITY_NOT_VISIBLE) { $this->logger->debug('Locale not visible'); @@ -821,7 +821,7 @@ private function getBaseSelect($read, $storeId, ResourceConnection $res) 'product_id' => 'p.entity_id', 'description' => 'p.short_description', 'external_id' => 'p.sku', - 'image_url' => 'p.small_image', + 'image_url' => 'p.' . $this->configProvider->getImageAttributeCode(), 'visibility' => 'p.visibility', ProductFeed::INCLUDE_IN_FEED_FLAG => ProductFeed::INCLUDE_IN_FEED_FLAG, 'bv_category_id' => 'p.bv_category_id', @@ -860,7 +860,7 @@ private function joinParent(Select $select, $storeId, ResourceConnection $res) 'pp.parent_id = parent.'.$this->productIdField, [ 'parent_bvfamily' => "GROUP_CONCAT(DISTINCT CONCAT_WS(',', {$familyFields}parent.sku))", - 'parent_image' => 'small_image', + 'parent_image' => $this->configProvider->getImageAttributeCode(), ] ); } @@ -876,7 +876,7 @@ private function joinParent(Select $select, $storeId, ResourceConnection $res) private function joinUrlRewrite(Select $select, $storeId, ResourceConnection $res) { /** - * urls + * urls */ return $select ->joinLeft( @@ -914,7 +914,7 @@ private function filterByProducts($select, $productIds) private function getStandardUrl($productId) { /** - * Handle missing rewrites + * Handle missing rewrites */ $standardUrl = 'catalog/product/view/id/'.$productId; @@ -944,7 +944,7 @@ private function getStoreUrl($storeUrl, $urlPath, $storeCode = null) private function _purgeUnversioned($productIds) { /** - * Database Resources + * Database Resources */ $write = $this->resourceConnection->getConnection('core_write'); @@ -963,7 +963,7 @@ private function _purgeUnversioned($productIds) private function logStats() { /** - * @var Select $select + * @var Select $select */ $select = $this->resourceConnection->getConnection('core_read') ->select() @@ -1019,7 +1019,7 @@ public function executeRow($id) private function getImageUrl($store, $indexData) { /** - * Use parent image if appropriate + * Use parent image if appropriate */ if ($indexData['image_url'] == '' || $indexData['image_url'] == 'no_selection') { if (!empty($indexData['parent_image'])) { @@ -1049,22 +1049,22 @@ private function getImageUrl($store, $indexData) public function getPlaceholderUrl($store) { /** - * @var Image $imageHelper + * @var Image $imageHelper */ /** - * @var \Magento\Framework\View\Asset\Repository $assetRepo + * @var \Magento\Framework\View\Asset\Repository $assetRepo */ /** - * @var \Magento\Framework\View\DesignInterface $design + * @var \Magento\Framework\View\DesignInterface $design */ /** - * @var Store $localeStore + * @var Store $localeStore */ /** - * @var string $locale + * @var string $locale */ /** - * @var \Magento\Theme\Model\Theme $theme + * @var \Magento\Theme\Model\Theme $theme */ $imageHelper = $this->objectManager->get('\Magento\Catalog\Helper\Image'); @@ -1090,7 +1090,7 @@ public function getPlaceholderUrl($store) protected function hasBadScopeIndex() { /** - * @var Select $select + * @var Select $select */ $select = $this->resourceConnection->getConnection('core_read') ->select() @@ -1126,7 +1126,7 @@ protected function getProductIdFieldName() private function saveProductIndexes() { /** - * @var \Bazaarvoice\Connector\Model\Index $bvIndex + * @var \Bazaarvoice\Connector\Model\Index $bvIndex */ foreach ($this->productIndexes as $bvIndex) { try { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index ede749b..7b6bc6d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -278,6 +278,13 @@ + + + + + Attribute of image to send to bazaarvoice (Default: "small_image") + + diff --git a/etc/config.xml b/etc/config.xml index 498d41f..cdb2f52 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -31,6 +31,9 @@ 1 0 + + small_image + diff --git a/etc/module.xml b/etc/module.xml index 0526e1b..932e65e 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -5,7 +5,7 @@ --> - +