private function prepareDataByCategories() { $listingProductsIds = $this->listing->getSetting('additional_data', 'adding_new_asin_listing_products_ids'); $listingProductCollection = $this->amazonFactory->getObject('Listing\\Product')->getCollection()->addFieldToFilter('id', array('in' => $listingProductsIds)); $productsIds = array(); $descriptionTemplatesIds = array(); foreach ($listingProductCollection->getData() as $item) { $productsIds[$item['id']] = $item['product_id']; $descriptionTemplatesIds[$item['id']] = $item['template_description_id']; } $productsIds = array_unique($productsIds); $categoriesIds = $this->getHelper('Magento\\Category')->getLimitedCategoriesByProducts($productsIds, $this->listing->getStoreId()); $categoriesData = array(); foreach ($categoriesIds as $categoryId) { $collection = $this->productFactory->create()->getCollection(); $collection->addFieldToFilter('entity_id', array('in' => $productsIds)); $collection->joinTable(array('ccp' => $this->resourceConnection->getTableName('catalog_category_product')), 'product_id=entity_id', array('category_id' => 'category_id')); $collection->addFieldToFilter('category_id', $categoryId); $data = $collection->getData(); foreach ($data as $item) { $categoriesData[$categoryId][] = array_search($item['entity_id'], $productsIds); } $categoriesData[$categoryId] = array_unique($categoriesData[$categoryId]); } $this->setData('categories_data', $categoriesData); $this->setData('description_templates_data', $descriptionTemplatesIds); $this->listing->setSetting('additional_data', 'adding_new_asin_description_templates_data', $descriptionTemplatesIds); $this->listing->save(); }
protected function renderStoreCategoryInfo($title, $data, $key) { $info = ''; if ($data[$key . '_mode'] == \Ess\M2ePro\Model\Ebay\Template\Category::CATEGORY_MODE_EBAY) { $info = $data[$key . '_path']; $info .= ' (' . $data[$key . '_id'] . ')'; } elseif ($data[$key . '_mode'] == \Ess\M2ePro\Model\Ebay\Template\Category::CATEGORY_MODE_ATTRIBUTE) { $info = $this->__('Magento Attribute > %attribute_label%', $this->getHelper('Magento\\Attribute')->getAttributeLabel($data[$key . '_attribute'], $this->listing->getStoreId())); } return $this->renderCategoryInfo($title, $info); }
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); }
public function fillCategoriesPaths(array &$data, \Ess\M2ePro\Model\Listing $listing) { $ebayCategoryHelper = $this->getHelper('Component\\Ebay\\Category\\Ebay'); $ebayStoreCategoryHelper = $this->getHelper('Component\\Ebay\\Category\\Store'); $temp = array('category_main' => array('call' => array($ebayCategoryHelper, 'getPath'), 'arg' => $listing->getMarketplaceId()), 'category_secondary' => array('call' => array($ebayCategoryHelper, 'getPath'), 'arg' => $listing->getMarketplaceId()), 'store_category_main' => array('call' => array($ebayStoreCategoryHelper, 'getPath'), 'arg' => $listing->getAccountId()), 'store_category_secondary' => array('call' => array($ebayStoreCategoryHelper, 'getPath'), 'arg' => $listing->getAccountId())); foreach ($temp as $key => $value) { if (!isset($data[$key . '_mode']) || !empty($data[$key . '_path'])) { continue; } if ($data[$key . '_mode'] == \Ess\M2ePro\Model\Ebay\Template\Category::CATEGORY_MODE_EBAY) { $data[$key . '_path'] = call_user_func($value['call'], $data[$key . '_id'], $value['arg']); } if ($data[$key . '_mode'] == \Ess\M2ePro\Model\Ebay\Template\Category::CATEGORY_MODE_ATTRIBUTE) { $attributeLabel = $this->getHelper('Magento\\Attribute')->getAttributeLabel($data[$key . '_attribute'], $listing->getStoreId()); $data[$key . '_path'] = 'Magento Attribute' . ' > ' . $attributeLabel; } } }
protected function _getStore() { return $this->_storeManager->getStore((int) $this->listing->getStoreId()); }