Skip to main content

Posts

Showing posts from May, 2021

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);        ...