-
Install symfony in xampp
C:\xampp\htdocs>composer create-project symfony/website-skeleton lee_example
start the server for project
C:\xampp\htdocs\lee_example>php -S 127.0.0.1:8000 -t public
-
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”;
}
-
Jquery code : to match element’s value from its id and show text based on that to other element
<script> jQuery(document).ready(function(){ var xle; xle= jQuery("#coupon_code").val(); if(xle>"FREENEXT") { jQuery("#msg").html('Express Delivery'); jQuery("#msg").css('color','#000'); } }); </script>
-
limit Input text box charecters ,enter only 10 characters at max
<script> var keycount =0; jQuery(document).on('keydown', 'input.product-custom-option', function(ev) { var c = ev.which; // console.log(c); if(c==8) { keycount--; } else{ keycount++; // console.log(keycount); } if(keycount>10) { return false; } }); </script> <input type="text" class="product-custom-option" />
OPtion 2
function ohmyfun() { var xdata=''; var lee = document.getElementsByClassName("product-custom-option")[0].id; console.log(lee); document.getElementsByClassName("product-custom-option")[0].addEventListener("keydown", getleecount); } function getleecount() { var lee_id = document.getElementsByClassName("product-custom-option")[0].id; var xle= document.getElementById(lee_id).value; console.log(xle.length); if(xle.length==9){ xdata = document.getElementById(lee_id).value; console.log(xdata); document.getElementById(lee_id).value=xdata; } else if(xle.length>9){ console.log(xdata); document.getElementById(lee_id).value=xdata; } } </script>
-
Get the attribute value in product page programatically
in Magento_Catalog / template /product/ make a phtml file .
write the below code
$_product = $block->getProduct(); $pi = $_product->getData('giftwrap'); // giftwrap is attribute name if($pi==1){ echo "show image";}
Magento_Catalog/layout /catalog_product_view.xml
<block name="catalog.mygifrwrap" template="Magento_Catalog::product/giftwrap.phtml" class="Magento\Catalog\Block\Product\View"/>
-
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();