How To Setup Algolia in Magento 2.x

Algolia is an American company that provides fast web search results through Software-as-a-Service (SaaS) model, It is Hosted based search engine accessible via an API powering computer grade search for websites / app, Using Algolia, Users feel personalized site search &s a fast and reliable search experience.

The following below Algolia Search Features

[1] – Search  as a Service [SAAS]]

[2] – API Integrate with Real Time Search

[3] – Auto Complete / Auto Suggest

[4] – Accurate Results

[5] – Full Text Search

[6] – AI Based Search

[7] – Instant Search Result

[8] – Find Answer Faster

[9] – Full Text Search Result

[10] – Globally 70 Data Center

[11] – Highly Optimized & Consumer Grade Search

[12] – Fast Response Time & Relevant Results

Algolia for Magento 2.x available the following below plans

[1] Free Plans :: Only limited features available
[2] Paid plans :: All features available

The following below steps to integrate Algolia with Magento 2.x

Step [1] – Run the below composer require command

Path=Magento 2 Root Directory

composer require algolia/algoliasearch-magento-2

Step [2] – Run below command to enable AlgoliaSearch

php bin/magento module:enable Algolia_AlgoliaSearch
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy

Step [3] – Check composer.json on Magento 2.x Directory

Step [4] – Check below file on Magento 2.x Directory

.magento.env.md

Step [5] Magento 2.x Admin settings for Algolia

To configure the Magento 2.x admin Algolia configuration, need the following Algolia credentials:

Application ID
Search-only API key
Admin API key

You can find these credentials on the Algolia Dashboard, on the API Keys page from the menu.

Step [6] Go To STORES > Configuration, redirects on configuration.

Step [7] – Go To Left Side Panel Algolia > Search, It redirects below Algolia Search Panel.

Fill Application ID, Search-only API key, Admin API key from previous Step [5]

Step [8] – Once, Magento 2.x Aloglia Admin Configuration has been done, send the data in your Magento 2.x installation to Algolia using the indexing process.

For Algolia Indexing Process, run below CLI Command

php bin/magento indexer:reindex algolia_products algolia_categories algolia_pages algolia_suggestions algolia_additional_sections

Finally, Magento 2.x with Algolia Search has been configured

Which Magento 2.x Database Tables For Algolia Search, While Magento 2.x Connected To Algolia Search.

How To Get Customer Data By GraphQL Query in Magento 2.x

We are going to explain, Custom GraphQL Query Module to fetch the Customer’s Data in Magento 2.x to retrieve basic information of the customer entity as below

  • email
  • firstname
  • lastname
  • gender
  • dob
  • created_at

There are following below steps need to follow.

Customer GraphQL Query Module by using custom module

Here, we are considering as
Namespace / ModuleName = Mage2db / CustomerGraphQl

Step [1]  Create registration.php file under your module [ Namespace / ModuleName ]

File Path=Mage2db/CustomerGraphQl/registration.php

Add below content in this file.

<?php
/**
 * @author       John
 * @copyright    Copyright (c) 2022 (https://mage2db.com)
 * @package      CustomerGraphQl
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mage2db_CustomerGraphQl',
    __DIR__
);

Briefly Explain module.xml

Step [2] – Create module.xml file under your module [ Namespace / ModuleName ]

File Path=Mage2db/CustomerGraphQl/etc/module.xml

Add below content in this file.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mage2db_CustomerGraphQl" setup_version="1.0.0">
        <sequence>
            <module name="Magento_GraphQl"/>
            <module name="Magento_Backend"/>
            <module name="Magento_CustomerGraphQl"/>
        </sequence>
    </module>
</config>

Briefly Explain registration.php

Our Module is depends on GraphQL and Customer GraphQL Module, we have given dependency on module.xml file.

Step [3] – Every GraphQl Module must contain schema.graphqls file under the etc folder of a module.

File Path=Mage2db/CustomerGraphQl/etc/schema.graphqls

Add below content in this file.

#Custom Module Customer GraphQL
type Query {

    customer_details(

    id: Int! @doc(description: "Specify The ID of The Customer.")

    ): CustomerData @resolver( class: "Mage2db\\CustomerGraphQl\\Model\\Resolver\\Customerlist") @doc(description: "Get list of Customer Data for the given customer id.")

}

type CustomerData {
        firstname: String
	lastname: String
	email: String
	gender: String
	dob: String
        city: String
	created_at: String
}

id: Int @doc(description: “Id of the Customer”) map to Stored Customers Listing id as Int type

Step [4] – Need to create Customerlist.php file from defined resolver from above schema.

CustomerData @resolver( class: “Mage2db\CustomerGraphQl\Model\Resolver\Customerlist”) @doc(description: “Get list of Customer Data for the given Customer ID.”)

Add below content in this file.

<?php
/**
 * @author       John
 * @email        johndusa1021@gmail.com
 * @copyright    Copyright (c) 2022 (https://mage2db.com)
 * @package      CustomerGraphQl
 */
