Thursday 14 June 2018

Forloop query not workin in Magento 2 | Get same Ordered Qty of all products in Magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$soldModel = $objectManager->get('Magento\Reports\Model\ResourceModel\Product\Sold\Collection');
$collections = $productCollection->addAttributeToSelect('*')->setOrder('entity_id', 'desc')->load();
$productdata = array();
foreach ($collections as $product){
         
            $soldproduct = clone $soldModel;
            $soldproduct = $soldproduct->addOrderedQty()->addAttributeToFilter('product_id', $product->getId())->setOrder('ordered_qty', 'desc')->getFirstItem();
            $sold = (int)$soldproduct->getOrderedQty();
         
            $product->setSold($sold);
            $productdata['products'][] = $product->getData();
}
echo '<pre>';print_r($productdata);

Friday 8 June 2018

Add Template ‘Empty Document’ Options in Right Click Context Menu in Ubuntu 18.04 | 17.10

New versions of Ubuntu 17.10 | 18.04 etc don’t give the option to create a new text document in right-click context menu anymore. Here is how to create new Empty Document like below image



I was trying to create a new text file in Ubuntu 18.04. I right clicked of the mouse but I didn’t see the option to create a new document. This option in the right-click context menu allowed creating an empty text file.


Step 1
Create " Empty Document " into /home/jaydip/Templates directory
Step 2
Open terminal and put following command
touch ~/Templates/Empty\ Document

Thursday 7 June 2018

How to reset MySQL / phpmyadmin root password on Ubuntu 18.04 Linux

1. The simplest approach to reset MySQL database root password is to execute mysql_secure_installation program and when prompted entering your new root MySQL password:
sudo mysql_secure_installation

New password:
Re-enter new password:
2. Let's stop the currently running MySQL database:
sudo service mysql stop
3. create a /var/run/mysqld directory to be used by MySQL process to store and access socket file:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld 
4. Start manually MySQL with the following linux commands :
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
5. Confirm that the process is running as expected: 
jobs
6. Access MySQL database without password 
mysql -u root
7. First flush privileges MySQL session
mysql> FLUSH PRIVILEGES;
8. The following commands will reset MySQL root password to "root" 
mysql> USE mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("root") WHERE User='root';
mysql> UPDATE user SET plugin="mysql_native_password" WHERE User='root';
9. Exit MySQL session: 
mysql> exit
10. Terminate current mysqld process 
sudo pkill mysqld
11. Start MYSQL database:
sudo service mysql start
12. If all went well you should now be able to login to your MySQL database with a root password: 
mysql -u root --password=root
mysql> exit

Wednesday 6 June 2018

How to Switch / Change / Downgrade from PHP 7.2 to 7.1 on Ubuntu 16.04 / 18.04 , Apache | PHP

Follow following steps

1. sudo add-apt-repository ppa:ondrej/php
2. sudo apt-get update
3. sudo apt-get install php7.1
4. sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
5. sudo a2dismod php7.2
6. sudo a2enmod php7.1
7. systemctl restart apache2
8. sudo rm /usr/bin/php
9. sudo ln -s /usr/bin/php7.1 /usr/bin/php

Tuesday 5 June 2018

shell_exec("mysql -u $dbuser --password='$dbpassword' --host='$sqlhost' $dbname < $file") not working in PHP

I try to execute query from PHP / CMD / Terminal


mysql -u admin --password='jaydip' --host='localhost' 'mg_kansagra' < '/var/www/html/magento/dump/db.sql'


Its show me following error

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 3167 (HY000) at line 17: The 'INFORMATION_SCHEMA.SESSION_VARIABLES' feature is disabled; see the documentation for 'show_compatibility_56'

ANSWER

Run the following query in your MySQL database:
set @@global.show_compatibility_56=ON;

Tuesday 29 May 2018

How to force redirect HTTP to HTTPS in AWS or any other server using .htaccess

1st Method
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

2nd Method
<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{HTTPS} !on
     RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Thursday 3 May 2018

How to get the final sql / mysql query from the grid includes filters and pagination in Magento


Open Following file
Open MagentoRoot/lib/Varien/Db/Adapter/Pdo/Mysql.php
Update false to true
protected $_debug = true
protected $_logAllQueries  = true