registry->registry('current_product'); return $product instanceof Product ? $product : null; } public function canRender(): bool { $product = $this->getProduct(); return $product && $product->getTypeId() === Configurable::TYPE_CODE; } public function getCountryOptions(): array { return $this->countryCollectionFactory->create()->loadByStore()->toOptionArray(false); } public function getJsonConfig(): string { $parent = $this->getProduct(); if (!$parent || !$this->canRender()) { return '{}'; } $children = []; $website = $this->storeManager->getStore()->getWebsite(); foreach ($parent->getTypeInstance()->getUsedProducts($parent) as $child) { if ((int)$child->getStatus() !== Status::STATUS_ENABLED) { continue; } $availability = $this->availabilityResolver->resolve($child, $website); $optionLabels = []; foreach ($parent->getTypeInstance()->getConfigurableAttributes($parent) as $configurableAttribute) { $attribute = $configurableAttribute->getProductAttribute(); $text = $child->getAttributeText((string)$attribute->getAttributeCode()); $optionLabels[] = [ 'label' => (string)$attribute->getStoreLabel(), 'value' => is_array($text) ? implode(', ', $text) : (string)$text, ]; } $children[(string)$child->getId()] = [ 'id' => (int)$child->getId(), 'sku' => (string)$child->getSku(), 'name' => (string)$child->getName(), 'options' => $optionLabels, 'requiresInquiry' => (bool)$availability['requires_inquiry'], 'availabilityReason' => (string)$availability['reason'], ]; } return $this->json->serialize([ 'parentId' => (int)$parent->getId(), 'parentName' => (string)$parent->getName(), 'children' => $children, 'submitUrl' => $this->getUrl('product-inquiry/index/post'), ]); } }