productQueue = $productQueue; $this->productQueueCollectionFactory = $productQueueCollectionFactory; $this->helper = $helper; $this->logger = $logger; $this->productsSync = $productsSync; $this->attributesSync = $attributesSync; $this->categoriesSync = $categoriesSync; $this->netSuiteAPI = $netSuiteAPI; $this->productMapper = $productMapper; } /** * Fetch data from NetSuite and add it to the queue. * * @return array */ public function fetch($pageSize = 50, $page = 1) { if ($this->helper->getMultiLocationEnabled()) { return $this->netSuiteAPI->fetchProductsWithLocation($pageSize, $page); } return $this->netSuiteAPI->fetchProducts($pageSize, $page); } /** * {@inheritdoc} */ public function getPageSize() { return $this->pageSize; } /** * Convert NetSuite data to Magento format * * @param array $data * @return array */ public function convertToMagentoFormat($data) { return $this->productMapper->convertToMagentoFormat($data); } /** * adds data to the queue. * * @param array $data * @return void */ public function enqueue($data) { foreach($data as $item) { $this->productQueue->insertOrUpdate($item); } } /** * Get next queue items to process * * @param int $batchSize * @return array */ public function dequeue($batchSize = 50) { return $this->productQueueCollectionFactory->create()->getNext($batchSize); } /** * Process queue item * * @param $queueItem * @return array */ public function processQueueItem($queueItem) { $data = $this->serializer->unserialize($queueItem->getData('data')); $configurableProductsData = null; // if (isset($data['Children'])) { // //Create or Update the simple products // foreach ($data['Children'] as $childData) { // if (!$product = $this->productsSync->createOrUpdate($childData, true)) { // continue; // } // if ($attributeData = $this->attributesSync->processAttributes($product, $childData)) { // $configurableProductsData[$product->getId()] = $attributeData; // } // } // } $categoryIds = $this->categoriesSync->getOrCreateCategoryIds($data); $product = $this->productsSync->createOrUpdate($data, false, $configurableProductsData, $categoryIds); // if (isset($product['data'])) { // $this->attributesSync->processAttributes($product['data'], $data); // } return $product; } }