namespace Mage2db\CustomerGraphQl\Model\Resolver;
 
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
 
class Customerlist implements ResolverInterface
{
	
        protected $_customerSession;
	protected $_customerFactory;
	protected $_addressFactory;
	protected $storeManager;
    
     /**
     * @param Field $field
     * @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
     * @param ResolveInfo $info
     * @param array|null $value
     * @param array|null $args
     * @return array|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed
     * @throws GraphQlInputException
     */
	 
	 public function __construct(
	 
     \Magento\Customer\Model\SessionFactory $customerSession,
     \Magento\Customer\Model\CustomerFactory $customerFactory,
     \Magento\Customer\Model\AddressFactory $addressFactory,
     \Magento\Framework\Url $url,
     StoreManagerInterface $storeManager
     )  
     {
	   $this->_customerSession = $customerSession->create();
           $this->_customerFactory = $customerFactory;
           $this->_addressFactory  = $addressFactory;
           $this->urlHelper = $url;
	   $this->storeManager = $storeManager;
          
      }
	 
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null)
    {
         $currentStoreId = $this->storeManager->getStore()->getId();

         $Customer_Collection = $this->_customerFactory->create()->load($args['id']);
		 		
		 return $Customer_Collection->getData();
    }
}

As per above script, resolve() method having script which is responsible for getting Customer GraphQl Data.

Step [5] – Finally your Customer GraphQl Query Module has been created

Run the following below commands at your Magento 2 root directory


php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

Step [6] – Check your Customer GraphQl Query Module query response by installing chrome extension ChromeiQL or Altair GraphQL addon.

Here we have checked by ChromeiQl

How To Setup Magento 2.x Coding Standard

Coding Standard is a set of rules / regulations to specify Magento 2.xCoding Standard, every developer / designer must follow while a participating in the Magento 2.x Project Development / Designing.

Magento 2.x Coding Standard design Application’s Security, Stability, Maintainability and Extensibility (extend or modify existing behavior)

The following below steps need to follow.

Step [1] – Go to Magento 2 Root Directory & run below command

composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard

Once successfully installed message as below

Config value “installed_paths” added successfully

Step [2] – Add below line in Magento 2 Root Directory composer.json

"scripts": {
	"post-install-cmd": [
	"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"],
	"post-update-cmd": [
	"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"]
	}

Step [3] – Run below command

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:flush

Step [4] – Verify Installation
Command should return the list of installed coding standards .
go inside magento-coding-standard

cd magento-coding-standard

Step [4.1] – Once go inside magento-coding-standard, Run below command

cd vendor\bin
phpcs -i

The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, Magento2, Magento2Framework and PHPCompatibility

Finally Magento 2.x Coding Standard has been installed successfully.

Step [5] – Run Below command to check either Installed Magento 2 Coding Standard proper working or not

phpcs --standard=Magento2 D:/xampp/htdocs/VendorName/ModuleName or Particular File Path

Once running phpcs command Solution as
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
Everytime once running phpcs after that need to run below command always
vendor/bin/phpcbf –standard=Magento2 D:/xampp/htdocs/HNI/yourcustomModule or particular file
Once running above command, minor issue (Line indented Issue, Space Issue, Whitespace
Issue, End of Line Issue etc) auto resolved
Again need to run below command & resolve issue according instruction
vendor/bin/phpcs –standard=Magento2 D:/xampp/htdocs/HNI/yourcustomModule or particular file

In Magento 2.4.x or Adobe Commerce 2.4.x — Magento 2.x Coding Standard already inbuilt just need to run CLI command as below

Syntax::

AdobeCommerce Root-Directory vendor/bin/phpcbf --standard=Magento2 app/code/John/Quicksupport
root@fad926ccdc9b:/var/www/html/wwwroot/magento246# vendor/bin/phpcs --standard=Magento2 app/code/John/Mage2db
root@fad926ccdc9b:/var/www/html/wwwroot/magento246# vendor/bin/phpcbf --standard=Magento2 app/code/John/Mage2db

Magento 2.x Never Allow The Direct Use of The ObjectManager Code

How To Install OpenSSL in Windows 10 or Above Windows Version

OpenSSL is an open-source command line tool which is used to generate Private Keys, create CSRs, implementation of the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols and identify certificate information.

The following below steps need to follow to install OpenSSL in Windows 10

Download the OpenSSL installer from the official OpenSSL

