/** * 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; }
/** * Prepare mock of Sitemap model * * @param array $actualData * @param int $maxLines * @param int $maxFileSize * @param array $expectedFile * @param int $expectedWrites * @param array $robotsInfo * @return \Magento\Sitemap\Model\Sitemap|PHPUnit_Framework_MockObject_MockObject * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareSitemapModelMock(&$actualData, $maxLines, $maxFileSize, $expectedFile, $expectedWrites, $robotsInfo) { // Check that all $expectedWrites lines were written $actualData = []; $currentFile = ''; $streamWriteCallback = function ($str) use(&$actualData, &$currentFile) { if (!array_key_exists($currentFile, $actualData)) { $actualData[$currentFile] = ''; } $actualData[$currentFile] .= $str; }; // Check that all expected lines were written $this->_fileMock->expects($this->exactly($expectedWrites))->method('write')->will($this->returnCallback($streamWriteCallback)); // Check that all expected file descriptors were created $this->_directoryMock->expects($this->exactly(count($expectedFile)))->method('openFile')->will($this->returnCallback(function ($file) use(&$currentFile) { $currentFile = $file; })); // Check that all file descriptors were closed $this->_fileMock->expects($this->exactly(count($expectedFile)))->method('close'); if (count($expectedFile) == 1) { $this->_directoryMock->expects($this->once())->method('renameFile')->will($this->returnCallback(function ($from, $to) { \PHPUnit_Framework_Assert::assertEquals('/sitemap-1-1.xml', $from); \PHPUnit_Framework_Assert::assertEquals('/sitemap.xml', $to); })); } // Check robots txt $robotsStart = ''; if (isset($robotsInfo['robotsStart'])) { $robotsStart = $robotsInfo['robotsStart']; } $robotsFinish = 'Sitemap: http://store.com/sitemap.xml'; if (isset($robotsInfo['robotsFinish'])) { $robotsFinish = $robotsInfo['robotsFinish']; } $this->_directoryMock->expects($this->any())->method('readFile')->will($this->returnValue($robotsStart)); $this->_directoryMock->expects($this->any())->method('write')->with($this->equalTo('robots.txt'), $this->equalTo($robotsFinish)); // Mock helper methods $pushToRobots = 0; if (isset($robotsInfo['pushToRobots'])) { $pushToRobots = (int) $robotsInfo['pushToRobots']; } $this->_helperMockSitemap->expects($this->any())->method('getMaximumLinesNumber')->will($this->returnValue($maxLines)); $this->_helperMockSitemap->expects($this->any())->method('getMaximumFileSize')->will($this->returnValue($maxFileSize)); $this->_helperMockSitemap->expects($this->any())->method('getEnableSubmissionRobots')->will($this->returnValue($pushToRobots)); $model = $this->_getModelMock(true); return $model; }
/** * @magentoConfigFixture default_store sitemap/product/image_include base */ public function testGetProductImageIncludePolicy() { $this->assertEquals('all', $this->_helper->getProductImageIncludePolicy(\Magento\Store\Model\Store::DEFAULT_STORE_ID)); $this->assertEquals('base', $this->_helper->getProductImageIncludePolicy(\Magento\Store\Model\Store::DISTRO_STORE_ID)); }
public function testGetValidPaths() { $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValueMap([[Data::XML_PATH_SITEMAP_VALID_PATHS, ScopeInterface::SCOPE_STORE, null, ['path1']], [Data::XML_PATH_PUBLIC_FILES_VALID_PATHS, ScopeInterface::SCOPE_STORE, null, ['path2']]])); $this->assertEquals(['path1', 'path2'], $this->data->getValidPaths()); }