/** * Execute command * * @param array $productIds * @return void */ public function execute($productIds = []) { $collection = $this->_productResource->getProducts($productIds, self::CHUNK_SIZE); $this->out('Preparing export of %d products to recommender system...', [$collection->getSize()]); $curPage = $collection->getCurPage(); while ($curPage <= $collection->getLastPageNumber()) { foreach ($collection as $product) { $this->_client->postEvent(new Event(Save::EVENT_SUBJECT, $this->_productBuilder->create($product))); } $this->out('%d of %d chunks exported...', [$curPage, $collection->getLastPageNumber()]); $collection->setCurPage(++$curPage); } $this->out('%d products exported to recommender', [$collection->getSize()]); }
/** * Builds event body for API * @param \Magento\Framework\Event $event * @return \Koklu\Event\Model\Event */ public function buildEventBody(\Magento\Framework\Event $event) { $product = $this->_productResource->getProduct($event->getProduct()->getId(), false); // we do not need to send an event if product is disabled or invisible $allowedVisibility = [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]; if ($product->getStatus() != Status::STATUS_ENABLED || !in_array($product->getVisibility(), $allowedVisibility)) { // however if the changes involved status or visibility, then we need to send a delete event // if ($event->getProduct()->dataHasChangedFor('status') // || $event->getProduct()->dataHasChangedFor('visibility') // ) { $this->_eventManager->dispatch('koklu_masterdata_not_salable_product_save', ['product' => $product]); // } return null; } return new Event(self::EVENT_SUBJECT, $this->_productBuilder->create($product)); }