/** * Prepare data for configurable product. * * @param ConfigurableProduct $product * @return array */ protected function prepareConfigurableData(ConfigurableProduct $product) { $result = []; $checkoutData = $product->getCheckoutData(); $result['qty'] = $checkoutData['qty']; $attributesData = $product->hasData('configurable_attributes_data') ? $product->getDataFieldConfig('configurable_attributes_data')['source']->getAttributesData() : null; if ($attributesData == null) { return $result; } foreach ($checkoutData['options']['configurable_options'] as $option) { $attributeId = $attributesData[$option['title']]['attribute_id']; $optionId = $attributesData[$option['title']]['options'][$option['value']]['id']; $result['super_attribute'][$attributeId] = $optionId; } return $result; }
/** * Prepare configurable product options. * * @param ConfigurableProduct $product * @return array */ protected function prepareConfigurableOptions(ConfigurableProduct $product) { $options = []; $attributesData = $product->getDataFieldConfig('configurable_attributes_data')['source']->getAttributesData(); foreach ($product->getCheckoutData()['options']['configurable_options'] as $checkoutOption) { $options[] = ['option_id' => $attributesData[$checkoutOption['title']]['attribute_id'], 'option_value' => $attributesData[$checkoutOption['title']]['options'][$checkoutOption['value']]['id']]; } return ['extension_attributes' => ['configurable_item_options' => $options]]; }