-
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();
-
How to play youtube on pop up on click of image
The sample
The code
<style> .col-xs-12.partitle { text-align: center; padding: 38px; font-size: 28px; text-transform: uppercase; font-family: 'Spartan'; } .trailer{margin-top:20px;margin-left:20px;margin-right:20px;padding:20px;} .trailer .title{ font-size:14px;font-family: 'Spartan'; font-weight:bold; margin-top:20px; } .trailer .titled{ font-size:12px;font-family: 'Spartan'; font-weight:normal; } .lifeunderpar .banner{background:#222;position:relative;} /*******************Video main********************/ .video-play-buttonm { position: absolute; z-index: 10; top:50%; left:50%; transform: translateX(-50%) translateY(-50%); box-sizing: content-box; display: block; width: 32px; height: 44px; /* background: #fa183d; */ border-radius: 50%; padding: 18px 20px 18px 28px; } .video-play-buttonm:before { content: ""; position: absolute; z-index: 0; left: 50%; top:50%; transform: translateX(-50%) translateY(-50%); display: block; width: 80px; height: 80px; background: transparent; border-radius: 50%; border:4px solid #ffffff; /*animation: pulse-border 1500ms ease-out infinite;*/ } .video-play-buttonm:after { content: ""; position: absolute; z-index: 1; left: 50%; top:50%; transform: translateX(-50%) translateY(-50%); display: block; width: 15px; height: 15px; background: #652dd314; border-radius: 0; transition: all 200ms; border-left: 24px solid #fff; border-top:16px solid transparent; border-bottom: 16px solid transparent; } } .video-play-buttonm:hover:after { background-color: darken(#fa183d, 10%); } .video-play-buttonm img { position: relative; z-index: 3; max-width: 100%; width: auto; height: auto; } .video-play-buttonm span { /* display: block;*/ /* position: relative;*/ /* z-index: 3;*/ /* width: 0;*/ /* height: 0;*/ /* border-left: 32px solid #fff;*/ /*border-top:22px solid transparent;*/ /*border-bottom: 22px solid transparent;*/ } @keyframes pulse-border { 0% { transform: translateX(-50%) translateY(-50%) translateZ(0) scale(1); opacity: 1; } 100% { transform: translateX(-50%) translateY(-50%) translateZ(0) scale(1.5); opacity: 0; } } .video-overlaym { position: fixed; z-index: -1; top:100px; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.80); opacity: 0; transition: all ease 500ms; } .video-overlaym.open { position: fixed; z-index: 1000; opacity: 1; } .video-overlaym-close { position: absolute; z-index: 1000; top:15px; right: 20px; font-size: 36px; line-height: 1; font-weight: 400; color: #fff; text-decoration: none; cursor: pointer; transition: all 200ms; } .video-overlaym-close:hover { color: #fa183d; } .video-overlaym iframe { position: absolute; top:50%; left: 50%; transform: translateX(-50%) translateY(-50%); /* width: 90%; */ /* height: auto; */ box-shadow: 0 0 15px rgba(0,0,0,0.75); } /*******************Video end********************/ .ytimg{ height: 100%; width: 100%; max-width: 100%; max-height:100%; position:relative; } .row.trailer > div { margin-bottom: 25px; } @media only screen and (max-width: 500px) { .trailer{margin-top:20px;margin-left:8px;margin-right:8px;padding:20px;} } </style> <div class="container-fluid"> <div class="lifeunderpar" > <div class="banner"> <img src="https://www.webmentor.in/wp-content/uploads/2019/10/cropped-qtq50-ytdL78.jpeg" /> <a id="play-videom" class="video-play-buttonm" href="#"> <span></span> </a> <div id="video-overlaym" class="video-overlaym"> <a class="video-overlaym-close">×</a> </div> </div> </div> </div> <script> jQuery('#play-videom').on('click', function(e){ e.preventDefault(); jQuery('#video-overlaym').addClass('open'); jQuery("#video-overlaym").append('<iframe width="100%" height="480" src="https://www.youtube.com/embed/aUw3vDdy8wk" frameborder="0" allowfullscreen></iframe>'); }); jQuery('.video-overlaym, .video-overlaym-close').on('click', function(e){ e.preventDefault(); close_videom(); }); jQuery(document).keyup(function(e){ if(e.keyCode === 27) { close_videom(); } }); function close_videom() { jQuery('.video-overlaym.open').removeClass('open').find('iframe').remove(); }; </script>
-
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.
-
How to import / upload heavy database on localhost Xampp.
- download the sql file you want to upload in the xampp phpmyadmin. eg olddb.sql
- create a database in localhost/phpmyadmin. eg mydb
- Go to xampp cpanel and click on Shell button on right.
- The CMD for sql window will open
- write the command over there and done. command is mysql -u username -p database_name < “/path/file.sql”
# mysql -u root -p mydb < "C:\olddb.sql"
-
How to add Slider in home page.
- Create a block in magento 2 eg name ‘myslider‘ with codes as below
<p><img class="mySlides" style="width: 100%;" src="https://xyz.com/media/wysiwyg/narciso-feb21.jpg"> <img class="mySlides" style="width: 100%;" src="https://xyz.com/media/wysiwyg/fragrance_category_brandbanner_2476x850px_2.jpg"> <img class="mySlides" style="width: 100%;" src="https://xyz.com/media/wysiwyg/dolce-maj-2021lyko---2476x762-px_2.jpg"></p>
- 2 Create a phtml page in folder app/design/frontend/Vendor/yourtheme/Magento_Theme/templates/ like theslider.phtml with the following codes
<style> .mySlides {display:none;} </style> <div class="slideshow-container"> <?php echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('myslider') ->toHtml(); ?> </div> <script> var myIndex = 0; carousel(); function carousel() { var i; var x = document.getElementsByClassName("mySlides"); for (i = 0; i < x.length; i++) { x[i].style.display = "none"; } myIndex++; if (myIndex > x.length) {myIndex = 1} x[myIndex-1].style.display = "block"; setTimeout(carousel, 2000); // Change image every 2 seconds } </script>
- 3 Call the block myslider in widget , which shall display on specific page , page as your homepage and container as AFTER PAGE HEADER TOP