Guest User

Untitled

a guest
Jun 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. /**
  2. *
  3. * {@inheritDoc}
  4. * @see IotaEShoppingApiStoreManagementInterface::getOptionsOfConfigurationProduct()
  5. */
  6. public function getOptionsOfConfigurationProduct($productId) {
  7. $product = $this->productFactory->create()->load($productId);
  8. $extensionAttributes = $product->getExtensionAttributes();
  9. $configurableProductOptions = $extensionAttributes->getConfigurableProductOptions();
  10. $options = $product->getOptions();
  11. $childProduct = $product->getTypeInstance()->getUsedProducts($product);
  12. $productAttributeOptions = array();
  13. foreach ($configurableProductOptions as $option) {
  14. $optionValues = array();
  15. foreach ($option->getValues() as $optionValue) {
  16. $optionValues[] = $optionValue->getData();
  17. }
  18. $children = array();
  19. foreach ($childProduct as $child) {
  20. $children[] = $child->getData();
  21. }
  22. $productAttributeOptionArray = $option->getData();
  23. $productAttributeOptionArray['values'] = $optionValues;
  24. $productAttributeOptionArray['child'] = $children ;
  25. $productAttributeOptions[] = $productAttributeOptionArray;
  26. }
  27.  
  28. $productOptions = array();
  29. foreach ($options as $option) {
  30. $optionValue = array();
  31. foreach ($option->getValues() as $value) {
  32. $optionValue[] = $value->getData();
  33. }
  34. $productOptionArray = $option->getData();
  35. $productOptionArray['values'] = $optionValue;
  36. $productOptions[] = $productOptionArray;
  37. }
  38.  
  39. $result = array(
  40. 'extension_attributes' => array('configurable_product_options' => $productAttributeOptions),
  41. 'options' => $productOptions
  42. );
  43. return [$result];
  44. }
  45.  
  46. [
  47. {
  48. "extension_attributes": {
  49. "configurable_product_options": [
  50. {
  51. "product_super_attribute_id": "160",
  52. "product_id": "962",
  53. "attribute_id": "141",
  54. "position": "0",
  55. "product_attribute": {},
  56. "label": "Size",
  57. "use_default": "0",
  58. "options": [
  59. {
  60. "value_index": "5",
  61. "label": "S",
  62. "product_super_attribute_id": "160",
  63. "default_label": "S",
  64. "store_label": "S",
  65. "use_default_value": true
  66. },
  67. {
  68. "value_index": "6",
  69. "label": "M",
  70. "product_super_attribute_id": "160",
  71. "default_label": "M",
  72. "store_label": "M",
  73. "use_default_value": true
  74. }
  75. ],
  76. "values": [
  77. {
  78. "value_index": "5"
  79. },
  80. {
  81. "value_index": "6"
  82. }
  83. ],
  84. "child": [
  85. {
  86. "entity_id": "960",
  87. "attribute_set_id": "4",
  88. "type_id": "simple",
  89. "sku": "Food With Option 1-S",
  90. "has_options": "0",
  91. "required_options": "0",
  92. "created_at": "2018-06-05 09:40:24",
  93. "updated_at": "2018-06-05 09:40:24",
  94. "parent_id": "962",
  95. "catalog_rule_price": null,
  96. "name": "Food With Option 1-S",
  97. "url_key": "food-with-option-1-s",
  98. "status": "1",
  99. "tax_class_id": "0",
  100. "koi_size": "5",
  101. "price": "1.0000",
  102. "weight": "1.0000",
  103. "media_gallery": {
  104. "images": [],
  105. "values": []
  106. },
  107. "tier_price": [],
  108. "tier_price_changed": 0
  109. },
  110. {
  111. "entity_id": "961",
  112. "attribute_set_id": "4",
  113. "type_id": "simple",
  114. "sku": "Food With Option 1-M",
  115. "has_options": "0",
  116. "required_options": "0",
  117. "created_at": "2018-06-05 09:40:25",
  118. "updated_at": "2018-06-05 09:40:25",
  119. "parent_id": "962",
  120. "catalog_rule_price": null,
  121. "name": "Food With Option 1-M",
  122. "url_key": "food-with-option-1-m",
  123. "status": "1",
  124. "tax_class_id": "0",
  125. "koi_size": "6",
  126. "price": "1.0000",
  127. "weight": "1.0000",
  128. "media_gallery": {
  129. "images": [],
  130. "values": []
  131. },
  132. "tier_price": [],
  133. "tier_price_changed": 0
  134. }
  135. ]
  136. }
  137. ]
  138. },
  139. "options": []
  140. }
  141. ]
Add Comment
Please, Sign In to add comment