vendor/shopware/core/Content/Product/ProductHydrator.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityHydrator;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
  7. use Shopware\Core\Framework\Log\Package;
  8. use Shopware\Core\Framework\Uuid\Uuid;
  9. #[Package('inventory')]
  10. class ProductHydrator extends EntityHydrator
  11. {
  12. /**
  13. * @param array<string, string> $row
  14. *
  15. * @throws \Exception
  16. */
  17. protected function assign(EntityDefinition $definition, Entity $entity, string $root, array $row, Context $context): Entity
  18. {
  19. if (isset($row[$root . '.id'])) {
  20. $entity->id = Uuid::fromBytesToHex($row[$root . '.id']);
  21. }
  22. if (isset($row[$root . '.versionId'])) {
  23. $entity->versionId = Uuid::fromBytesToHex($row[$root . '.versionId']);
  24. }
  25. if (isset($row[$root . '.parentId'])) {
  26. $entity->parentId = Uuid::fromBytesToHex($row[$root . '.parentId']);
  27. }
  28. if (isset($row[$root . '.manufacturerId'])) {
  29. $entity->manufacturerId = Uuid::fromBytesToHex($row[$root . '.manufacturerId']);
  30. }
  31. if (isset($row[$root . '.unitId'])) {
  32. $entity->unitId = Uuid::fromBytesToHex($row[$root . '.unitId']);
  33. }
  34. if (isset($row[$root . '.taxId'])) {
  35. $entity->taxId = Uuid::fromBytesToHex($row[$root . '.taxId']);
  36. }
  37. if (isset($row[$root . '.coverId'])) {
  38. $entity->coverId = Uuid::fromBytesToHex($row[$root . '.coverId']);
  39. }
  40. if (isset($row[$root . '.deliveryTimeId'])) {
  41. $entity->deliveryTimeId = Uuid::fromBytesToHex($row[$root . '.deliveryTimeId']);
  42. }
  43. if (isset($row[$root . '.featureSetId'])) {
  44. $entity->featureSetId = Uuid::fromBytesToHex($row[$root . '.featureSetId']);
  45. }
  46. if (isset($row[$root . '.canonicalProductId'])) {
  47. $entity->canonicalProductId = Uuid::fromBytesToHex($row[$root . '.canonicalProductId']);
  48. }
  49. if (isset($row[$root . '.cmsPageId'])) {
  50. $entity->cmsPageId = Uuid::fromBytesToHex($row[$root . '.cmsPageId']);
  51. }
  52. if (\array_key_exists($root . '.price', $row)) {
  53. $entity->price = $definition->decode('price', self::value($row, $root, 'price'));
  54. }
  55. if (isset($row[$root . '.productNumber'])) {
  56. $entity->productNumber = $row[$root . '.productNumber'];
  57. }
  58. if (isset($row[$root . '.stock'])) {
  59. $entity->stock = (int) $row[$root . '.stock'];
  60. }
  61. if (isset($row[$root . '.restockTime'])) {
  62. $entity->restockTime = (int) $row[$root . '.restockTime'];
  63. }
  64. if (isset($row[$root . '.autoIncrement'])) {
  65. $entity->autoIncrement = (int) $row[$root . '.autoIncrement'];
  66. }
  67. if (isset($row[$root . '.active'])) {
  68. $entity->active = (bool) $row[$root . '.active'];
  69. }
  70. if (isset($row[$root . '.availableStock'])) {
  71. $entity->availableStock = (int) $row[$root . '.availableStock'];
  72. }
  73. if (isset($row[$root . '.available'])) {
  74. $entity->available = (bool) $row[$root . '.available'];
  75. }
  76. if (isset($row[$root . '.isCloseout'])) {
  77. $entity->isCloseout = (bool) $row[$root . '.isCloseout'];
  78. }
  79. if (isset($row[$root . '.displayGroup'])) {
  80. $entity->displayGroup = $row[$root . '.displayGroup'];
  81. }
  82. if (isset($row[$root . '.states'])) {
  83. $entity->states = $definition->decode('states', self::value($row, $root, 'states'));
  84. }
  85. if (\array_key_exists($root . '.configuratorGroupConfig', $row)) {
  86. $entity->configuratorGroupConfig = $definition->decode('configuratorGroupConfig', self::value($row, $root, 'configuratorGroupConfig'));
  87. }
  88. if (isset($row[$root . '.mainVariantId'])) {
  89. $entity->mainVariantId = Uuid::fromBytesToHex($row[$root . '.mainVariantId']);
  90. }
  91. if (isset($row[$root . '.displayParent'])) {
  92. $entity->displayParent = (bool) $row[$root . '.displayParent'];
  93. }
  94. if (isset($row[$root . '.variantListingConfig'])) {
  95. $entity->variantListingConfig = $definition->decode('variantListingConfig', self::value($row, $root, 'variantListingConfig'));
  96. }
  97. if (\array_key_exists($root . '.variantRestrictions', $row)) {
  98. $entity->variantRestrictions = $definition->decode('variantRestrictions', self::value($row, $root, 'variantRestrictions'));
  99. }
  100. if (isset($row[$root . '.manufacturerNumber'])) {
  101. $entity->manufacturerNumber = $row[$root . '.manufacturerNumber'];
  102. }
  103. if (isset($row[$root . '.ean'])) {
  104. $entity->ean = $row[$root . '.ean'];
  105. }
  106. if (isset($row[$root . '.purchaseSteps'])) {
  107. $entity->purchaseSteps = (int) $row[$root . '.purchaseSteps'];
  108. }
  109. if (isset($row[$root . '.maxPurchase'])) {
  110. $entity->maxPurchase = (int) $row[$root . '.maxPurchase'];
  111. }
  112. if (isset($row[$root . '.minPurchase'])) {
  113. $entity->minPurchase = (int) $row[$root . '.minPurchase'];
  114. }
  115. if (isset($row[$root . '.purchaseUnit'])) {
  116. $entity->purchaseUnit = (float) $row[$root . '.purchaseUnit'];
  117. }
  118. if (isset($row[$root . '.referenceUnit'])) {
  119. $entity->referenceUnit = (float) $row[$root . '.referenceUnit'];
  120. }
  121. if (isset($row[$root . '.shippingFree'])) {
  122. $entity->shippingFree = (bool) $row[$root . '.shippingFree'];
  123. }
  124. if (\array_key_exists($root . '.purchasePrices', $row)) {
  125. $entity->purchasePrices = $definition->decode('purchasePrices', self::value($row, $root, 'purchasePrices'));
  126. }
  127. if (isset($row[$root . '.markAsTopseller'])) {
  128. $entity->markAsTopseller = (bool) $row[$root . '.markAsTopseller'];
  129. }
  130. if (isset($row[$root . '.weight'])) {
  131. $entity->weight = (float) $row[$root . '.weight'];
  132. }
  133. if (isset($row[$root . '.width'])) {
  134. $entity->width = (float) $row[$root . '.width'];
  135. }
  136. if (isset($row[$root . '.height'])) {
  137. $entity->height = (float) $row[$root . '.height'];
  138. }
  139. if (isset($row[$root . '.length'])) {
  140. $entity->length = (float) $row[$root . '.length'];
  141. }
  142. if (isset($row[$root . '.releaseDate'])) {
  143. $entity->releaseDate = new \DateTimeImmutable($row[$root . '.releaseDate']);
  144. }
  145. if (isset($row[$root . '.ratingAverage'])) {
  146. $entity->ratingAverage = (float) $row[$root . '.ratingAverage'];
  147. }
  148. if (\array_key_exists($root . '.categoryTree', $row)) {
  149. $entity->categoryTree = $definition->decode('categoryTree', self::value($row, $root, 'categoryTree'));
  150. }
  151. if (\array_key_exists($root . '.propertyIds', $row)) {
  152. $entity->propertyIds = $definition->decode('propertyIds', self::value($row, $root, 'propertyIds'));
  153. }
  154. if (\array_key_exists($root . '.optionIds', $row)) {
  155. $entity->optionIds = $definition->decode('optionIds', self::value($row, $root, 'optionIds'));
  156. }
  157. if (\array_key_exists($root . '.streamIds', $row)) {
  158. $entity->streamIds = $definition->decode('streamIds', self::value($row, $root, 'streamIds'));
  159. }
  160. if (\array_key_exists($root . '.tagIds', $row)) {
  161. $entity->tagIds = $definition->decode('tagIds', self::value($row, $root, 'tagIds'));
  162. }
  163. if (\array_key_exists($root . '.categoryIds', $row)) {
  164. $entity->categoryIds = $definition->decode('categoryIds', self::value($row, $root, 'categoryIds'));
  165. }
  166. if (isset($row[$root . '.childCount'])) {
  167. $entity->childCount = (int) $row[$root . '.childCount'];
  168. }
  169. if (isset($row[$root . '.customFieldSetSelectionActive'])) {
  170. $entity->customFieldSetSelectionActive = (bool) $row[$root . '.customFieldSetSelectionActive'];
  171. }
  172. if (isset($row[$root . '.sales'])) {
  173. $entity->sales = (int) $row[$root . '.sales'];
  174. }
  175. if (\array_key_exists($root . '.cheapestPrice', $row)) {
  176. $entity->cheapestPrice = $definition->decode('cheapestPrice', self::value($row, $root, 'cheapestPrice'));
  177. }
  178. if (isset($row[$root . '.createdAt'])) {
  179. $entity->createdAt = new \DateTimeImmutable($row[$root . '.createdAt']);
  180. }
  181. if (isset($row[$root . '.updatedAt'])) {
  182. $entity->updatedAt = new \DateTimeImmutable($row[$root . '.updatedAt']);
  183. }
  184. $entity->deliveryTime = $this->manyToOne($row, $root, $definition->getField('deliveryTime'), $context);
  185. $entity->tax = $this->manyToOne($row, $root, $definition->getField('tax'), $context);
  186. $entity->manufacturer = $this->manyToOne($row, $root, $definition->getField('manufacturer'), $context);
  187. $entity->unit = $this->manyToOne($row, $root, $definition->getField('unit'), $context);
  188. $entity->cover = $this->manyToOne($row, $root, $definition->getField('cover'), $context);
  189. $entity->featureSet = $this->manyToOne($row, $root, $definition->getField('featureSet'), $context);
  190. $entity->cmsPage = $this->manyToOne($row, $root, $definition->getField('cmsPage'), $context);
  191. $entity->canonicalProduct = $this->manyToOne($row, $root, $definition->getField('canonicalProduct'), $context);
  192. $this->translate($definition, $entity, $row, $root, $context, $definition->getTranslatedFields());
  193. $this->hydrateFields($definition, $entity, $root, $row, $context, $definition->getExtensionFields());
  194. $this->customFields($definition, $row, $root, $entity, $definition->getField('customFields'), $context);
  195. $this->manyToMany($row, $root, $entity, $definition->getField('options'));
  196. $this->manyToMany($row, $root, $entity, $definition->getField('properties'));
  197. $this->manyToMany($row, $root, $entity, $definition->getField('categories'));
  198. $this->manyToMany($row, $root, $entity, $definition->getField('streams'));
  199. $this->manyToMany($row, $root, $entity, $definition->getField('categoriesRo'));
  200. $this->manyToMany($row, $root, $entity, $definition->getField('tags'));
  201. $this->manyToMany($row, $root, $entity, $definition->getField('customFieldSets'));
  202. return $entity;
  203. }
  204. }