Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * @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));
 }