Example #1
0
 protected function _prepareCollection()
 {
     $collection = $this->productFactory->create()->getCollection()->addAttributeToSelect('sku')->addAttributeToSelect('name')->addAttributeToSelect('type_id');
     $collection->joinTable(array('cisi' => 'cataloginventory_stock_item'), 'product_id=entity_id', array('qty' => 'qty', 'is_in_stock' => 'is_in_stock'), '{{table}}.stock_id=1', 'left');
     // ---------------------------------------
     $collection->getSelect()->distinct();
     // ---------------------------------------
     // Set filter store
     // ---------------------------------------
     $store = $this->_getStore();
     if ($store->getId()) {
         $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', NULL, 'left', $store->getId());
         $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', NULL, 'inner', $store->getId());
         $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', NULL, 'inner', $store->getId());
         $collection->joinAttribute('thumbnail', 'catalog_product/thumbnail', 'entity_id', NULL, 'left', $store->getId());
     } else {
         $collection->addAttributeToSelect('price');
         $collection->addAttributeToSelect('status');
         $collection->addAttributeToSelect('visibility');
         $collection->addAttributeToSelect('thumbnail');
     }
     // ---------------------------------------
     // Hide products others listings
     // ---------------------------------------
     $prefix = $this->getHelper('Data\\GlobalData')->getValue('hide_products_others_listings_prefix');
     is_null($hideParam = $this->getHelper('Data\\Session')->getValue($prefix)) && ($hideParam = true);
     if ($hideParam || isset($this->listing['id'])) {
         $lpTable = $this->activeRecordFactory->getObject('Listing\\Product')->getResource()->getMainTable();
         $dbExcludeSelect = $collection->getConnection()->select()->from($lpTable, new \Zend_Db_Expr('DISTINCT `product_id`'));
         if ($hideParam) {
             $lTable = $this->activeRecordFactory->getObject('Listing')->getResource()->getMainTable();
             $dbExcludeSelect->join(array('l' => $lTable), '`l`.`id` = `listing_id`', NULL);
             $dbExcludeSelect->where('`l`.`account_id` = ?', $this->listing['account_id']);
             $dbExcludeSelect->where('`l`.`marketplace_id` = ?', $this->listing['marketplace_id']);
             $dbExcludeSelect->where('`l`.`component_mode` = ?', \Ess\M2ePro\Helper\Component\Ebay::NICK);
         } else {
             $dbExcludeSelect->where('`listing_id` = ?', (int) $this->listing['id']);
         }
         $collection->getSelect()->joinLeft(array('sq' => $dbExcludeSelect), 'sq.product_id = e.entity_id', array())->where('sq.product_id IS NULL');
     }
     // ---------------------------------------
     $collection->addFieldToFilter(array(array('attribute' => 'type_id', 'neq' => 'virtual')));
     $this->setCollection($collection);
     $this->getCollection()->addWebsiteNamesToResult();
     return parent::_prepareCollection();
 }
Example #2
0
 protected function _prepareCollection()
 {
     // Get collection
     // ---------------------------------------
     /* @var $collection \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection */
     $collection = $this->magentoProductCollectionFactory->create();
     $collection->setListingProductModeOn();
     $collection->setStoreId($this->listing->getData('store_id'))->addAttributeToSelect('name')->addAttributeToSelect('sku');
     // ---------------------------------------
     // ---------------------------------------
     $listingProductsIds = $this->listing->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
     $lpTable = $this->activeRecordFactory->getObject('Listing\\Product')->getResource()->getMainTable();
     $collection->joinTable(array('lp' => $lpTable), 'product_id=entity_id', array('id' => 'id'), '{{table}}.listing_id=' . (int) $this->listing->getId());
     $alpTable = $this->activeRecordFactory->getObject('Amazon\\Listing\\Product')->getResource()->getMainTable();
     $collection->joinTable(array('alp' => $alpTable), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_description_id' => 'template_description_id'));
     $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds);
     $collection->getSelect()->where('alp.search_settings_status != ? OR alp.search_settings_status IS NULL', \Ess\M2ePro\Model\Amazon\Listing\Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS);
     $collection->getSelect()->where('alp.general_id IS NULL');
     // ---------------------------------------
     $this->setCollection($collection);
     parent::_prepareCollection();
     return $this;
 }