MAGENTO2
-
magento 2 how to check if module is enabled or disabled in phtml file
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$moduleManager = $objectManager->get(‘\Magento\Framework\Module\Manager’);
$xme = $moduleManager->isEnabled(‘Sparsh_AutoRelatedProducts’);
if( $xme==1){
echo “module enable”;
}
-
Get the product count by attribute(swatches) in filter option in magento 2
\Magento\Swatches\Block\LayeredNavigation\RenderLayered::getOptionViewData
return [
‘label’ => $swatchOption->getLabel(),
‘link’ => $linkToOption,
‘custom_style’ => $customStyle,
‘count’ => $filterItem->getCount()
];
Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml
<?php foreach ($swatchData[‘options’] as $option => $label): ?>
<?php if(isset($label[‘count’])) {echo $label[‘count’];} ?>
-
Get product price and currency symbol in phtml page magento2 from product id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); $b= 1234; $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); $regularPrice= $productd->getPrice(); $specialPrice = $productd->getFinalPrice(); <?php echo $priceHelper->currency($specialPrice, true, false) ?> // code for currency with special price
-
How to get product url from product id magento 2
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository'); $b= 1232; // the product id $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); $sku = $productd->getSku();// getting Sku $productData = $productRepository->get($sku); <a href="<?php echo $productData->getProductUrl(); ?>"> Show product </a>
-
How to show product image from product id in phtml page magento 2
The following code will show the product image from given product id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $b=1232; // product id $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); <div class="product-image"> <img src="<?php echo $productd->getMediaConfig()->getMediaUrl($productd->getImage()); ?>" > </div>
-
How to get the SKU of product in phtml magento2 from given product Id.
Through the help of Object Manager we can get SKU of the product if we have product id.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository'); $b; $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); // product id $sku = $productd->getSku();
-
How to call static block in phtml magento2?
to call a static block content in an phtml page , the below code is done in the phtml
$this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('flashdeal')->toHtml();
-
Magento 4.2 Installation error
In ErrorHandler.php line 61:
Warning: file_put_contents(C:/xampp/htdocs/two42/generated/metadata/primary|global|plugin-list.php): failed to open stream: No such file or directory in C:\xampp\htdocs\two42\vendor\magento\framework\Interc
eption\PluginListGenerator.php on line 414C:\xampp\htdocs\two42\vendor\magento\framework\Interception\PluginListGenerator.php
$cacheId = implode(‘|’, $this->scopePriorityScheme) . “|” . $this->cacheId;
change pipe to hyphen
$cacheId = implode(‘-‘, $this->scopePriorityScheme) . “-” . $this->cacheId; -
Magento Installation and error while installing in xampp.
Installation magento after downloading its file and placing its unzipped file in htdocs folder
code for installation CMD (command line) after
php bin/magento setup:install –base-url=http://localhost/om/ –db-host=localhost –db-name=om –db-user=root –db-password= –admin-firstname=Admin –admin-lastname=Admin –admin-email=admin@test.com –admin-user=admin –admin-password=q1234567 –backend-frontname=admin –language=en_US –currency=USD –timezone=Europe/Kiev –use-rewrites=1
Locale’ not found in C:\xampp\htdocs\om\vendor\magento\framework\Locale\Bundle\DataBundle.php:64
Solution for PHP Fatal Error Class ‘locale’ Not Found in Magento 2:
Open file and find the line ;extension=php_intl.dll or ;extension=intl.
Remove (;) from there and save the file.
Restart Xampp or Wamp server and refresh the installation page.
That’s it.
Missing following extensions: ‘sockets’
go to php.ini and remove ; from the below statements.
extension=xsl
extension=soap
extension=sockets
Could not validate a connection to Elasticsearch. No alive nodes found in your cluster
go to elasticsearch /bin/elasticsearch.bat
and open localhost:9200 in browser.
This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP
go to php.ini in xampp and uncomment : extension=sodium
-
Error in localhost server Xampp
Deprecated: Method ReflectionParameter::getClass() is deprecated in C:\xampp\htdocs\xyz\vendor\magento\framework\Code\Reader\ClassReader.php on line 36
This error is due to Magento 2 does not support PHP 8 , in that case please install lower version of xampp.