Download Path: https://slproweb.com/products/Win32OpenSSL.html

I have done download exe file of Win64 OpenSSL v3.0.2 Light

Step [1] – Win64OpenSSL_Light-3_0_2.exe in Downloads folder, once click on exe file

Step [2] – Path for Installation

Step [3] – Selection of Installation folder

Step [4] – Select default selected The Windows system directory

Step [5] – Ready To Install

Step [6] – Finally OpenSSL has been successfully Installed

Step [7] – Set Environment variable For SSL

Step [8] – Using Shortcut Key ‘Windows’ + ‘r’ then type ‘sysdm.cpl’

Go to Advanced > Environment Variables or Directly Open Environment Variables

Step [9] – Under System Variables, Click on Path

Step [10] – Once Click Edit Button, below popup window display,

Need to click on New Button and add below path

C:\Program Files\OpenSSL-Win64\bin

Step [10] – Finally run

openssl version

How To Resolve Blank Page Error [Storefront & Backend] After Installation in Magento 2.x

While Installing a Magento 2.x installation [Community Edition or Enterprise Edition or Commerce Cloud Edition ], you have seen that common blank page error [Storefront & Backend] that displays blank page.

Solution :: The following below steps need to follow

Step [1] – Go To ‘Validator.php’ file located at below path,

File Path = Magento 2 Root Directory
\vendor\magento\framework\View\Element\Template\File\Validator.php

Step [2] – Once open Validator.php

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    foreach ($directories as $directory) {
        if (0 === strpos($this->fileDriver->getRealPath($path), $directory)) {
            return true;
        }
    }
    return false;
}

[3] – Need to replace Validator.php code with following below code

protected function isPathInDirectories($path, $directories) {

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

if (!is_array($directories)) 

{ $directories = (array)$directories; } 

foreach ($directories as $directory) { 

if (0 === strpos($realPath, $directory)) 

{ return true; } 

} return false; 

}


Why Elon Musk bought Twitter @ $44 Billion Deal

Business Tycoon Elon Musk & CEO of electric-car company Tesla and aerospace company SpaceX agreed to acquire Twitter for $44 billion on 26th April, 2022

The Following below reason, why acquired Twitter by Elon Musk

Reason [1] – Due To Free Speech, he wants to implement free speech on the platform so it can fulfil its potential as the world’s ‘Digital Town Square’.

Reason [2] – To make the company private is likely to have substantial ramifications for a service used by more than 300 million people, including many world leaders.

Reason [3] – To desire as safeguard Twitter as a free speech system rather than censorship, “Free speech is essential to a functioning democracy”

Reason [4] – To remove Fake Profile, & keeping genuine user & verified profiles

Reason [5] – To modify / moderate Twitter’s policies content, arguing that so be a genuine forum for free speech.

Reason [6] – To protect Twitter users from harmful content & keeping genuine content

Origins of Twitter::

The origins of Twitter date back to early 2006, when NYU student Jack Dorsey shared a new online communication idea with some of his coworkers at Odeo, a podcasting company. Dorsey’s idea was a platform that allowed users to share short messages with groups of people, similar to sending text messages.

First Tweet::

Jack Dorsey sent the first message on Twitter on 21st March 2006, 9:50 PM. It read, “just setting up my twttr.”

Twitter Trends Increased By 2007::

Twitter was introduced to the public on July 15th, 2006, . The website started watching around 20,000 tweets per day in the first months, but this number grew to 60,000 in 2007

Twitter Tweet Limit Increased from 140 characters to 140 characters::

Twitter was originally designed as an Mobile SMS-based platform in early days where limit was 140 characters, Twitter decided to increase Twitter limit from 140-character limit to 280 characters limit On 2017

How To Install Yarn in Windows 10 / 11

The following below steps need to follow.

Step [1] –Yarn need to download from below URL.

 Download the Yarn .msi installer

Step [2] – Once Installer Package done, click on that one.

Step [3] – The following Installer steps display as per screenshots as

Installer Screenshot-1

Installer Screenshot-2

Installer Screenshot-3

Installer Screenshot-4

Step [4] – Finally Yarn has been installed , Got to your Command Prompt & type

yarn --version

How To Install Node.js in Windows 10 / 11

The Following below steps need to follow.

Step [1] – Download Node.js from below URL for Windows.

https://nodejs.org/en/download/

Step [2] – Once Download done, click on Installer & further steps as per below screenshots.

Installer Screenshot-1

Installer Screenshot-2

Installer Screenshot-3

Installer Screenshot-4

Installer Screenshot-5

Installer Screenshot-6, this sept will take some time, Please Be Patience

Step [3] – Finally Node.js has been installed , Got to your Command Prompt & type

node --version