Posts

How to override js in magento 2

 How to override js in magento 2 To override js we need requirejs-config.js requirejs-config.js need to create at [Vendor]/[Module]/view/frontend/requirejs-config.js var config = {     map: {         '*': {             'Magento_Checkout/js/model/shipping-rates-validator':'Vendor_Module/js/model/shipping-rates-validator'         }     } }; Create file at app/code/Vendor/Module/view/frontend/web/js/model/shipping-rates-validator.js Write your inside file and boom!!!  If developer mode is on and symlinks are generating clear cache bin/magento cache:clean If production mode is on , need to deploy static content files using command bin/magento s:s:d  If like efforts, Please share, comment and subscribe for future posts and inspire more.

Adding custom attribute to Customer

Adding custom attribute to Customer Create InstallData.php file at app/code/{Vendor}/{Module Name}/Setup/InstallData.php <?php namespace Hello\CustomerAttribute\Setup; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Eav\Model\Config; use Magento\Customer\Model\Customer; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory, Config $eavConfig) { $this->eavSetupFactory = $eavSetupFactory; $this->eavConfig       = $eavConfig; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( \Magento\Customer\Model\Customer::ENTITY, ...

Magento 2 Add Product Attribute Programmatically

 Magento 2 Add Product Attribute Programmatically Create file InstallData.php at app/code/Vendor/Module/Setup/InstallData.php <?php namespace Vendor\Module\Setup; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'brand_attribute', [ 'type' => 'text', 'backend' => '', 'frontend' =...

Magento 2 How to Override Core Block, Model and controller

Magento 2 How to Override Core Block, Model and controller Create di.xml file at app/code/{Vendor}/{Module}/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">         <preference for="Magento\Catalog\Controller\Product\View" type="{Vendor}\{Module}\Controller\Catalog\Product\View" /> </config> Create File View.php at app/code/{Vendor}/{Module}/Controller/Catalog/Product/ <?php namespace Vendor\Module\Controller\Catalog\Product; class View extends \Magento\Catalog\Controller\Product\View { public function execute(){ echo 'Hello Called from Overriden File '.__DIR_;exit; } } If like efforts, Please share, comment and subscribe for future posts and inspire more.

How to check if customer is logged in or not?

How to check if customer is logged in or not?   1) Using Object Manager. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) {       // Yes customer is logged in } 2) From Controller. $this->_objectManager->get('Magento\Customer\Model\Session'); if($customerSession->isLoggedIn()) {    // Yes customer is logged in } 3) From Block or Model Or Helper. protected $customerSession; public function __construct(     \Magento\Customer\Model\SessionFactory $customerSession ) {     $this->customerSession = $customerSession; } public function isLoggedIn() // use this function in phtml file {     return $this->customerSession->create()->isLoggedIn(); } If like efforts, Please share, comment and subscribe for future posts and inspire more.

Magento 2 How to load product by id

1)   Object method $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id); 2)  Factory Method <?php namespace Hello\Module\Block; class Product extends \Magento\Framework\View\Element\Template {   protected $_productloader;     public function __construct(         \Magento\Framework\View\Element\Template\Context $context,         \Magento\Catalog\Model\ProductFactory $_productloader     ) {         $this->_productloader = $_productloader;         parent::__construct($context);     }     public function getLoadProduct($id)     {         return $this->_productloader->create()->load($id);     } } If like efforts, Please share, comment and subscribe for future posts and inspire more.

