VendorName/ModuleName/etc/frontend/di.xml
<?xml version="1.0"?>
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="vendor_configurable_product_configurable" type="VendorName\ModuleName\Block\ConfigurableProduct\Product\View\Type\Configurable" sortOrder="1"/>
</type>
</config>
namespace VendorName\Module\Block\ConfigurableProduct\Product\View\Type;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Json\DecoderInterface;
class Configurable
{
protected $jsonEncoder;
protected $jsonDecoder;
public function __construct(
EncoderInterface $jsonEncoder,
DecoderInterface $jsonDecoder
) {
$this->jsonDecoder = $jsonDecoder;
$this->jsonEncoder = $jsonEncoder;
}
public function aroundGetJsonConfig(
\Magento\ConfigurableProduct\Block\Product\View\Type\Configurable $subject,
\Closure $proceed
)
{
$config = $proceed();
$config = $this->jsonDecoder->decode($config);
$config['url'] = 'sample_url';
return $this->jsonEncoder->encode($config);
}
}
You can use after plugin following way:
namespace VendorName\Module\Block\ConfigurableProduct\Product\View\Type;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Json\DecoderInterface;
class Configurable
{
protected $jsonEncoder;
protected $jsonDecoder;
public function __construct(
EncoderInterface $jsonEncoder,
DecoderInterface $jsonDecoder
) {
$this->jsonDecoder = $jsonDecoder;
$this->jsonEncoder = $jsonEncoder;
}
public function afterGetJsonConfig(
\Magento\ConfigurableProduct\Block\Product\View\Type\Configurable $subject,
$config
)
{
$config = $this->jsonDecoder->decode($config);
$config['url'] = 'sample_url';
return $this->jsonEncoder->encode($config);
}
}