Data.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\DownloadableImportExport\Helper;
  7. use Magento\DownloadableImportExport\Model\Import\Product\Type\Downloadable;
  8. /**
  9. * Class Data
  10. */
  11. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  12. {
  13. /**
  14. * Check whether the row is valid.
  15. *
  16. * @param array $rowData
  17. * @return bool
  18. */
  19. public function isRowDownloadableEmptyOptions(array $rowData)
  20. {
  21. $result = isset($rowData[Downloadable::COL_DOWNLOADABLE_LINKS])
  22. && $rowData[Downloadable::COL_DOWNLOADABLE_LINKS] == ''
  23. && isset($rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES])
  24. && $rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES] == '';
  25. return $result;
  26. }
  27. /**
  28. * Check whether the row is valid.
  29. *
  30. * @param array $rowData
  31. * @return bool
  32. */
  33. public function isRowDownloadableNoValid(array $rowData)
  34. {
  35. $result = isset($rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES]) ||
  36. isset($rowData[Downloadable::COL_DOWNLOADABLE_LINKS]);
  37. return $result;
  38. }
  39. /**
  40. * Fill exist options
  41. *
  42. * @param array $base
  43. * @param array $option
  44. * @param array $existingOptions
  45. * @return array
  46. */
  47. public function fillExistOptions(array $base, array $option, array $existingOptions)
  48. {
  49. $result = [];
  50. foreach ($existingOptions as $existingOption) {
  51. if ($option['link_url'] == $existingOption['link_url']
  52. && $option['link_file'] == $existingOption['link_file']
  53. && $option['link_type'] == $existingOption['link_type']
  54. && $option['sample_url'] == $existingOption['sample_url']
  55. && $option['sample_file'] == $existingOption['sample_file']
  56. && $option['sample_type'] == $existingOption['sample_type']
  57. && $option['product_id'] == $existingOption['product_id']) {
  58. $result = array_replace($base, $option, $existingOption);
  59. }
  60. }
  61. return $result;
  62. }
  63. /**
  64. * Fill array data options for base entity
  65. *
  66. * @param array $base
  67. * @param array $replacement
  68. * @return array
  69. */
  70. public function prepareDataForSave(array $base, array $replacement)
  71. {
  72. $result = [];
  73. foreach ($replacement as $item) {
  74. $result[] = array_intersect_key($item, $base);
  75. }
  76. return $result;
  77. }
  78. /**
  79. * Get type parameters - file or url
  80. *
  81. * @param string $option
  82. * @return string
  83. */
  84. public function getTypeByValue($option)
  85. {
  86. $result = Downloadable::FILE_OPTION_VALUE;
  87. if (preg_match('/\bhttps?:\/\//i', $option)) {
  88. $result = Downloadable::URL_OPTION_VALUE;
  89. }
  90. return $result;
  91. }
  92. }