Skip to main content

Posts

What startSetup() and endSetup() methods actually does?

The startSetup() and endSetup() methods are used in setup scripts. They are often at the beginning and the end of an upgrade/install method, like in “upgrade()” method of Magento/Catalog/Setup/UpgradeData.php The question is “do you really need them?” Or does it just “look necessary”? This blog post explores what these functions do and then explains when you do and do not need to use these methods. Let’s see what these methods are doing. First, startSetup(): public function startSetup() {   $this->rawQuery("SET SQL_MODE=''");  $this->rawQuery("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");   $this->rawQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");   return $this;  } 1. Disable foreign keys check. It may be necessary in some rare cases (for example, in a case of cyclic references between tables), but it’s not needed in common situations. It even may lead to hiding real problems
Recent posts

Magento 2.2.4: Community Or Enterprise Menu does not appear on home page

  In Magento 2.2.4  Community  Or  Enterprise  edition default menu does not appear on the home page I was checked and found that JS is not showing in inspect element on the home page, so the reason for this menu is not displaying. in inspect element on the home page showing like this  <esi:include src="http://127.0.0.1/ab-ee/page_cache/block/esi/blocks/%5B%22catalog.topnav%22%5D/handles/WyJkZWZhdWx0IiwiY21zX2luZGV4X2luZGV4IiwiY21zX3BhZ2VfdmlldyJd/"></esi:include>  Here  Actually, the problem is related to   Varnish Cache   if I disable   Varnish Cache  from   Store -> Configuration -> Advanced -> System -> Full page cache -> Caching Application   Set to   Varnish Cache   then the menu is not displaying if I set it to   'Built-in cache'   then it's working fine. OR  follow the below steps to get this done Overwrite default.xml located at /vendor/magento/module-theme/view/frontend/layout/ search for ttl="3600" written inside &qu

Magento 2 issues with layouts

 Hi  I came with new issue debugging if have xml tag not valid issue to find which file it is. Some times we will get xml errors like  1 exception(s): Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'referenceBlock', attribute 'remove': 'True' is not a valid value of the atomic type 'xs:boolean'. Line: 1 Element 'referenceBlock', attribute 'remove': 'True' is not a valid value of the atomic type 'xs:boolean'. Line: 2 Element 'referenceBlock', attribute 'remove': 'True' is not a valid value of the atomic type 'xs:boolean'. Line: 3 like this of errors we will get It's hard find which file it is if we did in any xml file we can easily locate if some done long days ago if got ticket to solve this is hard to find. Some will do in pages admin Layout Update XML section some one done core files based their flexible they will do but finding is hard so for this do below st

Magento 2 product collection Filtering multi-select attribute values

  If you have multi-select attribute of product like below If you want filter value for this option Use below syntax to get product data: ->addAttributeToFilter('store_model', array('finset' => $params['store_model'])) finset key is used for multiselect attribute filter. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $products = $objectManager->get('Magento\Catalog\Model\Product')         ->getCollection()         ->addAttributeToSelect('*')         ->addAttributeToSelect('store_brand')         ->addAttributeToSelect('store_model')         ->addAttributeToSelect('store_year')         ->addAttributeToFilter('store_brand', array('finset' => $params['store_brand']))         ->addAttributeToFilter('store_model', array('finset' => $params['store_model']))         ->addAttributeToFilter('store_year', array('

Magento 2 add images in knockout files

If you want to add a dynamic image from the theme or module’s web/images folder, You can be assigned images using the knockout template with ease. Simply call the function in src of your image tag, require.toUrl(‘web/images’) Keep the image in web/images/logo.png location of your theme or module. <img data-bind="attr: { src: require.toUrl('images/pawan.png') }" /> Now simply add above one line in .html template to display the image on your page.  Using this method, Your images search for the theme web/images folder. If you want to display Images from specific Module’s Web folder: If you have images in the module web folder in your theme or Custom module, app/design/frontend/{Vendor}/{themename}/Magento_Checkout/web/images/logo.png You have to add module name before image path, <img data-bind="attr: { src: require.toUrl('Magento_Checkout/images/logo.png') }" /> When you see the front page, your images have taken a path from the pub/static

Magento 2 checkout - Update shipping methods after change of city, address line and telephone fields

When we  need to trigger the call that updates the shipping methods on the checkout page when the city, address lines, telephone and email fields change. Just like when the shipping methods are updated when the postcode, country and province fields change. We need to try below steps in custom shipping module as described follows and its working fine for me: Pawan/Customshipping/view/frontend/requirejs-config.js var config = {     "map": {         "*": {             "Magento_OfflineShipping/js/model/shipping-rates-validation-rules/flatrate": "Pawan_ Customshipping /js/model/shipping-rates-validation-rules/flatrate",         }     } }; Pawan/Customshipping /view/frontend/web/js/model/shipping-rates-validation-rules/flatrate.js define([], function () {     'use strict';     return {         /**          * @return {Object}          */         getRules: function () {             return {                 'country_id': {                

How to Add Magento 2 Sort by Price for Low to High & High to Low Options and name A-Z & Z-A etc sort dropdown

The store design and its navigation must be in such a way that makes it easier for the shopper to find the exact required product and make the shopping process comfortable and enjoyable.  Navigation can be made easier and hence improve the shopping experience by offering custom sorting options. The default Magento 2 offers sorting by position, product name, and price  A price-sensitive customer may save some clicks by starting with the cheapest products. On the other hand, customers who have a high standard for quality may quickly find their most desired products by sampling from high prices to low prices. To provide such feature in Magento 2 and serve both the type of price-sensitive customers, you can add Magento 2 sort by price for low to high & high to low options. Some people can sort by names A-Z or Z-A, position low to high high to low like this we can improve sales to our site and user can easily find products for implementing this fallow given steps to implement sorting Ad