Magento 2 popup modal

 How to use magento 2 modal for popup. There are tow ways to initiate popup modal in magento 2. 1) Using js. require(     [      'jquery',         'Magento_Ui/js/modal/modal'     ],     function(         $,         modal     ) {         var options = {             type: 'popup',             responsive: true,             innerScroll: true,             buttons: [{                 text: $.mage.__('Continue'),                 class: 'mymodal1',                 click: function () {                     this.closeModal();             ...

Magento 2 404 error for scripts and css

 Magento 2 404 error for scripts and css 1)  Please check mistakenly not deleted .htaccess file at pub/static path. 2) When Magento is not running on production mode , it will create symlinks for some static resource. So what to do is delete pub/static/frontend and pub/static/adminhtml   Alert : Do not delete .htaccess under pub/static/ folder.  3) Changing the behavior. Open up app/etc/di.xml and find the virtualType name="developerMaterialization" section. In that section one may find code item name="view_preprocessed" that needs to be modified or deleted. You can modify it by changing the contents from  Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink   to  Magento\Framework\App\View\Asset\MaterializationStrategy\Copy This should  have solve your problem with the symlink creation. If like efforts, Please share, comment and subscribe for future posts and inspire more.

How to use Zend log Magento 2

 To use Zend log use below code in any PHP file. $yourmessageString = 'Hey from magento zend log'; $yourmessageArray = ['Hey from magento zend log Array ']; $writer = new \Zend\Log\Writer\Stream(BP . ‘/var/log/custom.log’); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info($yourmessageString); $logger->info(print_r($yourmessageArray,true)); //for array and objects

Knock out js Short hands

 Knock out JS short hand properties. You can use  1.  this.knockoutProperty /= value;  instead  this.knockoutProperty(this.knockoutProperty() / value) 2.   this.knockoutProperty *= value;  instead  this.knockoutProperty(this.knockoutProperty() * value) 3. this.knockoutProperty -= value;  instead  this.knockoutProperty(this.knockoutProperty() - value) 4.  this.knockoutProperty += value;  instead  this.knockoutProperty(this.knockoutProperty() + value) Please like , share and subscribe.

How to add product attribute value in minicart magento 2

How to add product attribute value in minicart magento 2? First need to do is create a plugin so add plugin at di.xml at first. di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Checkout\CustomerData\DefaultItem"> <plugin disabled="false" name="AddAttPlug" sortorder="10" type="Your\Module\Plugin\DefaultItem"> </plugin></type> </config> Now create a plugin class and below line of code.   Default.php <?php namespace Your\Module\Plugin; use Magento\Quote\Model\Quote\Item; class DefaultItem { public function aroundGetItemData($subject, \Closure $proceed, Item $item) { $data = $proceed($item); $product = $item->getProduct(); $atts = [ "product_weight" => $product->ge...

How to create a order from quote?

How to create a order from quote in magento 2? Find full answer below. We will load one product than we will create a quote for it and than we will convert that quote into an order. <?php use Magento\Framework\App\Action\Action; class OrderCreateTest extends Action {     protected $_quoteFactory;     protected $_orderModel;     protected $_productModel;     protected $_customerRepository;     protected $_quoteManagementModel;          public function __construct(\Magento\Quote\Model\QuoteFactory $quoteFactory, \Magento\Sales\Model\Order $orderModel, \Magento\Catalog\Model\Product $productModel, \Magento\Framework\App\Action\Context $context, \Magento\Quote\Model\QuoteManagement $quoteManagementModel, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)     {         $this->_quoteFactory         = $...

Understand Magento type node and how to use for own benefits.

Hey folks, Today we will going to learn fundamental of < type /> node which used in di.xml. So let's start without time waste let's talk about <type />  node. To understand this concept we will use an example for that we will create sample module. So let's do this together.  If you already know how to create a module you can skip this intro. To create a module there is two files are required. registration.php module.xml So let's create a registration.php path :  app/code/Extrembler/Base \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Extrembler_Base', __DIR__ ); Second we need to create module.xml path : app/code/Extrembler/Base/etc <?xml version="1.0"?> <!-- /** * @category Extrembler * @package Extrembler_Base * @author Extrembler <gaurangpadhiyar1993@gmail.com> */ --> <config xmlns:xsi="http://www...

Magento Currency Symbol

Image
Magento Currency Symbol Do want to change look of currency or fronted display symbol or do not want a symbol at all? If yes, you landed at correct place to while searching for a solutions. We are bringing a extension solution for you guys so without help of developer you can change look of currency symbol. Extension which we have developed. Currency Symbol - By Extrembler Features Easily enable/disable functionality Simply set currency symbol from pre-defined options Multi-store compatibility Enable/disable module store wise Change behaviours of currency symbol store wise Remove Currency Symbol using option no symbol Comes With Free Lifetime Updates 100% Open Source Multi-Store Supported Support If you have any questions about this extension, you can  Contact Us . If like efforts, Please share, comment and subscribe for future posts and inspire more.

Magento 2.3.3 Realease Notes - Features and Enhancement

Image
New release include 170 functional fixed by Magento team and community contributors in core product. A major change regarding security enhancement made in Magento 2.3.3. As per official statement from Magento release notes 75 security enhancements made. There are several changes so let's categories them and go on trip of Magento 2.3.3. Security enhancements Platform upgrades Infrastructure improvements Inventory Management enhancements Vendor-developed extension enhancements Magento Shipping Performance boosts Merchant tool enhancements GraphQL PWA Studio Google Shopping ads Channel Backward-incompatible Changes Security enhancements Improvements in core payment methods which are now compliant with PSD2 regulations. PSD = Payment Services Directive. A major PSD2 change is in Braintree payment. Now Magento version 2.3.3 can verfiy Braintree payment transactions by native Braintree 3D Secure 2.0 service. Authorize.net introduced "c...

Magento 2.3.2 - Export Error

Image
Have you just upgraded to Magento version 2.3.2? Have an error on export? Than you are at right place for a solution. So without wasting time , let's roll the camera. Error: Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : CData section too big found in vendor/magento/framework/View/TemplateEngine/Xhtml/Template.php on line 60 Preconditions (*) Magento version 2.3.2 Too big files and number of files more (around > 20000) Steps to reproduce (*) Login Admin panel Go to System -> Export Expected result (*) 1) 2) Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : CData section too big found in vendor/magento/framework/View/TemplateEngine/Xhtml/Template.php on line 60 You have error as described than below solution for your store. 1)  export_grid.xml      vendor/magento/module-import-export/view/adminhtml/ui_component/export_grid.xml <?xml versi...

Magento 2 Import Scripts

Magento 2 Import Scripts Simple and faster way to import data scripts for magento 2. https://github.com/Extrembler/Magento-2-Import-Scripts Keep your self updated by subscribing our website so whenever we update with new import scripts we can inform you. #import #importmagento2 #magento2 #simpleimport  If like efforts, Please share, comment and subscribe for future posts and inspire more.

Popup Before Add to Cart - Magento

Image
Magento is very big e-commerce platform which support various functionality by extension , also called as module. In this blog, we will see an unique functionality "Popup before Add to cart". Essentially, while adding product to cart website owner need to show some content for marketing purpose or anything else. This extension exactly made for same functionality. It will show content before adding product to cart. Extrembler CartBeforePopup v 1.0.0 Another question is that, What if website owner need to show CMS block content on popup. Don't worry , our team has already taken care of that. An extension provide functionality to user where he/she can choose any cms block from system or simple text content based on choice. One of the major benefit of the module, easily disable and enable functionality without disabling the module. Find out more information below. Features: 1. Easy installation. 2. Manageable content. 3. Easy selection of CMS ...

Magento 2.2 and PHP 7.2

Image
Are you facing issues after upgrading magento 2.2 to PHP 7.2?  Follow below steps to resolve the same. Migrating Magento 2.2 to server with PHP version 7.2 , many issues faced and so we have approached many files to solve this. Keep patient and follow steps one by one.  1) PHP 7.2 does not contain 4 the mcrypt extension 8. In Debian pecl install mcrypt-snapshot In Windows composer require phpseclib/mcrypt_compat:* 2) Warning: ini_set(): A session is active. You cannot change the session module’s ini settings at this time in lib/internal/Magento/Framework/Session/SessionManager.php on line 129 Replace the lines: lib/internal/Magento/Framework/Session/SessionManager.php #Line128-Line129 // Enable session.use_only_cookies ini_set(‘session.use_only_cookies’, ‘1’); with the following ones: if (!$this->isSessionExists()) {  // Enable session.use_only_cookies  ini_set(‘session.use_only_cookies’, ‘...