/** * Delete piece of transactional data by key. * * @param int $key */ public function deleteFromAccount($key) { $apiEnabled = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_API_ENABLED); $catalogEnabled = $this->helper->isCatalogSyncEnabled(); if ($apiEnabled && $catalogEnabled) { $scope = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES); if ($scope == 1) { //register in queue with importer $this->importerFactory->create()->registerQueue('Catalog_Default', [$key], \Dotdigitalgroup\Email\Model\Importer::MODE_SINGLE_DELETE, \Magento\Store\Model\Store::DEFAULT_STORE_ID); } if ($scope == 2) { $stores = $this->storeManager->getStores(); foreach ($stores as $store) { $websiteCode = $store->getWebsite()->getCode(); $storeCode = $store->getCode(); //register in queue with importer $this->importerFactory->create()->registerQueue('Catalog_' . $websiteCode . '_' . $storeCode, [$key], \Dotdigitalgroup\Email\Model\Importer::MODE_SINGLE_DELETE, $store->getWebsite()->getId()); } } } }
/** * Catalog sync. * * @return array */ public function sync() { $response = ['success' => true, 'message' => 'Done.']; $this->start = microtime(true); $enabled = $this->helper->isEnabled(); $catalogSyncEnabled = $this->helper->isCatalogSyncEnabled(); //api and catalog sync enabled if ($enabled && $catalogSyncEnabled) { try { //remove product with product id set and no product $write = $this->resource->getConnection('core_write'); $catalogTable = $this->resource->getTableName('email_catalog'); $select = $write->select(); $select->reset()->from(['c' => $catalogTable], ['c.product_id'])->joinLeft(['e' => $this->resource->getTableName('catalog_product_entity')], 'c.product_id = e.entity_id')->where('e.entity_id is NULL'); //delete sql statement $deleteSql = $select->deleteFromSelect('c'); //run query $write->query($deleteSql); $scope = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES); //if only to pull default value if ($scope == 1) { $products = $this->_exportCatalog(\Magento\Store\Model\Store::DEFAULT_STORE_ID); if ($products) { //register in queue with importer $this->importerFactory->create()->registerQueue('Catalog_Default', $products, \Dotdigitalgroup\Email\Model\Importer::MODE_BULK, \Magento\Store\Model\Store::DEFAULT_STORE_ID); //set imported $this->_setImported($this->productIds); //set number of product imported $this->countProducts += count($products); } //using single api $this->_exportInSingle(\Magento\Store\Model\Store::DEFAULT_STORE_ID, 'Catalog_Default', \Magento\Store\Model\Store::DEFAULT_STORE_ID); //if to pull store values. will be pulled for each store } elseif ($scope == 2) { $stores = $this->helper->getStores(); foreach ($stores as $store) { $websiteCode = $store->getWebsite()->getCode(); $storeCode = $store->getCode(); $products = $this->_exportCatalog($store); if ($products) { //register in queue with importer $this->importerFactory->create()->registerQueue('Catalog_' . $websiteCode . '_' . $storeCode, $products, \Dotdigitalgroup\Email\Model\Importer::MODE_BULK, $store->getWebsite()->getId()); //set imported $this->_setImported($this->productIds); //set number of product imported //@codingStandardsIgnoreStart $this->countProducts += count($products); //@codingStandardsIgnoreEnd } //using single api $this->_exportInSingle($store, 'Catalog_' . $websiteCode . '_' . $storeCode, $store->getWebsite()->getId()); } } } catch (\Exception $e) { $this->helper->debug((string) $e, []); } } if ($this->countProducts) { $message = 'Total time for sync : ' . gmdate('H:i:s', microtime(true) - $this->start) . ', Total synced = ' . $this->countProducts; $this->helper->log($message); $response['message'] = $message; } return $response; }