Skip to main content

Posts

Magento 2 Minicart - Display line item subtotal rather than unit price

url: https://magento.stackexchange.com/questions/173028/magento-2-minicart-display-line-item-subtotal-rather-than-unit-price     Final Solution, You can get item qty using $qty = $item->getQty(); Now just you have to set $block->getUnitDisplayPriceInclTax()*$qty to get lineItem subtotal for each item. app/design/frontend/{Packagename}/{themename}/Magento_Weee/templates/checkout/cart/item/price/sidebar.phtml   <?php /** @var $block \Magento\Weee\Block\Item\Price\Renderer */ $item = $block ->getItem(); $originalZone = $block ->getZone(); $block ->setZone(\Magento\Framework\Pricing\Render::ZONE_CART); /* custom logic*/ $qty = $item ->getQty(); ?> <?php if ( $block ->displayPriceInclTax() || $block ->displayBothPrices()): ?> < span class = "price-including-tax" data-label = " <?php echo $block ->escapeHtml(__( 'Incl. Tax' )); ?> " > <?php if ( $block ->displayPriceWithWeeeDetai...

Magento 2 get cart totals

 <?php $totals = $block->getTotals() ; ?> <table class="data table totals">     <tbody>         <?php foreach($totals as $key => $total) :?>             <?php if(!empty($total->getValue())) :?>                 <tr>                     <td><?= $total->getTitle()->getText() ?></th>                     <td>                         <span class="price"><?= $this->helper('Magento\Framework\Pricing\Helper\Data')->currency(nu...

Magento 2 Get Cart Quote Total in minicart.phtml

  This Below line is workig for all cases if cache is enable its working fine, < span data-bind = "html: getCartParam('subtotal')" > </ span >     Add this in  minicart.phtml <?php $quote = $block ->getTotalsCache(); $getSubTotal = $quote [ 'subtotal' ]->getData( 'value' ); $getGrandTotal = $quote [ 'grand_total' ]->getData( 'value' ); $getShippingRate = $quote [ 'shipping' ]->getData( 'value' ); $finalSubTotal = $this ->helper( 'Magento\Framework\Pricing\Helper\Data' )->currency(number_format( $getSubTotal , 2 ), true , false ); $finalShippingTotal = $this ->helper( 'Magento\Framework\Pricing\Helper\Data' )->currency(number_format( $getShippingRate , 2 ), true , false ); $finalGrandTotal = $this ->helper( 'Magento\Framework\Pricing\Helper\Data' )->currency(number_format( $getGrandTotal , 2 ), true , f...

script to change single product add to cart text

  add this in addtocart.phtml page <script>     require([         'jquery',         'mage/mage',         'Magento_Catalog/product/view/validation',         'Magento_Catalog/js/catalog-add-to-cart'     ], function ($) {         'use strict';         $('#product_addtocart_form').mage('validation', {             radioCheckboxClosest: '.nested',             submitHandler: function (form) {                 var widget = $(form).catalogAddToCart({                     bindS...

add minicart to custom header

 <move element="minicart" destination="Custom_header" before="-" />     <!--referenceContainer name="page.wrapper" remove="true"/-->         <referenceBlock name="header.container" remove="true" />            <referenceContainer name="page.wrapper">             <block class="Magento\Framework\View\Element\Template"             name="Custom_header"             template="Magento_Theme::html/customheader.phtml"             before="-"/>                             </referenceContainer> ////*****************************************************************////...

Solution to Change Currency Symbol Position in Magento 2

Note : You can use any extension   1. Create events.xml file at app/code/vendor/Exenstion/etc/frontend   <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">     <event name="currency_display_options_forming">         <observer name="change_currency_position" instance="vendor\Exenstion\Observer\ChangeCurrencyPosition"/>     </event> </config>  2. Create ChangeCurrencyPosition.php  file at app/code/vendor/Exenstion/Observer   <?php namespace vendor\Exenstion\Observer; use Magento\Framework\Event\ObserverInterface; class ChangeCurrencyPosition implements ObserverInterface {     public function execute(\Magento\Framework\Event\Observer $observer)     {      ...

get configurable items of product magento 2

 $product_id = 25; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id); foreach ($configProduct->getOptions() as $options) {     $optionData = $options->getValues();     $parent_title = $options->getTitle();     $parent_id = $options->getId();     $parent[$parent_id] = $options->getTitle();     foreach ($optionData as $data) {         /* echo '<pre>';          print_r($data->getData());         echo '</pre>'; */         $optionPrice [ $data['option_id'] ][ $data['title'] ] = $data->getPrice();         $optionid [ $data['option_id'] ][ $data['title'] ] = $data['option_type_id'];     } } $optionPricemy...

get bundle product options magento 2

<?php         $id = 9;          $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();          $product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($id);          $customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);          $productTypeInstance = $_objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');          $productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);          $typeInstance = $_objectManager->get('Magento\GroupedProduct\Model\Product\Type\Grouped');          $childs = $typeInstance->getAssociatedProducts($product);        ...

Get latest products magento 2

  <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager ->create( 'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory' ); $collection = $productCollection ->create() ->addAttributeToSelect( '*' ) ->load(); $store = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore();    foreach ( $collection as $product ){ echo 'Name = ' . $product ->getName(). '<br/>' ; }   foreach ($collection as $product) { $imageUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage(); <div class="item"> <a href="<?= $product->getProductUrl(); ?>"> <div class="product-home"> <span class="tag">NEU</span> <img src="<?php echo $imageUrl; ?>" alt...

Include jquery, owl carousel, bootstrapjs in magento 2

  app/design/frontend/Vendor/Theme/Magento_Theme/layout/default.xml   < referenceContainer name = "after.body.start" > < block class = "Magento\Framework\View\Element\Template" name = "custom.js" template = "Magento_Theme::custom_js.phtml" /> </ referenceContainer >   app/design/frontend/Vendor/Theme/requirejs-config.js /**  * Copyright © 2015 Magento. All rights reserved.  * See COPYING.txt for license details.  */ var config = {     map: {         '*': {             'respond': 'js/respond.min',             'customScript':'js/customscript'         }     },     paths: {             'bootstrap': 'js/bootstrap.min',      ...

Magento 1: get all categories with product count

 <?php $cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>                     <?php $category = Mage::getModel('catalog/category')->load($cat_id); ?>                     <?php //echo $category->getName(); ?>                                         <?php $_helper = Mage::helper('catalog/category') ?>                     <?php $_categories = $_helper->getStoreCategories() ?>                     <?php if (count($_categories) > 0): ?>      ...

Magento 2: code to get featured products

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */ $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); /** Apply filters here */ $collection = $productCollection->addAttributeToSelect('*')->load();     foreach ($collection as $product){     // echo 'Name  =  '.$product->getName().'<br>';     echo '<pre>';     //print_r($product->getData());     print_r($product['sw_featured']);     echo '</pre>'; } ?>

Magento 2: get child product of current configurable product

<?php      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();     $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product     $productTypeInstance = $product->getTypeInstance();     $usedProducts = $productTypeInstance->getUsedProducts($product);     echo $product->getId(); //Main configurable product ID     echo $product->getName(); //Main Configurable Name     foreach ($usedProducts  as $child) {         echo $child->getId()."</br>"; //Child Product Id          echo $child->getName()."</br>"; //Child Product Name     }?>

Magento 2: get product category on product detail page

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); $categories = $product->getCategoryIds(); /*will return category ids array*/ foreach($categories as $category){     $cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category);     $cats[] = $cat->getName();     }         // echo '<pre>';     // print_r($cats);     // echo '</pre>';         ?>

Magento 2: Putty Commands

cd - change directory cd ..    - come out of one directory pwd        -    Path of my current directory wget - get downloadable data unzip filename.zip -d /pictures  - for unzip data and -d for directory unzip -l filename.zip  -  list all files from a .zip file unzip filename.zip filename.txt  -- extract / unzip certain file from a .zip file zip -r filename *  -   zip up an entire directory including all sub-directories zip -r example2.zip *  -  zip all files in current directory rm -rf *    -    delete all files in directory rm -rf foldername/  -  To delete a whole folder and its content mysql -u user_name -p database_name< advomate_pompusalive.sql  ------ for import DB mysqldump -u username -p  database_to_be_exported > db_file_name.sql  ------   for export DB yum install zip unzip -y...

Magento 2: CRUD

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $tableName = $resource->getTableName('employee'); //gives table name with prefix //Select Data from table $sql = "Select * FROM " . $tableName; $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array. //Delete Data from table $sql = "Delete FROM " . $tableName." Where emp_id = 10"; $connection->query($sql); //Insert Data into table $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')"; $connection->query($sql); //Update Data into table $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12"; $connecti...