Bulk.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Sync\Td;
  3. /**
  4. * Handle TD bulk data for importer.
  5. */
  6. class Bulk extends \Dotdigitalgroup\Email\Model\Sync\Contact\Bulk
  7. {
  8. /**
  9. * Sync.
  10. *
  11. * @param mixed $collection
  12. *
  13. * @return null
  14. */
  15. public function sync($collection)
  16. {
  17. foreach ($collection as $item) {
  18. $websiteId = $item->getWebsiteId();
  19. if ($this->helper->isEnabled($websiteId)) {
  20. $this->client = $this->helper->getWebsiteApiClient($websiteId);
  21. $importData = $this->serializer->unserialize($item->getImportData());
  22. if ($this->client) {
  23. if (strpos($item->getImportType(), 'Catalog_') !== false) {
  24. $result = $this->client->postAccountTransactionalDataImport(
  25. $importData,
  26. $item->getImportType()
  27. );
  28. } else {
  29. if ($item->getImportType() == \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS) {
  30. //Skip if one hour has not passed from created
  31. if ($this->helper->getDateDifference($item->getCreatedAt()) < 3600) {
  32. continue;
  33. }
  34. }
  35. $result = $this->client->postContactsTransactionalDataImport(
  36. $importData,
  37. $item->getImportType()
  38. );
  39. }
  40. $this->_handleItemAfterSync($item, $result);
  41. }
  42. }
  43. }
  44. }
  45. }