:::: MENU ::::

Magento Tutorial | Magento Blog | Learn Magento 2

Cookies Consent Popup

If error in indexing after upgrade then run below sql query in phpmyadmin


CREATE  SQL SECURITY INVOKER   VIEW `inventory_stock_1`   AS  SELECT  DISTINCT    legacy_stock_status.product_id,   legacy_stock_status.website_id,   legacy_stock_status.stock_id,    legacy_stock_status.qty quantity,   legacy_stock_status.stock_status is_salable,   product.sku    FROM cataloginventory_stock_status` `legacy_stock_status`  INNER JOIN `catalog_product_entity` product    ON legacy_stock_status.product_id = product.entity_id;


and run below commands

* Clear `var/generation`

* Clear `var/cache`

* Enable Magento modules: `php bin/magento module:enable --all`

* Compile DI `php bin/magento setup:di:compile`

I have installed Elasticsearch in my Linux. 


Follow below Steps.


Run the below command to Install Elasticsearch In locally. 


Download and install the public signing key :


`wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -`


Installing from the APT repositoryedit 


You may need to install the apt-transport-https package on Debian before proceeding :

`sudo apt-get install apt-transport-https`


Save the repository definition to /etc/apt/sources.list.d/elastic-7.x.list :

`echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list`


You can install the Elasticsearch Debian package with :

`sudo apt-get update && sudo apt-get install elasticsearch`


Elasticsearch is not started automatically after installation. How to start and stop Elasticsearch depends on whether your system uses SysV `init` or `systemd` (used by newer distributions).


`ps -p 1`

Running Elasticsearch with SysV `init` : Use the `update-rc.d` command to configure Elasticsearch to start automatically when the system boots up : 


`sudo update-rc.d elasticsearch defaults 95 10`


Elasticsearch can be started and stopped using the `service` command :


`sudo -i service elasticsearch start`

`sudo -i service elasticsearch stop`


Configure Apache and Elasticsearch : Set up a proxy (Set up a proxy for Apache 2.4)


Enable mod_proxy as follows :

`a2enmod proxy_http` or `sudo a2enmod proxy_http`


Use a text editor to open /etc/apache2/sites-available/000-default.conf


Add the following directive at the top of the file :

`Listen 8080`


Add the following at the bottom of the file :

    <VirtualHost *:8080>

        ProxyPass "/" "http://localhost:9200/"

        ProxyPassReverse "/" "http://localhost:9200/"

    </VirtualHost>


Restart Apache :

`service apache2 restart` or `sudo service apache2 restart`


Verify the proxy works by entering the following command :


For example, if your proxy uses port 8080:

`curl -i http://localhost:8080/_cluster/health`


If curl request success then messages display like below : 

    HTTP/1.1 200 OK

    Date: Sun, 23 Aug 2020 06:05:56 GMT

    Server: Apache/2.4.18 (Ubuntu)

    content-type: application/json; charset=UTF-8

    content-length: 389

        {"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":1,"active_shards":1,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":1,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":50.0}


Go to `Admin Panel -> Stores -> Settings -> Configuration -> Catalog -> Catalog Search`. Change the settings like below. 


`Search Engine : Search Engine7`

`Elasticsearch Server Hostname : localhost`

`Elasticsearch Server Port : 8080`

`Elasticsearch Index Prefix : magento2`

`Enable Elasticsearch HTTP Auth : No`

`Elasticsearch Server Timeout : 15`

Now save the configuration & run below cache clean command. 

`php bin/magento cache:clean`

Now click on `Test Connection` button.

After successful you will receive `Successful! Test again?` in `Test Connection` button. 

Ref : <a href="https://devdocs.magento.com/guides/v2.4/install-gde/prereq/es-config-apache.html">Dev Docs</a> & <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html">Elasticsearch</a>


Recently on one of our client’s stores. we ran into an issue with creating a Shopping Cart Price Rule promo. The goal was to create a rule where if there were 3 or more products with a certain SKU in the cart then apply a discount. However, when we went to create the rule – based on SKU – we realized that the conditions dropdown was no longer displaying the attributes as it had in the past. The dropdown looked something like this:

Please choose a condition to add…
Conditions Combination
Cart Item Attribute
– Price In cart
– Quantity in cart
– Row total in cart
Product Attribute
– Attribute Set
– Category

The fix that worked for us:
In the Magento Admin Panel go to Catalog > Attributes > Manage Attributes
Select any attribute that you’d like to be able to sort by in the conditions list. On the edit-a-attribute page, under “Frontend Properties” set “Use for Promo Rule Conditions” to “Yes”. Save the attribute.
Then go to System > Index Management and re‑index.

Now – when you go back to creating your Shopping Cart Price Rule, you will see your attribute in the conditions list.

Simple fix for an annoying issue.

I Found Solution for it and i hope its work for you. placeholder comes from : vendor/magento/module-catalog/Helper/Product.php i try to save my images directly in my theme on below path and it works.
app/design/frontend/Your/Theme/Magento_Catalog/web/images/product/placeholder
and put your images with below name in jpg format.
  • image.jpg
  • small_image.jpg
  • thumbnail.jpg
    Dont forget to do upvote if its work for you. cheers !!
Sometime we just need to use simple jQuery on checkout page but checkout element bind with knockout js so our jQuery not work smoothly so below is a way to call your jQuery after bind perticular element.

Use below code in your jquery and it will load after binding your element in page.

function waitForElement(query, callback){
    var poops = setInterval(function(){
        if(document.querySelector(query)){    
            clearInterval(poops);
            callback();
        }
    }, 100);
}

waitForElement(".class", function(){
    alert("element is loaded.. do stuff");
});
Put below code in anywhere in magento2 :- $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log');$logger = new \Zend\Log\Logger();$logger->addWriter($writer);$logger->info("Product Info ". $product->getSku() . "----- Id  ". $product->getId() );
Or you can try this : file_put_contents(BP . '/var/log/events.log', "$eventName\n", FILE_APPEND);