public function testPrepareDataSource() { $dataSource = ['data' => ['items' => [[ProductInterface::STATUS => self::STATUS_ID]]]]; $expectedDataSource = ['data' => ['items' => [[ProductInterface::STATUS => self::STATUS_ID, '' => self::STATUS_TEXT]]]]; $this->statusMock->expects($this->once())->method('getOptionText')->with(self::STATUS_ID)->willReturn(self::STATUS_TEXT); $this->assertEquals($expectedDataSource, $this->getModel()->prepareDataSource($dataSource)); }
/** * @return \Magento\Catalog\Model\ResourceModel\Product\Collection */ public function getProductsCollection() { /* @var $product \Magento\Catalog\Model\Product */ $product = $this->productFactory->create(); /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */ $collection = $product->getCollection(); /** @var $resourceStock \Magento\CatalogInventory\Model\ResourceModel\Stock */ $resourceStock = $this->stockFactory->create(); $resourceStock->addLowStockFilter($collection, ['qty', 'notify_stock_qty', 'low_stock_date', 'use_config' => 'use_config_notify_stock_qty']); $collection->addAttributeToSelect('name', true)->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])->setOrder('low_stock_date'); $this->eventManager->dispatch('rss_catalog_notify_stock_collection_select', ['collection' => $collection]); return $collection; }
/** * Prepare Data Source * * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) { $dataSource = parent::prepareDataSource($dataSource); if (empty($dataSource['data']['items'])) { return $dataSource; } $fieldName = $this->getData('name'); $sourceFieldName = ProductInterface::STATUS; foreach ($dataSource['data']['items'] as &$item) { if (!empty($item[$sourceFieldName])) { $item[$fieldName] = $this->status->getOptionText($item[$sourceFieldName]); } } return $dataSource; }
/** * Get category collection array * * @param null|string|bool|int|\Magento\Store\Model\Store $storeId * @return array|bool */ public function getCollection($storeId) { $products = []; /* @var $store \Magento\Store\Model\Store */ $store = $this->_storeManager->getStore($storeId); if (!$store) { return false; } $adapter = $this->_getWriteAdapter(); $this->_select = $adapter->select()->from(['e' => $this->getMainTable()], [$this->getIdFieldName(), 'updated_at'])->joinInner(['w' => $this->getTable('catalog_product_website')], 'e.entity_id = w.product_id', [])->joinLeft(['url_rewrite' => $this->getTable('url_rewrite')], 'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1' . $adapter->quoteInto(' AND url_rewrite.store_id = ?', $store->getId()) . $adapter->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE), ['url' => 'request_path'])->where('w.website_id = ?', $store->getWebsiteId()); $this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in'); $this->_addFilter($store->getId(), 'status', $this->_productStatus->getVisibleStatusIds(), 'in'); // Join product images required attributes $imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId()); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'name'); $this->_select->columns(['name' => $this->getReadConnection()->getIfNullSql('t2_name.value', 't1_name.value')]); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'thumbnail'); $this->_select->columns(['thumbnail' => $this->getReadConnection()->getIfNullSql('t2_thumbnail.value', 't1_thumbnail.value')]); } elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'image'); $this->_select->columns(['image' => $this->getReadConnection()->getIfNullSql('t2_image.value', 't1_image.value')]); } } $query = $adapter->query($this->_select); while ($row = $query->fetch()) { $product = $this->_prepareProduct($row, $store->getId()); $products[$product->getId()] = $product; } return $products; }
/** * Get category collection array * * @param null|string|bool|int|\Magento\Store\Model\Store $storeId * @return array|bool */ public function getCollection($storeId) { $products = array(); /* @var $store \Magento\Store\Model\Store */ $store = $this->_storeManager->getStore($storeId); if (!$store) { return false; } $urConditions = array('e.entity_id = ur.product_id', 'ur.category_id IS NULL', $this->_getWriteAdapter()->quoteInto('ur.store_id = ?', $store->getId()), $this->_getWriteAdapter()->quoteInto('ur.is_system = ?', 1)); $this->_select = $this->_getWriteAdapter()->select()->from(array('e' => $this->getMainTable()), array($this->getIdFieldName(), 'updated_at'))->joinInner(array('w' => $this->getTable('catalog_product_website')), 'e.entity_id = w.product_id', array())->joinLeft(array('ur' => $this->getTable('core_url_rewrite')), join(' AND ', $urConditions), array('url' => 'request_path'))->where('w.website_id = ?', $store->getWebsiteId()); $this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in'); $this->_addFilter($store->getId(), 'status', $this->_productStatus->getVisibleStatusIds(), 'in'); // Join product images required attributes $imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId()); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'name'); $this->_select->columns(array('name' => $this->getReadConnection()->getIfNullSql('t2_name.value', 't1_name.value'))); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'thumbnail'); $this->_select->columns(array('thumbnail' => $this->getReadConnection()->getIfNullSql('t2_thumbnail.value', 't1_thumbnail.value'))); } elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) { $this->_joinAttribute($store->getId(), 'image'); $this->_select->columns(array('image' => $this->getReadConnection()->getIfNullSql('t2_image.value', 't1_image.value'))); } } $query = $this->_getWriteAdapter()->query($this->_select); while ($row = $query->fetch()) { $product = $this->_prepareProduct($row, $store->getId()); $products[$product->getId()] = $product; } return $products; }
/** * {@inheritdoc} */ protected function _prepareColumns() { $this->addColumn('in_products', ['type' => 'checkbox', 'name' => 'in_products', 'values' => $this->getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id', 'header_css_class' => 'col-select', 'column_css_class' => 'col-select']); $this->addColumn('position', ['header' => __('Position'), 'name' => 'position', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => true, 'is_system' => 1, 'header_css_class' => 'col-hidden', 'column_css_class' => 'col-hidden']); $this->addColumn('id', ['header' => __('ID'), 'type' => 'number', 'index' => 'entity_id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'name']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->status->getOptionArray()]); $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->visibility->getOptionArray()]); }
/** * @return $this */ protected function _prepareMassaction() { $this->setMassactionIdField('entity_id'); $this->getMassactionBlock()->setTemplate('Magento_Catalog::product/grid/massaction_extended.phtml'); $this->getMassactionBlock()->setFormFieldName('product'); $this->getMassactionBlock()->addItem('delete', array('label' => __('Delete'), 'url' => $this->getUrl('catalog/*/massDelete'), 'confirm' => __('Are you sure?'))); $statuses = $this->_status->getOptionArray(); array_unshift($statuses, array('label' => '', 'value' => '')); $this->getMassactionBlock()->addItem('status', array('label' => __('Change status'), 'url' => $this->getUrl('catalog/*/massStatus', array('_current' => true)), 'additional' => array('visibility' => array('name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses)))); if ($this->_authorization->isAllowed('Magento_Catalog::update_attributes')) { $this->getMassactionBlock()->addItem('attributes', array('label' => __('Update Attributes'), 'url' => $this->getUrl('catalog/product_action_attribute/edit', array('_current' => true)))); } $this->_eventManager->dispatch('adminhtml_catalog_product_grid_prepare_massaction', array('block' => $this)); return $this; }
/** * Add columns to grid * * @return $this */ protected function _prepareColumns() { if (!$this->getProduct()->getUpsellReadonly()) { $this->addColumn('in_products', array('type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id', 'header_css_class' => 'col-select', 'column_css_class' => 'col-select')); } $this->addColumn('entity_id', array('header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id')); $this->addColumn('name', array('header' => __('Name'), 'index' => 'name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name')); $this->addColumn('type', array('header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->_type->getOptionArray(), 'header_css_class' => 'col-type', 'column_css_class' => 'col-type')); $sets = $this->_setsFactory->create()->setEntityTypeFilter($this->_productFactory->create()->getResource()->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', array('header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name')); $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->_status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status')); $this->addColumn('visibility', array('header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->_visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility')); $this->addColumn('sku', array('header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku')); $this->addColumn('price', array('header' => __('Price'), 'type' => 'currency', 'currency_code' => (string) $this->_scopeConfig->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price')); $this->addColumn('position', array('header' => __('Position'), 'name' => 'position', 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => !$this->getProduct()->getUpsellReadonly(), 'edit_only' => !$this->getProduct()->getId(), 'header_css_class' => 'col-position', 'column_css_class' => 'col-position', 'filter_condition_callback' => array($this, 'filterProductPosition'))); return parent::_prepareColumns(); }
/** * @return $this */ protected function _prepareColumns() { $this->addColumn('in_products', ['header_css_class' => 'a-center', 'type' => 'checkbox', 'name' => 'in_products', 'values' => $this->_getSelectedProducts(), 'align' => 'center', 'index' => 'entity_id']); $this->addColumn('entity_id', ['header' => __('ID'), 'sortable' => true, 'index' => 'entity_id', 'type' => 'number', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']); $this->addColumn('name', ['header' => __('Name'), 'index' => 'product_name', 'header_css_class' => 'col-name', 'column_css_class' => 'col-name']); $this->addColumn('type', ['header' => __('Type'), 'index' => 'type_id', 'type' => 'options', 'options' => $this->type->getOptionArray(), 'header_css_class' => 'col-type', 'column_css_class' => 'col-type']); /** @var \Magento\Catalog\Model\Resource\Product $resource */ $resource = $this->productFactory->create()->getResource(); $sets = $this->setCollectionFactory->create()->setEntityTypeFilter($resource->getTypeId())->load()->toOptionHash(); $this->addColumn('set_name', ['header' => __('Attribute Set'), 'index' => 'attribute_set_id', 'type' => 'options', 'options' => $sets, 'header_css_class' => 'col-attr-name', 'column_css_class' => 'col-attr-name']); $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'options' => $this->status->getOptionArray(), 'header_css_class' => 'col-status', 'column_css_class' => 'col-status']); $this->addColumn('visibility', ['header' => __('Visibility'), 'index' => 'visibility', 'type' => 'options', 'options' => $this->visibility->getOptionArray(), 'header_css_class' => 'col-visibility', 'column_css_class' => 'col-visibility']); $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku', 'header_css_class' => 'col-sku', 'column_css_class' => 'col-sku']); $this->addColumn('price', ['header' => __('Price'), 'type' => 'currency', 'currency_code' => (string) $this->_scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, ScopeInterface::SCOPE_STORE), 'index' => 'price', 'header_css_class' => 'col-price', 'column_css_class' => 'col-price']); $this->addColumn('position', ['header' => __('Position'), 'name' => 'position', 'width' => 60, 'type' => 'number', 'validate_class' => 'validate-number', 'index' => 'position', 'editable' => true]); return $this; }
/** * Regenerate search index for specific store * * @param int $storeId Store View Id * @param int|array $productIds Product Entity Id * @return \Generator * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function rebuildStoreIndex($storeId, $productIds = null) { if ($productIds !== null) { $productIds = array_unique(array_merge($productIds, $this->getProductIdsFromParents($productIds))); } // prepare searchable attributes $staticFields = []; foreach ($this->getSearchableAttributes('static') as $attribute) { $staticFields[] = $attribute->getAttributeCode(); } $dynamicFields = ['int' => array_keys($this->getSearchableAttributes('int')), 'varchar' => array_keys($this->getSearchableAttributes('varchar')), 'text' => array_keys($this->getSearchableAttributes('text')), 'decimal' => array_keys($this->getSearchableAttributes('decimal')), 'datetime' => array_keys($this->getSearchableAttributes('datetime'))]; // status and visibility filter $visibility = $this->getSearchableAttribute('visibility'); $status = $this->getSearchableAttribute('status'); $statusIds = $this->catalogProductStatus->getVisibleStatusIds(); $allowedVisibility = $this->engine->getAllowedVisibility(); return $this->iteratorFactory->create(['storeId' => $storeId, 'productIds' => $productIds, 'staticFields' => $staticFields, 'dynamicFields' => $dynamicFields, 'visibility' => $visibility, 'allowedVisibility' => $allowedVisibility, 'status' => $status, 'statusIds' => $statusIds]); }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $modelId = $product->getId(); if ($modelId) { $storeId = $this->locator->getStore()->getId(); /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); $data[$product->getId()]['links'][self::LINK_TYPE] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== self::LINK_TYPE) { continue; } /** @var \Magento\Catalog\Api\Data\ProductInterface $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $storeId); $data[$modelId]['links'][self::LINK_TYPE][] = ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; } $data[$modelId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $storeId; } return $data; }
/** * {@inheritdoc} */ public function modifyData(array $data) { /** @var \Magento\Catalog\Model\Product $product */ $product = $this->locator->getProduct(); $productId = $product->getId(); if (!$productId) { return $data; } foreach ($this->getDataScopes() as $dataScope) { $data[$productId]['links'][$dataScope] = []; foreach ($this->productLinkRepository->getList($product) as $linkItem) { if ($linkItem->getLinkType() !== $dataScope) { continue; } /** @var \Magento\Catalog\Model\Product $linkedProduct */ $linkedProduct = $this->productRepository->get($linkItem->getLinkedProductSku(), false, $this->locator->getStore()->getId()); $data[$productId]['links'][$dataScope][] = ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; } } $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId; $data[$productId][self::DATA_SOURCE_DEFAULT]['current_store_id'] = $this->locator->getStore()->getId(); return $data; }
/** * Render RSS * * @return string */ protected function _toHtml() { $newUrl = $this->getUrl('rss/catalog/notifystock', array('_secure' => true, '_nosecret' => true)); $title = __('Low Stock Products'); /** @var $rssObj \Magento\Rss\Model\Rss */ $rssObj = $this->_rssFactory->create(); $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8')); $globalNotifyStockQty = (double) $this->_scopeConfig->getValue(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_NOTIFY_STOCK_QTY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); /* @var $product \Magento\Catalog\Model\Product */ $product = $this->_productFactory->create(); /* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */ $collection = $product->getCollection(); /** @var $resourceStock \Magento\CatalogInventory\Model\Resource\Stock */ $resourceStock = $this->_stockFactory->create(); $resourceStock->addLowStockFilter($collection, array('qty', 'notify_stock_qty', 'low_stock_date', 'use_config' => 'use_config_notify_stock_qty')); $collection->addAttributeToSelect('name', true)->addAttributeToFilter('status', array('in' => $this->_productStatus->getVisibleStatusIds()))->setOrder('low_stock_date'); $this->_eventManager->dispatch('rss_catalog_notify_stock_collection_select', array('collection' => $collection)); /* using resource iterator to load the data one by one instead of loading all at the same time. loading all data at the same time can cause the big memory allocation. */ $this->_resourceIterator->walk($collection->getSelect(), array(array($this, 'addNotifyItemXmlCallback')), array('rssObj' => $rssObj, 'product' => $product, 'globalQty' => $globalNotifyStockQty)); return $rssObj->createRssXml(); }
/** * Fill data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { /** @var \Magento\Framework\Currency $currency */ $currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode()); return ['id' => $linkedProduct->getId(), 'name' => $linkedProduct->getName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $currency->toCurrency(sprintf("%f", $linkedProduct->getPrice())), 'qty' => $linkItem->getExtensionAttributes()->getQty(), 'position' => $linkItem->getPosition(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'type_id' => $linkedProduct->getTypeId(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName()]; }
/** * Set only saleable filter * * @param \Magento\Catalog\Model\Product $product * @return $this */ public function setSaleableStatus($product) { $product->setData($this->_keyStatusFilters, $this->_catalogProductStatus->getSaleableStatusIds()); return $this; }
/** * @dataProvider getOptionTextDataProvider * @param string $text * @param string $id */ public function testGetOptionText($text, $id) { $this->assertEquals($text, $this->status->getOptionText($id)); }
/** * Retrieve visible statuses * * @return array */ public function getVisibleStatuses() { return $this->_catalogProductStatus->getVisibleStatusIds(); }
/** * @return \Magento\Framework\Api\Filter */ private function addFilterStatus() { if ($this->getStatus() === 1) { $this->searchCriteriaBuilder->addFilter(ProductInterface::STATUS, $this->productStatus->getVisibleStatusIds(), 'in'); } }
/** * Regenerate search index for specific store * * @param int $storeId Store View Id * @param int|array $productIds Product Entity Id * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function rebuildStoreIndex($storeId, $productIds = null) { $this->cleanIndex($storeId, $productIds); // prepare searchable attributes $staticFields = []; foreach ($this->getSearchableAttributes('static') as $attribute) { $staticFields[] = $attribute->getAttributeCode(); } $dynamicFields = ['int' => array_keys($this->getSearchableAttributes('int')), 'varchar' => array_keys($this->getSearchableAttributes('varchar')), 'text' => array_keys($this->getSearchableAttributes('text')), 'decimal' => array_keys($this->getSearchableAttributes('decimal')), 'datetime' => array_keys($this->getSearchableAttributes('datetime'))]; // status and visibility filter $visibility = $this->getSearchableAttribute('visibility'); $status = $this->getSearchableAttribute('status'); $statusIds = $this->catalogProductStatus->getVisibleStatusIds(); $allowedVisibility = $this->engineProvider->get()->getAllowedVisibility(); $lastProductId = 0; while (true) { $products = $this->getSearchableProducts($storeId, $staticFields, $productIds, $lastProductId); if (!$products) { break; } $productAttributes = []; $productRelations = []; foreach ($products as $productData) { $lastProductId = $productData['entity_id']; $productAttributes[$productData['entity_id']] = $productData['entity_id']; $productChildren = $this->getProductChildIds($productData['entity_id'], $productData['type_id']); $productRelations[$productData['entity_id']] = $productChildren; if ($productChildren) { foreach ($productChildren as $productChildId) { $productAttributes[$productChildId] = $productChildId; } } } $productIndexes = []; $productAttributes = $this->getProductAttributes($storeId, $productAttributes, $dynamicFields); foreach ($products as $productData) { if (!isset($productAttributes[$productData['entity_id']])) { continue; } $productAttr = $productAttributes[$productData['entity_id']]; if (!isset($productAttr[$visibility->getId()]) || !in_array($productAttr[$visibility->getId()], $allowedVisibility)) { continue; } if (!isset($productAttr[$status->getId()]) || !in_array($productAttr[$status->getId()], $statusIds)) { continue; } $productIndex = [$productData['entity_id'] => $productAttr]; $hasChildren = false; $productChildren = $productRelations[$productData['entity_id']]; if ($productChildren) { foreach ($productChildren as $productChildId) { if (isset($productAttributes[$productChildId])) { $productChildAttr = $productAttributes[$productChildId]; if (!isset($productChildAttr[$status->getId()]) || !in_array($productChildAttr[$status->getId()], $statusIds)) { continue; } $hasChildren = true; $productIndex[$productChildId] = $productChildAttr; } } } if ($productChildren !== null && !$hasChildren) { continue; } $index = $this->prepareProductIndex($productIndex, $productData, $storeId); $productIndexes[$productData['entity_id']] = $index; } $this->saveProductIndexes($storeId, $productIndexes); } $this->fulltextResource->resetSearchResults(); }
/** * Prepare data column * * @param ProductInterface $linkedProduct * @param ProductLinkInterface $linkItem * @return array */ protected function fillData(ProductInterface $linkedProduct, ProductLinkInterface $linkItem) { return ['id' => $linkedProduct->getId(), 'thumbnail' => $this->imageHelper->init($linkedProduct, 'product_listing_thumbnail')->getUrl(), 'name' => $linkedProduct->getName(), 'status' => $this->status->getOptionText($linkedProduct->getStatus()), 'attribute_set' => $this->attributeSetRepository->get($linkedProduct->getAttributeSetId())->getAttributeSetName(), 'sku' => $linkItem->getLinkedProductSku(), 'price' => $linkedProduct->getPrice(), 'position' => $linkItem->getPosition()]; }