namespace Nailalliance\Masterkey\Block; class ProductInfo extends \Magento\Framework\View\Element\Template { protected $_registry; protected $_productRepository; protected $_storeManager; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, array $data = [] ) { $this->_registry = $registry; $this->_productRepository = $productRepository; $this->_storeManager = $context->getStoreManager(); parent::__construct($context, $data); } public function getCurrentProduct() { return $this->_registry->registry('current_product'); } public function getStoreBaseUrl() { return $this->_storeManager->getStore()->getBaseUrl(); } public function getProductData() { $product = $this->getCurrentProduct(); if (!$product) { return '{}'; } // Collect related product SKUs $relatedSkus = []; $relatedProducts = $product->getRelatedProducts(); foreach ($relatedProducts as $related) { $relatedSkus[] = $related->getSku(); } // Get image URLs for each SKU $mainProductImages = [$product->getImageUrl()]; $thumbnailImages = []; foreach ($relatedProducts as $related) { $thumbnailImages[] = $related->getThumbnailUrl(); } $data = [ 'domain_name' => $this->getStoreBaseUrl(), 'master_sku' => $product->getSku(), 'related_skus' => $relatedSkus, 'gel' => $product->getCustomAttribute('gel') ? $product->getCustomAttribute('gel')->getValue() : '', 'lacquer' => $product->getCustomAttribute('lacquer') ? $product->getCustomAttribute('lacquer')->getValue() : '', 'dip' => $product->getCustomAttribute('dip') ? $product->getCustomAttribute('dip')->getValue() : '', 'main_product_images' => $mainProductImages, 'image_alt_texts' => [$product->getName()], 'product_title' => $product->getName(), 'product_description' => $product->getDescription(), 'thumbnail_images' => $thumbnailImages ]; return json_encode($data); } public function getJsonProductData() { $product = $this->getCurrentProduct(); if (!$product) { return '{}'; } $data = [ 'ProductName' => $product->getName(), 'ProductID' => $product->getId(), 'SKU' => $product->getSku(), 'Categories' => $product->getCategoryIds(), 'ImageURL' => $product->getImageUrl(), 'URL' => $product->getProductUrl(), 'Brand' => "Gelish and Morgan Taylor", 'Price' => $product->getPrice(), 'CompareAtPrice' => $product->getFinalPrice() ]; return json_encode($data); } } An error has happened during application run. See exception log for details.