protected function _prepareCollection() { // Get collection // --------------------------------------- $collection = $this->productFactory->create()->getCollection()->addAttributeToSelect('name'); // --------------------------------------- // --------------------------------------- $collection->getSelect()->distinct(); // --------------------------------------- // Set filter store // --------------------------------------- $store = $this->_storeManager->getStore($this->listing->getData('store_id')); if ($store->getId()) { $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', NULL, 'inner', $store->getId()); $collection->joinAttribute('thumbnail', 'catalog_product/thumbnail', 'entity_id', NULL, 'left', $store->getId()); } else { $collection->addAttributeToSelect('thumbnail'); } // --------------------------------------- // --------------------------------------- $productAddIds = (array) json_decode($this->listing->getChildObject()->getData('product_add_ids'), true); $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()); $elpTable = $this->activeRecordFactory->getObject('Ebay\\Listing\\Product')->getResource()->getMainTable(); $collection->joinTable(array('elp' => $elpTable), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id')); $collection->getSelect()->where('lp.id IN (?)', $productAddIds); // --------------------------------------- // Set collection to grid $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $data = $this->getHelper('Data\\GlobalData')->getValue('search_data'); $collection = $this->customCollectionFactory->create(); $collection->setConnection($this->resourceConnection->getConnection()); foreach ($data['data'] as $index => $item) { $temp = array('id' => $index, 'general_id' => $item['general_id'], 'brand' => $item['brand'], 'title' => $item['title'], 'image_url' => $item['image_url'], 'price' => isset($item['list_price']['amount']) ? $item['list_price']['amount'] : null, 'is_variation_product' => $item['is_variation_product']); if ($temp['is_variation_product']) { if (!$item['bad_parent']) { $temp += array('parentage' => $item['parentage'], 'variations' => $item['variations'], 'bad_parent' => $item['bad_parent']); } else { $temp['bad_parent'] = $item['bad_parent']; } if (!empty($item['requested_child_id'])) { $temp['requested_child_id'] = $item['requested_child_id']; } } $collection->addItem(new \Magento\Framework\DataObject($temp)); } $collection->setCustomSize(count($data)); $this->setCollection($collection); parent::_prepareCollection(); $collection->setCustomIsLoaded(true); return $this; }
protected function _prepareCollection() { $collection = $this->amazonFactory->getObject('Order')->getCollection(); $collection->getSelect()->joinLeft(array('so' => $this->resourceConnection->getTableName('sales_order')), '(so.entity_id = `main_table`.magento_order_id)', array('magento_order_num' => 'increment_id')); // Add Filter By Account // --------------------------------------- if ($accountId = $this->getRequest()->getParam('amazonAccount')) { $collection->addFieldToFilter('main_table.account_id', $accountId); } // --------------------------------------- // Add Filter By Marketplace // --------------------------------------- if ($marketplaceId = $this->getRequest()->getParam('amazonMarketplace')) { $collection->addFieldToFilter('main_table.marketplace_id', $marketplaceId); } // --------------------------------------- // Add Not Created Magento Orders Filter // --------------------------------------- if ($this->getRequest()->getParam('not_created_only')) { $collection->addFieldToFilter('magento_order_id', array('null' => true)); } // --------------------------------------- $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->activeRecordFactory->getObject('Order\\Log')->getCollection(); $collection->addFieldToFilter('order_id', $this->order->getId()); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->ebayFactory->getObject('Order\\Item')->getCollection()->addFieldToFilter('order_id', $this->order->getId()); //todo $collection->getSelect()->joinLeft(array('cisi' => $this->resourceConnection->getTableName('cataloginventory_stock_item')), '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)', array('is_in_stock')); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $failedProducts = json_decode($this->getRequest()->getParam('failed_products'), 1); $collection = $this->productFactory->create()->getCollection()->addAttributeToSelect('sku')->addAttributeToSelect('name')->addAttributeToSelect('type_id')->joinField('qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left')->joinField('is_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); $collection->addFieldToFilter('entity_id', array('in' => $failedProducts)); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $this->prepareCacheData(); $collection = $this->amazonFactory->getObject('Listing\\Other')->getCollection(); $collection->getSelect()->group(array('account_id', 'marketplace_id')); // Set collection to grid $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->amazonFactory->getObject('Listing\\Other')->getCollection(); $collection->getSelect()->joinLeft(array('mp' => $this->activeRecordFactory->getObject('Marketplace')->getResource()->getMainTable()), 'mp.id = main_table.marketplace_id', array('marketplace_title' => 'mp.title'))->joinLeft(array('am' => $this->activeRecordFactory->getObject('Amazon\\Marketplace')->getResource()->getMainTable()), 'am.marketplace_id = main_table.marketplace_id', array('currency' => 'am.default_currency')); // Add Filter By Account if ($this->getRequest()->getParam('account')) { $collection->addFieldToFilter('main_table.account_id', $this->getRequest()->getParam('account')); } // Add Filter By Marketplace if ($this->getRequest()->getParam('marketplace')) { $collection->addFieldToFilter('main_table.marketplace_id', $this->getRequest()->getParam('marketplace')); } $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $componentMode = $this->getHelper('Data\\GlobalData')->getValue('componentMode'); $ignoreListings = (array) $this->getHelper('Data\\GlobalData')->getValue('ignoreListings'); // Update statistic table values $this->activeRecordFactory->getObject('Listing')->getResource()->updateStatisticColumns(); $this->activeRecordFactory->getObject(ucfirst($componentMode) . '\\Listing')->getResource()->updateStatisticColumns(); $collection = $this->parentFactory->getObject($componentMode, 'Listing')->getCollection(); foreach ($ignoreListings as $listingId) { $collection->addFieldToFilter('main_table.id', array('neq' => $listingId)); } $this->addAccountAndMarketplaceFilter($collection); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Prepare selling format collection // --------------------------------------- $collectionSellingFormat = $this->activeRecordFactory->getObject('Template\\SellingFormat')->getCollection(); $collectionSellingFormat->getSelect()->reset(Select::COLUMNS); $collectionSellingFormat->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'' . self::TEMPLATE_SELLING_FORMAT . '\' as `type`'), new \Zend_Db_Expr('\'0\' as `marketplace_id`'), 'create_date', 'update_date', new \Zend_Db_Expr('NULL as `category_path`'), new \Zend_Db_Expr('NULL as `browsenode_id`'), new \Zend_Db_Expr('NULL as `is_new_asin_accepted`'))); $collectionSellingFormat->getSelect()->where('component_mode = (?)', \Ess\M2ePro\Helper\Component\Amazon::NICK); // --------------------------------------- // Prepare synchronization collection // --------------------------------------- $collectionSynchronization = $this->activeRecordFactory->getObject('Template\\Synchronization')->getCollection(); $collectionSynchronization->getSelect()->reset(Select::COLUMNS); $collectionSynchronization->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'' . self::TEMPLATE_SYNCHRONIZATION . '\' as `type`'), new \Zend_Db_Expr('\'0\' as `marketplace_id`'), 'create_date', 'update_date', new \Zend_Db_Expr('NULL as `category_path`'), new \Zend_Db_Expr('NULL as `browsenode_id`'), new \Zend_Db_Expr('NULL as `is_new_asin_accepted`'))); $collectionSynchronization->getSelect()->where('component_mode = (?)', \Ess\M2ePro\Helper\Component\Amazon::NICK); // --------------------------------------- // Prepare shipping override collection // --------------------------------------- $collectionShippingOverride = $this->activeRecordFactory->getObject('Amazon\\Template\\ShippingOverride')->getCollection(); $collectionShippingOverride->getSelect()->reset(Select::COLUMNS); $collectionShippingOverride->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'' . self::TEMPLATE_SHIPPING_OVERRIDE . '\' as `type`'), 'marketplace_id', 'create_date', 'update_date', new \Zend_Db_Expr('NULL as `category_path`'), new \Zend_Db_Expr('NULL as `browsenode_id`'), new \Zend_Db_Expr('NULL as `is_new_asin_accepted`'))); // --------------------------------------- // Prepare shipping override collection // --------------------------------------- $collectionDescription = $this->amazonFactory->getObject('Template\\Description')->getCollection(); $collectionDescription->getSelect()->join(array('mm' => $this->activeRecordFactory->getObject('Marketplace')->getResource()->getMainTable()), 'mm.id=second_table.marketplace_id', array()); $collectionDescription->addFieldToFilter('mm.status', \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE); $collectionDescription->getSelect()->reset(Select::COLUMNS); $collectionDescription->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'' . self::TEMPLATE_DESCRIPTION . '\' as `type`'), 'second_table.marketplace_id', 'create_date', 'update_date', 'second_table.category_path', 'second_table.browsenode_id', 'second_table.is_new_asin_accepted')); // --------------------------------------- // Prepare union select // --------------------------------------- $unionSelect = $this->resourceConnection->getConnection()->select(); $unionSelect->union(array($collectionSellingFormat->getSelect(), $collectionSynchronization->getSelect(), $collectionDescription->getSelect(), $collectionShippingOverride->getSelect())); // --------------------------------------- // Prepare result collection // --------------------------------------- /** @var \Ess\M2ePro\Model\ResourceModel\Collection\Custom $resultCollection */ $resultCollection = $this->customCollectionFactory->create(); $resultCollection->setConnection($this->resourceConnection->getConnection()); $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('template_id', 'title', 'type', 'marketplace_id', 'create_date', 'update_date', 'category_path', 'browsenode_id', 'is_new_asin_accepted')); // --------------------------------------- // echo $resultCollection->getSelectSql(true); exit; $this->setCollection($resultCollection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->ebayFactory->getObject('Listing\\Other')->getCollection(); $collection->getSelect()->joinLeft(array('mp' => $this->activeRecordFactory->getObject('Marketplace')->getResource()->getMainTable()), 'mp.id = main_table.marketplace_id', array('marketplace_title' => 'mp.title')); $collection->getSelect()->joinLeft(array('mea' => $this->activeRecordFactory->getObject('Ebay\\Account')->getResource()->getMainTable()), 'mea.account_id = main_table.account_id', array('account_mode' => 'mea.mode')); // Add Filter By Account if ($accountId = $this->getRequest()->getParam('account')) { $collection->addFieldToFilter('main_table.account_id', $accountId); } // Add Filter By Marketplace if ($marketplaceId = $this->getRequest()->getParam('marketplace')) { $collection->addFieldToFilter('main_table.marketplace_id', $marketplaceId); } $collection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $collection->getSelect()->columns(array('id' => 'main_table.id', 'account_id' => 'main_table.account_id', 'marketplace_id' => 'main_table.marketplace_id', 'product_id' => 'main_table.product_id', 'title' => 'second_table.title', 'sku' => 'second_table.sku', 'item_id' => 'second_table.item_id', 'online_qty' => new \Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'online_price' => 'second_table.online_price', 'status' => 'main_table.status', 'start_date' => 'second_table.start_date', 'end_date' => 'second_table.end_date', 'currency' => 'second_table.currency', 'account_mode' => 'mea.mode')); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $listingProductsIds = $this->listing->getSetting('additional_data', 'adding_listing_products_ids'); // Get collection // --------------------------------------- /* @var $collection \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection */ $collection = $this->magentoProductCollectionFactory->create(); $collection->setStoreId($this->listing['store_id'])->setListingProductModeOn()->addAttributeToSelect('name')->addAttributeToSelect('sku'); $collection->joinTable(array('cisi' => 'cataloginventory_stock_item'), 'product_id=entity_id', array('qty' => 'qty'), '{{table}}.stock_id=1', 'left'); // --------------------------------------- $lpTable = $this->activeRecordFactory->getObject('Listing\\Product')->getResource()->getMainTable(); $collection->joinTable(array('lp' => $lpTable), 'product_id=entity_id', array('id' => 'id', 'component_mode' => 'component_mode', 'amazon_status' => 'status', 'additional_data' => 'additional_data'), '{{table}}.listing_id=' . (int) $this->listing['id']); $alpTable = $this->activeRecordFactory->getObject('Amazon\\Listing\\Product')->getResource()->getMainTable(); $collection->joinTable(array('alp' => $alpTable), 'listing_product_id=id', array('general_id' => 'general_id', 'general_id_search_info' => 'general_id_search_info', 'search_settings_status' => 'search_settings_status', 'search_settings_data' => 'search_settings_data', 'variation_child_statuses' => 'variation_child_statuses', 'amazon_sku' => 'sku', 'online_qty' => 'online_qty', 'online_price' => 'online_price', 'online_sale_price' => 'online_sale_price', 'is_afn_channel' => 'is_afn_channel', 'is_general_id_owner' => 'is_general_id_owner', 'is_variation_parent' => 'is_variation_parent'), '{{table}}.variation_parent_id is NULL'); $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds); // --------------------------------------- $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Get collection // --------------------------------------- $collection = $this->ebayFactory->getObject('Listing\\Product\\Variation')->getCollection(); $collection->getSelect()->where('main_table.listing_product_id = ?', (int) $this->getListingProductId()); $collection->getSelect()->group('main_table.id'); // --------------------------------------- // Join variation option tables // --------------------------------------- $collection->getSelect()->join(array('mlpvo' => $this->activeRecordFactory->getObject('Listing\\Product\\Variation\\Option')->getResource()->getMainTable()), '`mlpvo`.`listing_product_variation_id`=`main_table`.`id`', array()); $collection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $collection->getSelect()->columns(array('id' => 'main_table.id', 'listing_product_id' => 'main_table.listing_product_id', 'additional_data' => 'main_table.additional_data', 'add' => 'second_table.add', 'delete' => 'second_table.delete', 'online_price' => 'second_table.online_price', 'online_sku' => 'second_table.online_sku', 'available_qty' => new \Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'status' => 'second_table.status', 'attributes' => 'GROUP_CONCAT(`mlpvo`.`attribute`, \'==\', `mlpvo`.`option` SEPARATOR \'||\')', 'products_ids' => 'GROUP_CONCAT(`mlpvo`.`attribute`, \'==\', `mlpvo`.`product_id` SEPARATOR \'||\')')); $resultCollection = $this->customCollection->create(); $resultCollection->setConnection($this->resourceConnection->getConnection()); $resultCollection->getSelect()->reset()->from(array('main_table' => $collection->getSelect()), array('id', 'listing_product_id', 'additional_data', 'add', 'delete', 'online_price', 'available_qty', 'online_sku', 'online_qty_sold', 'status', 'attributes', 'products_ids')); // Set collection to grid $this->setCollection($resultCollection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->activeRecordFactory->getObject('Order\\Log')->getCollection(); $collection->getSelect()->joinLeft(array('mo' => $this->activeRecordFactory->getObject('Order')->getResource()->getMainTable()), '(mo.id = `main_table`.order_id)', array('magento_order_id')); $componentNick = $this->getHelper('Data\\GlobalData')->getValue('component_nick'); if ($componentNick) { $accountId = (int) $this->getRequest()->getParam($componentNick . 'Account', false); $marketplaceId = (int) $this->getRequest()->getParam($componentNick . 'Marketplace', false); if ($accountId) { $collection->getSelect()->where('mo.account_id = ?', $accountId); } if ($marketplaceId) { $collection->getSelect()->where('mo.marketplace_id = ?', $marketplaceId); } } $collection->getSelect()->joinLeft(array('so' => $this->resourceConnection->getTableName('sales_order')), '(so.entity_id = `mo`.magento_order_id)', array('magento_order_number' => 'increment_id')); $orderId = $this->getRequest()->getParam('order_id'); if ($orderId && !$this->getRequest()->isXmlHttpRequest()) { $collection->addFieldToFilter('main_table.order_id', (int) $orderId); /** @var \Ess\M2ePro\Model\Order $order */ $order = $this->activeRecordFactory->getObjectLoaded('Order', (int) $orderId); $channelOrderId = $order->getData($order->getComponentMode() . '_order_id'); $this->_setFilterValues(array('channel_order_id' => $channelOrderId, 'component_mode' => $order->getComponentMode())); } $channel = $this->getRequest()->getParam('channel'); if (!empty($channel)) { $collection->getSelect()->where('main_table.component_mode = ?', $channel); } else { $components = $this->getHelper('View')->getComponentHelper()->getEnabledComponents(); $collection->addFieldToFilter('main_table.component_mode', array('in' => $components)); } // --------------------------------------- if ($this->getRequest()->getParam('sort', 'create_date') == 'create_date') { $collection->setOrder('id', $this->getRequest()->getParam('dir', 'DESC')); } // --------------------------------------- $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $select = $this->resourceConnection->getConnection()->select()->from($this->resourceConnection->getTableName('m2epro_amazon_dictionary_specific'))->where('marketplace_id = ?', (int) $this->marketplaceId)->where('product_data_nick = ?', $this->productDataNick)->where('type != ?', \Ess\M2ePro\Model\Amazon\Template\Description\Specific::DICTIONARY_TYPE_CONTAINER)->where('xpath LIKE ?', "{$this->currentXpath}/%")->order('title ASC'); if ($this->searchQuery) { $select->where('title LIKE ?', "%{$this->searchQuery}%"); } $filteredResult = []; $queryStmt = $select->query(); while ($row = $queryStmt->fetch()) { if (in_array($row['xpath'], $this->renderedSpecifics) || in_array($row['xpath'], $this->selectedSpecifics)) { continue; } $row['data_definition'] = (array) json_decode($row['data_definition'], true); $row['is_desired'] = !empty($row['data_definition']['is_desired']) && $row['data_definition']['is_desired']; if ($this->onlyDesired && !$row['is_desired']) { continue; } $filteredResult[] = $row; } usort($filteredResult, function ($a, $b) { if ($a['is_desired'] && !$b['is_desired']) { return -1; } if ($b['is_desired'] && !$a['is_desired']) { return 1; } return $a['title'] == $b['title'] ? 0 : ($a['title'] > $b['title'] ? 1 : -1); }); $collection = $this->customCollectionFactory->create(); $collection->setConnection($this->resourceConnection->getConnection()); foreach ($filteredResult as $item) { $collection->addItem(new \Magento\Framework\DataObject($item)); } $collection->setCustomSize(count($filteredResult)); $this->setCollection($collection); parent::_prepareCollection(); $collection->setCustomIsLoaded(true); return $this; }
protected function _prepareCollection() { // Get collection logs // --------------------------------------- $categoriesCollection = $this->activeRecordFactory->getObject('Listing\\Auto\\Category')->getCollection(); $categoriesCollection->getSelect()->reset(\Zend_Db_Select::FROM); $categoriesCollection->getSelect()->from(array('mlac' => $this->activeRecordFactory->getObject('Listing\\Auto\\Category')->getResource()->getMainTable())); $categoriesCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $categoriesCollection->getSelect()->columns(new \Zend_Db_Expr('GROUP_CONCAT(`category_id`)')); $categoriesCollection->getSelect()->where('mlac.group_id = main_table.id'); $collection = $this->activeRecordFactory->getObject('Listing\\Auto\\Category\\Group')->getCollection(); $collection->addFieldToFilter('main_table.listing_id', $this->getRequest()->getParam('id')); $collection->getSelect()->columns(array('categories' => new \Zend_Db_Expr('(' . $categoriesCollection->getSelect() . ')'))); // --------------------------------------- // we need sort by id also, because create_date may be same for some adjustment entries // --------------------------------------- if ($this->getRequest()->getParam('sort', 'create_date') == 'create_date') { $collection->setOrder('id', $this->getRequest()->getParam('dir', 'DESC')); } // --------------------------------------- // Set collection to grid $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $this->setNoTemplatesText(); /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\Description\Collection $descriptionCollection */ $descriptionCollection = $this->parentFactory->getObject(\Ess\M2ePro\Helper\View\Amazon::NICK, 'Template\\Description')->getCollection(); $descriptionCollection->addFieldToFilter('marketplace_id', $this->getMarketplaceId()); $preparedCollection = $this->customCollectionFactory->create(); $preparedCollection->setConnection($this->resourceConnection->getConnection()); $data = $descriptionCollection->getData(); $preparedData = []; foreach ($data as $item) { if (!$this->getCheckNewAsinAccepted()) { $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED; $preparedData[] = $item; continue; } if (!$item['is_new_asin_accepted']) { $item['description_template_action_status'] = self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED; $preparedData[] = $item; continue; } $variationProductsIds = $this->getVariationsProductsIds(); if (!empty($variationProductsIds)) { $detailsModel = $this->modelFactory->getObject('Amazon\\Marketplace\\Details'); $detailsModel->setMarketplaceId($this->getMarketplaceId()); $themes = $detailsModel->getVariationThemes($item['product_data_nick']); if (empty($themes)) { $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED; $preparedData[] = $item; continue; } } $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED; $preparedData[] = $item; continue; } if (!empty($preparedData)) { usort($preparedData, function ($a, $b) { return $a["description_template_action_status"] < $b["description_template_action_status"]; }); foreach ($preparedData as $item) { $preparedCollection->addItem(new \Magento\Framework\DataObject($item)); } } $preparedCollection->setCustomSize(count($preparedData)); $this->setCollection($preparedCollection); parent::_prepareCollection(); $preparedCollection->setCustomIsLoaded(true); return $this; }
protected function _prepareCollection() { $collection = $this->productModel->getCollection()->addAttributeToSelect('sku')->addAttributeToSelect('name')->addAttributeToSelect('type_id')->joinField('qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left')->joinField('is_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Get collection products in listing // --------------------------------------- $nameAttribute = $this->resourceCatalogProduct->getAttribute('name'); $nameAttributeId = $nameAttribute ? (int) $nameAttribute->getId() : 0; $listingProductCollection = $this->ebayFactory->getObject('Listing\\Product')->getCollection(); $listingProductCollection->getSelect()->distinct(); $listingProductCollection->getSelect()->join(array('l' => $this->activeRecordFactory->getObject('Listing')->getResource()->getMainTable()), '`l`.`id` = `main_table`.`listing_id`'); $listingProductCollection->getSelect()->join(array('em' => $this->activeRecordFactory->getObject('Ebay\\Marketplace')->getResource()->getMainTable()), '`em`.`marketplace_id` = `l`.`marketplace_id`'); $listingProductCollection->getSelect()->join(array('cpe' => $this->resourceConnection->getTableName('catalog_product_entity')), 'cpe.entity_id = `main_table`.product_id'); $listingProductCollection->getSelect()->joinLeft(array('cpev' => $this->resourceConnection->getTableName('catalog_product_entity_varchar')), '`cpev`.`entity_id` = `main_table`.`product_id`' . ' AND `cpev`.`attribute_id` = ' . $nameAttributeId . ' AND `cpev`.`store_id` = 0'); $listingProductCollection->getSelect()->joinLeft(array('ebit' => $this->activeRecordFactory->getObject('Ebay\\Item')->getResource()->getMainTable()), '(`ebit`.`id` = `second_table`.`ebay_item_id`)', array('item_id')); // --------------------------------------- // add stock availability, status & visibility to select // --------------------------------------- $listingProductCollection->getSelect()->joinLeft(array('cisi' => $this->resourceStockItem->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND `cisi`.`stock_id` = 1)', array('is_in_stock')); // --------------------------------------- $listingProductCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $listingProductCollection->getSelect()->columns(array('account_id' => 'l.account_id', 'marketplace_id' => 'l.marketplace_id', 'product_id' => 'main_table.product_id', 'product_name' => 'cpev.value', 'product_sku' => 'cpe.sku', 'currency' => 'em.currency', 'ebay_item_id' => 'ebit.item_id', 'listing_product_id' => 'main_table.id', 'listing_other_id' => new \Zend_Db_Expr('NULL'), 'additional_data' => 'main_table.additional_data', 'status' => 'main_table.status', 'online_sku' => 'second_table.online_sku', 'online_title' => 'second_table.online_title', 'online_qty' => new \Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'online_bids' => 'second_table.online_bids', 'online_start_price' => 'second_table.online_start_price', 'online_current_price' => 'second_table.online_current_price', 'online_reserve_price' => 'second_table.online_reserve_price', 'online_buyitnow_price' => 'second_table.online_buyitnow_price', 'min_online_price' => 'IF( (`t`.`variation_min_price` IS NULL), `second_table`.`online_current_price`, `t`.`variation_min_price` )', 'max_online_price' => 'IF( (`t`.`variation_max_price` IS NULL), `second_table`.`online_current_price`, `t`.`variation_max_price` )', 'listing_id' => 'l.id', 'listing_title' => 'l.title', 'is_m2epro_listing' => new \Zend_Db_Expr(1), 'is_in_stock' => 'cisi.is_in_stock')); $listingProductCollection->getSelect()->joinLeft(new \Zend_Db_Expr('( SELECT `mlpv`.`listing_product_id`, MIN(`melpv`.`online_price`) as variation_min_price, MAX(`melpv`.`online_price`) as variation_max_price FROM `' . $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource()->getMainTable() . '` AS `mlpv` INNER JOIN `' . $this->activeRecordFactory->getObject('Ebay\\Listing\\Product\\Variation')->getResource()->getMainTable() . '` AS `melpv` ON (`mlpv`.`id` = `melpv`.`listing_product_variation_id`) WHERE `melpv`.`status` != ' . \Ess\M2ePro\Model\Listing\Product::STATUS_NOT_LISTED . ' GROUP BY `mlpv`.`listing_product_id` )'), 'second_table.listing_product_id=t.listing_product_id', array('variation_min_price' => 'variation_min_price', 'variation_max_price' => 'variation_max_price')); // --------------------------------------- // --------------------------------------- $listingOtherCollection = $this->ebayFactory->getObject('Listing\\Other')->getCollection(); $listingOtherCollection->getSelect()->distinct(); // add stock availability, type id, status & visibility to select // --------------------------------------- $listingOtherCollection->getSelect()->joinLeft(array('cisi' => $this->resourceStockItem->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)', array('is_in_stock')); // --------------------------------------- $listingOtherCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $listingOtherCollection->getSelect()->columns(array('account_id' => 'main_table.account_id', 'marketplace_id' => 'main_table.marketplace_id', 'product_id' => 'main_table.product_id', 'product_name' => 'second_table.title', 'product_sku' => 'second_table.sku', 'currency' => 'second_table.currency', 'ebay_item_id' => 'second_table.item_id', 'listing_product_id' => new \Zend_Db_Expr('NULL'), 'listing_other_id' => 'main_table.id', 'additional_data' => new \Zend_Db_Expr('NULL'), 'status' => 'main_table.status', 'online_sku' => new \Zend_Db_Expr('NULL'), 'online_title' => new \Zend_Db_Expr('NULL'), 'online_qty' => new \Zend_Db_Expr('(second_table.online_qty - second_table.online_qty_sold)'), 'online_qty_sold' => 'second_table.online_qty_sold', 'online_bids' => new \Zend_Db_Expr('NULL'), 'online_start_price' => new \Zend_Db_Expr('NULL'), 'online_current_price' => 'second_table.online_price', 'online_reserve_price' => new \Zend_Db_Expr('NULL'), 'online_buyitnow_price' => new \Zend_Db_Expr('NULL'), 'min_online_price' => 'second_table.online_price', 'max_online_price' => 'second_table.online_price', 'listing_id' => new \Zend_Db_Expr('NULL'), 'listing_title' => new \Zend_Db_Expr('NULL'), 'is_m2epro_listing' => new \Zend_Db_Expr(0), 'is_in_stock' => 'cisi.is_in_stock', 'variation_min_price' => new \Zend_Db_Expr('NULL'), 'variation_max_price' => new \Zend_Db_Expr('NULL'))); // --------------------------------------- // --------------------------------------- $selects = array($listingProductCollection->getSelect()); $selects[] = $listingOtherCollection->getSelect(); $unionSelect = $this->resourceConnection->getConnection()->select(); $unionSelect->union($selects); $resultCollection = $this->customCollectionFactory->create(); $resultCollection->setConnection($this->resourceConnection->getConnection()); $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('account_id', 'marketplace_id', 'product_id', 'product_name', 'product_sku', 'currency', 'ebay_item_id', 'listing_product_id', 'listing_other_id', 'additional_data', 'status', 'online_sku', 'online_title', 'online_qty', 'online_qty_sold', 'online_bids', 'online_start_price', 'online_current_price', 'online_reserve_price', 'online_buyitnow_price', 'min_online_price', 'max_online_price', 'listing_id', 'listing_title', 'is_m2epro_listing', 'is_in_stock')); // --------------------------------------- $accountId = (int) $this->getRequest()->getParam('ebayAccount', false); $marketplaceId = (int) $this->getRequest()->getParam('ebayMarketplace', false); $listingType = (int) $this->getRequest()->getParam('listing_type', false); if ($accountId) { $resultCollection->getSelect()->where('account_id = ?', $accountId); } if ($marketplaceId) { $resultCollection->getSelect()->where('marketplace_id = ?', $marketplaceId); } if ($listingType) { if ($listingType == Switcher::LISTING_TYPE_M2E_PRO) { $resultCollection->getSelect()->where('is_m2epro_listing = ?', 1); } elseif ($listingType == Switcher::LISTING_TYPE_LISTING_OTHER) { $resultCollection->getSelect()->where('is_m2epro_listing = ?', 0); } } $this->setCollection($resultCollection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Prepare selling format collection // --------------------------------------- $collectionSellingFormat = $this->activeRecordFactory->getObject('Template\\SellingFormat')->getCollection(); $collectionSellingFormat->getSelect()->join(array('etsf' => $this->activeRecordFactory->getObject('Ebay\\Template\\SellingFormat')->getResource()->getMainTable()), 'main_table.id=etsf.template_selling_format_id', array('is_custom_template')); $collectionSellingFormat->getSelect()->reset(Select::COLUMNS); $collectionSellingFormat->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'0\' as `marketplace`'), new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_SELLING_FORMAT . '\' as `nick`'), 'create_date', 'update_date')); $collectionSellingFormat->addFieldToFilter('component_mode', \Ess\M2ePro\Helper\Component\Ebay::NICK); $collectionSellingFormat->addFieldToFilter('is_custom_template', 0); // --------------------------------------- // Prepare synchronization collection // --------------------------------------- $collectionSynchronization = $this->activeRecordFactory->getObject('Template\\Synchronization')->getCollection(); $collectionSynchronization->getSelect()->join(array('ets' => $this->activeRecordFactory->getObject('Ebay\\Template\\Synchronization')->getResource()->getMainTable()), 'main_table.id=ets.template_synchronization_id', array('is_custom_template')); $collectionSynchronization->getSelect()->reset(Select::COLUMNS); $collectionSynchronization->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'0\' as `marketplace`'), new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_SYNCHRONIZATION . '\' as `nick`'), 'create_date', 'update_date')); $collectionSynchronization->addFieldToFilter('component_mode', \Ess\M2ePro\Helper\Component\Ebay::NICK); $collectionSynchronization->addFieldToFilter('is_custom_template', 0); // --------------------------------------- // Prepare description collection // --------------------------------------- $collectionDescription = $this->activeRecordFactory->getObject('Template\\Description')->getCollection(); $collectionDescription->getSelect()->join(array('ets' => $this->activeRecordFactory->getObject('Ebay\\Template\\Description')->getResource()->getMainTable()), 'main_table.id=ets.template_description_id', array('is_custom_template')); $collectionDescription->getSelect()->reset(Select::COLUMNS); $collectionDescription->getSelect()->columns(array('id as template_id', 'title', new \Zend_Db_Expr('\'0\' as `marketplace`'), new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_DESCRIPTION . '\' as `nick`'), 'create_date', 'update_date')); $collectionDescription->addFieldToFilter('component_mode', \Ess\M2ePro\Helper\Component\Ebay::NICK); $collectionDescription->addFieldToFilter('is_custom_template', 0); // --------------------------------------- // Prepare payment collection // --------------------------------------- $collectionPayment = $this->activeRecordFactory->getObject('Ebay\\Template\\Payment')->getCollection(); $collectionPayment->getSelect()->reset(Select::COLUMNS); $collectionPayment->getSelect()->columns(array('id as template_id', 'title', 'marketplace_id as marketplace', new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_PAYMENT . '\' as `nick`'), 'create_date', 'update_date')); $collectionPayment->addFieldToFilter('is_custom_template', 0); $collectionPayment->addFieldToFilter('marketplace_id', array('in' => $this->getEnabledMarketplacesIds())); // --------------------------------------- // Prepare shipping collection // --------------------------------------- $collectionShipping = $this->activeRecordFactory->getObject('Ebay\\Template\\Shipping')->getCollection(); $collectionShipping->getSelect()->reset(Select::COLUMNS); $collectionShipping->getSelect()->columns(array('id as template_id', 'title', 'marketplace_id as marketplace', new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_SHIPPING . '\' as `nick`'), 'create_date', 'update_date')); $collectionShipping->addFieldToFilter('is_custom_template', 0); $collectionShipping->addFieldToFilter('marketplace_id', array('in' => $this->getEnabledMarketplacesIds())); // --------------------------------------- // Prepare return collection // --------------------------------------- $collectionReturn = $this->activeRecordFactory->getObject('Ebay\\Template\\ReturnPolicy')->getCollection(); $collectionReturn->getSelect()->reset(Select::COLUMNS); $collectionReturn->getSelect()->columns(array('id as template_id', 'title', 'marketplace_id as marketplace', new \Zend_Db_Expr('\'' . \Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_RETURN_POLICY . '\' as `nick`'), 'create_date', 'update_date')); $collectionReturn->addFieldToFilter('is_custom_template', 0); $collectionReturn->addFieldToFilter('marketplace_id', array('in' => $this->getEnabledMarketplacesIds())); // --------------------------------------- // Prepare union select // --------------------------------------- $unionSelect = $this->resourceConnection->getConnection()->select(); $unionSelect->union(array($collectionSellingFormat->getSelect(), $collectionSynchronization->getSelect(), $collectionDescription->getSelect(), $collectionPayment->getSelect(), $collectionShipping->getSelect(), $collectionReturn->getSelect())); // --------------------------------------- // Prepare result collection // --------------------------------------- /** @var \Ess\M2ePro\Model\ResourceModel\Collection\Custom $resultCollection */ $resultCollection = $this->customCollectionFactory->create(); $resultCollection->setConnection($this->resourceConnection->getConnection()); $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('template_id', 'title', 'nick', 'marketplace', 'create_date', 'update_date')); // --------------------------------------- $this->setCollection($resultCollection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Get collection products in listing // --------------------------------------- $listingProductCollection = $this->amazonFactory->getObject('Listing\\Product')->getCollection(); $listingProductCollection->getSelect()->distinct(); $listingProductCollection->getSelect()->join(array('l' => $this->activeRecordFactory->getObject('Listing')->getResource()->getMainTable()), '(`l`.`id` = `main_table`.`listing_id`)', array('listing_title' => 'title', 'store_id', 'marketplace_id'))->join(array('al' => $this->activeRecordFactory->getObject('Amazon\\Listing')->getResource()->getMainTable()), '(`al`.`listing_id` = `l`.`id`)', array('template_selling_format_id')); // --------------------------------------- // only parents and individuals $listingProductCollection->getSelect()->where('second_table.variation_parent_id IS NULL'); // Communicate with magento product table // --------------------------------------- $dbSelect = $this->resourceConnection->getConnection()->select()->from($this->resourceConnection->getTableName('catalog_product_entity_varchar'), new \Zend_Db_Expr('MAX(`store_id`)'))->where("`entity_id` = `main_table`.`product_id`")->where("`attribute_id` = `ea`.`attribute_id`")->where("`store_id` = 0 OR `store_id` = `l`.`store_id`"); $listingProductCollection->getSelect()->join(array('cpe' => $this->resourceConnection->getTableName('catalog_product_entity')), '(cpe.entity_id = `main_table`.product_id)', array('magento_sku' => 'sku'))->join(array('cisi' => $this->resourceConnection->getTableName('cataloginventory_stock_item')), '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)', array('is_in_stock'))->join(array('cpev' => $this->resourceConnection->getTableName('catalog_product_entity_varchar')), "(`cpev`.`entity_id` = `main_table`.product_id)", array('value'))->join(array('ea' => $this->resourceConnection->getTableName('eav_attribute')), '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')', array())->where('`cpev`.`store_id` = (' . $dbSelect->__toString() . ')'); // --------------------------------------- $listingProductCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $listingProductCollection->getSelect()->columns(array('is_m2epro_listing' => new \Zend_Db_Expr('1'), 'magento_sku' => 'cpe.sku', 'is_in_stock' => 'cisi.is_in_stock', 'product_name' => 'cpev.value', 'listing_title' => 'l.title', 'store_id' => 'l.store_id', 'account_id' => 'l.account_id', 'marketplace_id' => 'l.marketplace_id', 'template_selling_format_id' => 'al.template_selling_format_id', 'listing_product_id' => 'main_table.id', 'product_id' => 'main_table.product_id', 'listing_id' => 'main_table.listing_id', 'status' => 'main_table.status', 'is_general_id_owner' => 'second_table.is_general_id_owner', 'general_id' => 'second_table.general_id', 'is_afn_channel' => 'second_table.is_afn_channel', 'is_variation_parent' => 'second_table.is_variation_parent', 'variation_child_statuses' => 'second_table.variation_child_statuses', 'online_sku' => 'second_table.sku', 'online_qty' => 'second_table.online_qty', 'online_price' => 'second_table.online_price', 'online_sale_price' => 'second_table.online_sale_price', 'online_sale_price_start_date' => 'second_table.online_sale_price_start_date', 'online_sale_price_end_date' => 'second_table.online_sale_price_end_date', 'min_online_price' => 'IF( (`t`.`variation_min_price` IS NULL), IF( `second_table`.`online_sale_price_start_date` IS NOT NULL AND `second_table`.`online_sale_price_end_date` IS NOT NULL AND `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(), `second_table`.`online_sale_price`, `second_table`.`online_price` ), `t`.`variation_min_price` )', 'max_online_price' => 'IF( (`t`.`variation_max_price` IS NULL), IF( `second_table`.`online_sale_price_start_date` IS NOT NULL AND `second_table`.`online_sale_price_end_date` IS NOT NULL AND `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(), `second_table`.`online_sale_price`, `second_table`.`online_price` ), `t`.`variation_max_price` )')); $listingProductCollection->getSelect()->joinLeft(new \Zend_Db_Expr('( SELECT `malp`.`variation_parent_id`, MIN( IF( `malp`.`online_sale_price_start_date` IS NOT NULL AND `malp`.`online_sale_price_end_date` IS NOT NULL AND `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND `malp`.`online_sale_price_end_date` >= CURRENT_DATE(), `malp`.`online_sale_price`, `malp`.`online_price` ) ) as variation_min_price, MAX( IF( `malp`.`online_sale_price_start_date` IS NOT NULL AND `malp`.`online_sale_price_end_date` IS NOT NULL AND `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND `malp`.`online_sale_price_end_date` >= CURRENT_DATE(), `malp`.`online_sale_price`, `malp`.`online_price` ) ) as variation_max_price FROM `' . $this->activeRecordFactory->getObject('Amazon\\Listing\\Product')->getResource()->getMainTable() . '` as malp INNER JOIN `' . $this->activeRecordFactory->getObject('Listing\\Product')->getResource()->getMainTable() . '` AS `mlp` ON (`malp`.`listing_product_id` = `mlp`.`id`) WHERE `mlp`.`status` IN ( ' . \Ess\M2ePro\Model\Listing\Product::STATUS_LISTED . ', ' . \Ess\M2ePro\Model\Listing\Product::STATUS_STOPPED . ', ' . \Ess\M2ePro\Model\Listing\Product::STATUS_UNKNOWN . ' ) AND `malp`.`variation_parent_id` IS NOT NULL GROUP BY `malp`.`variation_parent_id` )'), 'second_table.listing_product_id=t.variation_parent_id', array('variation_min_price' => 'variation_min_price', 'variation_max_price' => 'variation_max_price')); // --------------------------------------- $listingOtherCollection = $this->amazonFactory->getObject('Listing\\Other')->getCollection(); $listingOtherCollection->getSelect()->distinct(); // add stock availability, type id, status & visibility to select // --------------------------------------- $listingOtherCollection->getSelect()->joinLeft(array('cisi' => $this->resourceStockItem->getMainTable()), '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)', array('is_in_stock'))->joinLeft(array('cpe' => $this->resourceConnection->getTableName('catalog_product_entity')), '(cpe.entity_id = `main_table`.product_id)', array('magento_sku' => 'sku')); // --------------------------------------- $listingOtherCollection->getSelect()->reset(\Zend_Db_Select::COLUMNS); $listingOtherCollection->getSelect()->columns(array('is_m2epro_listing' => new \Zend_Db_Expr(0), 'magento_sku' => 'cpe.sku', 'is_in_stock' => 'cisi.is_in_stock', 'product_name' => 'second_table.title', 'listing_title' => new \Zend_Db_Expr('NULL'), 'store_id' => new \Zend_Db_Expr(0), 'account_id' => 'main_table.account_id', 'marketplace_id' => 'main_table.marketplace_id', 'template_selling_format_id' => new \Zend_Db_Expr('NULL'), 'listing_product_id' => new \Zend_Db_Expr('NULL'), 'product_id' => 'main_table.product_id', 'listing_id' => new \Zend_Db_Expr('NULL'), 'status' => 'main_table.status', 'is_general_id_owner' => new \Zend_Db_Expr('NULL'), 'general_id' => 'second_table.general_id', 'is_afn_channel' => 'second_table.is_afn_channel', 'is_variation_parent' => new \Zend_Db_Expr('NULL'), 'variation_child_statuses' => new \Zend_Db_Expr('NULL'), 'online_sku' => 'second_table.sku', 'online_qty' => 'second_table.online_qty', 'online_price' => 'second_table.online_price', 'online_sale_price' => new \Zend_Db_Expr('NULL'), 'online_sale_price_start_date' => new \Zend_Db_Expr('NULL'), 'online_sale_price_end_date' => new \Zend_Db_Expr('NULL'), 'min_online_price' => 'second_table.online_price', 'max_online_price' => 'second_table.online_price', 'variation_min_price' => new \Zend_Db_Expr('NULL'), 'variation_max_price' => new \Zend_Db_Expr('NULL'))); // --------------------------------------- // --------------------------------------- $selects = array($listingProductCollection->getSelect(), $listingOtherCollection->getSelect()); $unionSelect = $this->resourceConnection->getConnection()->select(); $unionSelect->union($selects); $resultCollection = $this->customCollectionFactory->create(); $resultCollection->setConnection($this->resourceConnection->getConnection()); $resultCollection->getSelect()->reset()->from(array('main_table' => $unionSelect), array('is_m2epro_listing', 'magento_sku', 'is_in_stock', 'product_name', 'listing_title', 'store_id', 'account_id', 'marketplace_id', 'template_selling_format_id', 'listing_product_id', 'product_id', 'listing_id', 'status', 'is_general_id_owner', 'general_id', 'is_afn_channel', 'is_variation_parent', 'variation_child_statuses', 'online_sku', 'online_qty', 'online_price', 'online_sale_price', 'online_sale_price_start_date', 'online_sale_price_end_date', 'min_online_price', 'max_online_price', 'variation_min_price', 'variation_max_price')); // --------------------------------------- $accountId = (int) $this->getRequest()->getParam('amazonAccount', false); $marketplaceId = (int) $this->getRequest()->getParam('amazonMarketplace', false); $listingType = (int) $this->getRequest()->getParam('listing_type', false); if ($accountId) { $resultCollection->getSelect()->where('account_id = ?', $accountId); } if ($marketplaceId) { $resultCollection->getSelect()->where('marketplace_id = ?', $marketplaceId); } if ($listingType) { if ($listingType == Switcher::LISTING_TYPE_M2E_PRO) { $resultCollection->getSelect()->where('is_m2epro_listing = ?', 1); } elseif ($listingType == Switcher::LISTING_TYPE_LISTING_OTHER) { $resultCollection->getSelect()->where('is_m2epro_listing = ?', 0); } } // Set collection to grid $this->setCollection($resultCollection); return parent::_prepareCollection(); }
protected function _prepareCollection() { // Get collection // --------------------------------------- $collection = $this->amazonFactory->getObject('Listing\\Product')->getCollection(); $collection->getSelect()->distinct(); $collection->getSelect()->where("`second_table`.`variation_parent_id` = ?", (int) $this->getListingProduct()->getId()); // --------------------------------------- $lpvTable = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource()->getMainTable(); $lpvoTable = $this->activeRecordFactory->getObject('Listing\\Product\\Variation\\Option')->getResource()->getMainTable(); $collection->getSelect()->joinLeft(new \Zend_Db_Expr('( SELECT mlpv.listing_product_id, GROUP_CONCAT(`mlpvo`.`attribute`, \'==\', `mlpvo`.`product_id` SEPARATOR \'||\') as products_ids FROM `' . $lpvTable . '` as mlpv INNER JOIN `' . $lpvoTable . '` AS `mlpvo` ON (`mlpvo`.`listing_product_variation_id`=`mlpv`.`id`) WHERE `mlpv`.`component_mode` = \'amazon\' GROUP BY `mlpv`.`listing_product_id` )'), 'main_table.id=t.listing_product_id', array('products_ids' => 'products_ids')); // TODO // $collection->getSelect()->joinLeft( // array('malpr' => Mage::getResourceModel('M2ePro/Amazon_Listing_Product_Repricing')->getMainTable()), // '(`second_table`.`listing_product_id` = `malpr`.`listing_product_id`)', // array( // 'is_repricing' => 'listing_product_id', // 'is_repricing_disabled' => 'is_online_disabled', // ) // ); // Set collection to grid $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { $collection = $this->order->getChildObject()->getExternalTransactionsCollection(); $this->setCollection($collection); return parent::_prepareCollection(); }