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 _toHtml() { if ($this->getRequest()->isXmlHttpRequest()) { $this->js->add(<<<JS ListingGridHandlerObj.afterInitPage(); JS ); return parent::_toHtml(); } $showNotCompletedPopup = ''; if ($this->getRequest()->getParam('not_completed', false)) { $showNotCompletedPopup = 'ListingGridHandlerObj.showNotCompletedPopup();'; } $this->js->add(<<<JS require([ 'M2ePro/Amazon/Listing/Product/Add/SearchAsin/Grid' ],function() { ListingGridHandlerObj = new AmazonListingProductAddSearchAsinGrid( '{$this->getId()}', {$this->listing->getId()} ); ListingGridHandlerObj.actionHandler.setOptions(M2ePro); ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro); ListingGridHandlerObj.afterInitPage(); {$showNotCompletedPopup} }); JS ); if (!$this->listing->getChildObject()->isGeneralIdAttributeMode() && !$this->listing->getChildObject()->isWorldwideIdAttributeMode()) { if (!$this->listing->getChildObject()->isSearchByMagentoTitleModeEnabled()) { $gridId = $this->getId(); $this->js->add(<<<JS var mmassActionEl = \$("{$gridId}_massaction-select"); if (mmassActionEl && mmassActionEl.select('option[value="assignGeneralId"]').length > 0) { var assignGeneralIdOption = mmassActionEl.select('option[value="assignGeneralId"]')[0]; assignGeneralIdOption.disabled = true; mmassActionEl.insert({bottom: assignGeneralIdOption.remove()}); } JS ); } } else { $autoSearchSetting = $this->listing->getSetting('additional_data', 'auto_search_was_performed'); if (!$autoSearchSetting) { $this->listing->setSetting('additional_data', 'auto_search_was_performed', 1); $this->listing->save(); $this->js->add(<<<JS ListingGridHandlerObj.getGridMassActionObj().selectAll(); ListingGridHandlerObj.productSearchHandler.searchGeneralIdAuto(ListingGridHandlerObj.getSelectedProductsString()); JS ); } } return parent::_toHtml(); }
/** * @param \Magento\Catalog\Model\Product $product * @param \Ess\M2ePro\Model\Listing $listing * @throws \Ess\M2ePro\Model\Exception\Logic */ public function addProductByWebsiteListing(\Magento\Catalog\Model\Product $product, \Ess\M2ePro\Model\Listing $listing) { $logData = array('reason' => __METHOD__); $listingProduct = $this->getListing()->addProduct($product, false, true, $logData); if (!$listingProduct instanceof \Ess\M2ePro\Model\Listing\Product) { return; } /** @var \Ess\M2ePro\Model\Ebay\Listing $ebayListing */ $ebayListing = $listing->getChildObject(); $params = array('template_category_id' => $ebayListing->getAutoWebsiteAddingTemplateCategoryId(), 'template_other_category_id' => $ebayListing->getAutoWebsiteAddingTemplateOtherCategoryId()); $this->processAddedListingProduct($listingProduct, $params); }
private function getDataFromListing(\Ess\M2ePro\Model\Listing $source, array $params = array()) { $accountId = $source->getAccountId(); $marketplaceId = $source->getMarketplaceId(); $storeId = $source->getStoreId(); $attributeSets = $this->getHelper('Magento\\AttributeSet')->getAll(\Ess\M2ePro\Helper\Magento\AbstractHelper::RETURN_TYPE_IDS); $templates = array(); foreach ($this->templateManager->getAllTemplates() as $nick) { $manager = $this->templateManagerFactory->create()->setTemplate($nick)->setOwnerObject($source->getChildObject()); $templateId = $manager->getIdColumnValue(); $templateMode = $manager->getModeValue(); $templates[$nick] = array('id' => $templateId, 'mode' => $templateMode, 'force_parent' => false); } return array('account_id' => $accountId, 'marketplace_id' => $marketplaceId, 'store_id' => $storeId, 'attribute_sets' => $attributeSets, 'display_use_default_option' => false, 'templates' => $templates); }
/** * @param \Magento\Catalog\Model\Product $product * @param \Ess\M2ePro\Model\Listing $listing * @throws \Ess\M2ePro\Model\Exception\Logic */ public function addProductByWebsiteListing(\Magento\Catalog\Model\Product $product, \Ess\M2ePro\Model\Listing $listing) { $logData = array('reason' => __METHOD__); $listingProduct = $this->getListing()->addProduct($product, false, true, $logData); if (!$listingProduct instanceof \Ess\M2ePro\Model\Listing\Product) { return; } /** @var \Ess\M2ePro\Model\Amazon\Listing $amazonListing */ $amazonListing = $listing->getChildObject(); $params = array('template_description_id' => $amazonListing->getAutoWebsiteAddingDescriptionTemplateId()); $this->processAddedListingProduct($listingProduct, $params); }