Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * {@inheritDoc}
- * @see IotaEShoppingApiStoreManagementInterface::getOptionsOfConfigurationProduct()
- */
- public function getOptionsOfConfigurationProduct($productId) {
- $product = $this->productFactory->create()->load($productId);
- $extensionAttributes = $product->getExtensionAttributes();
- $configurableProductOptions = $extensionAttributes->getConfigurableProductOptions();
- $options = $product->getOptions();
- $childProduct = $product->getTypeInstance()->getUsedProducts($product);
- $productAttributeOptions = array();
- foreach ($configurableProductOptions as $option) {
- $optionValues = array();
- foreach ($option->getValues() as $optionValue) {
- $optionValues[] = $optionValue->getData();
- }
- $children = array();
- foreach ($childProduct as $child) {
- $children[] = $child->getData();
- }
- $productAttributeOptionArray = $option->getData();
- $productAttributeOptionArray['values'] = $optionValues;
- $productAttributeOptionArray['child'] = $children ;
- $productAttributeOptions[] = $productAttributeOptionArray;
- }
- $productOptions = array();
- foreach ($options as $option) {
- $optionValue = array();
- foreach ($option->getValues() as $value) {
- $optionValue[] = $value->getData();
- }
- $productOptionArray = $option->getData();
- $productOptionArray['values'] = $optionValue;
- $productOptions[] = $productOptionArray;
- }
- $result = array(
- 'extension_attributes' => array('configurable_product_options' => $productAttributeOptions),
- 'options' => $productOptions
- );
- return [$result];
- }
- [
- {
- "extension_attributes": {
- "configurable_product_options": [
- {
- "product_super_attribute_id": "160",
- "product_id": "962",
- "attribute_id": "141",
- "position": "0",
- "product_attribute": {},
- "label": "Size",
- "use_default": "0",
- "options": [
- {
- "value_index": "5",
- "label": "S",
- "product_super_attribute_id": "160",
- "default_label": "S",
- "store_label": "S",
- "use_default_value": true
- },
- {
- "value_index": "6",
- "label": "M",
- "product_super_attribute_id": "160",
- "default_label": "M",
- "store_label": "M",
- "use_default_value": true
- }
- ],
- "values": [
- {
- "value_index": "5"
- },
- {
- "value_index": "6"
- }
- ],
- "child": [
- {
- "entity_id": "960",
- "attribute_set_id": "4",
- "type_id": "simple",
- "sku": "Food With Option 1-S",
- "has_options": "0",
- "required_options": "0",
- "created_at": "2018-06-05 09:40:24",
- "updated_at": "2018-06-05 09:40:24",
- "parent_id": "962",
- "catalog_rule_price": null,
- "name": "Food With Option 1-S",
- "url_key": "food-with-option-1-s",
- "status": "1",
- "tax_class_id": "0",
- "koi_size": "5",
- "price": "1.0000",
- "weight": "1.0000",
- "media_gallery": {
- "images": [],
- "values": []
- },
- "tier_price": [],
- "tier_price_changed": 0
- },
- {
- "entity_id": "961",
- "attribute_set_id": "4",
- "type_id": "simple",
- "sku": "Food With Option 1-M",
- "has_options": "0",
- "required_options": "0",
- "created_at": "2018-06-05 09:40:25",
- "updated_at": "2018-06-05 09:40:25",
- "parent_id": "962",
- "catalog_rule_price": null,
- "name": "Food With Option 1-M",
- "url_key": "food-with-option-1-m",
- "status": "1",
- "tax_class_id": "0",
- "koi_size": "6",
- "price": "1.0000",
- "weight": "1.0000",
- "media_gallery": {
- "images": [],
- "values": []
- },
- "tier_price": [],
- "tier_price_changed": 0
- }
- ]
- }
- ]
- },
- "options": []
- }
- ]
Add Comment
Please, Sign In to add comment