- /**
- * Composes configuration for js
- *
- * @return string
- */
- public function getJsonConfig()
- {
- $store = $this->getCurrentStore();
- $currentProduct = $this->getProduct();
-
- $regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price');
- $finalPrice = $currentProduct->getPriceInfo()->getPrice('final_price');
-
- $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());
- $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);
-
- $config = [
- 'attributes' => $attributesData['attributes'],
- 'template' => str_replace('%s', '<%- data.price %>', $store->getCurrentCurrency()->getOutputFormat()),
- 'optionPrices' => $this->getOptionPrices(),
- 'prices' => [
- 'oldPrice' => [
- 'amount' => $this->_registerJsPrice($regularPrice->getAmount()->getValue()),
- ],
- 'basePrice' => [
- 'amount' => $this->_registerJsPrice(
- $finalPrice->getAmount()->getBaseAmount()
- ),
- ],
- 'finalPrice' => [
- 'amount' => $this->_registerJsPrice($finalPrice->getAmount()->getValue()),
- ],
- ],
- 'productId' => $currentProduct->getId(),
- 'chooseText' => __('Choose an Option...'),
- 'images' => isset($options['images']) ? $options['images'] : [],
- 'index' => isset($options['index']) ? $options['index'] : [],
- ];
-
- if ($currentProduct->hasPreconfiguredValues() && !empty($attributesData['defaultValues'])) {
- $config['defaultValues'] = $attributesData['defaultValues'];
- }
-
- $config = array_merge($config, $this->_getAdditionalConfig());
-
- return $this->jsonEncoder->encode($config);
- }