Friday 4 October 2019

Cannot add a new addondomain in WHM panel

(XID a57bw8) Sorry, the domain is already pointed to an IP address that does not appear to use DNS servers associated with this server. in WHM panel

Visit this area in WHM panel:

1. WebHost Manager »Server Configuration »Tweak Settings, Domains tab:

2. Enable the following setting


Saturday 28 September 2019

How to create/write code in text/json file and get content of file in PHP | Codeigniter

Create file and directory
public function createfileanddir() {
    $directoryname = 'directoryname';
    $filename = 1;
    $directory = APPPATH . 'uploads/cache/'.$directoryname;
    if (!file_exists($directory)) {
        mkdir($directory, 0777, true);
    }
    $file = APPPATH . 'uploads/cache/'.$directoryname.'/'.$filename.'.json';
    if (file_exists($file)) {
        unlink($file);
    }
    if (!file_exists($file)) {
        $settings = [
            'settings'=>[],
            'socialSettingsArr'=>[],
            'pageSettings'=>[],
        ];
        $fh = fopen($file, 'w');
        fwrite($fh, json_encode($settings));
        fclose($fh);
    }
}
Get content from file and directory
public function getfiles() {
    $directoryname = 'directoryname';
    $directory = 'uploads/cache/'.$directoryname;
    $files = array_diff(scandir($directory), array('.', '..'));
    if(count($files) > 0){
        foreach ($files as $file):
            $file = $directory . '/'.$file;
            $storedata = file_get_contents($file);
            $storedata = json_decode($storedata, true);
            echo '<pre>';print_r($storedata);
        endforeach;
    }
}

Friday 27 September 2019

Magento 2 Missing Table when transfer server Error "inventory_stock_1"

Error
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'inventory_stock_1' doesn't exist, query was:........
Solution
1) Open your phpmyadmin
2) Remove your current "inventory_stock_1" if available
3) Run following query on sql
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;

3) Reindex your store data then check your store.

Tuesday 24 September 2019

How to create pagination in shopify rest api using php

Shopify new API next page issue | page_info => invalid value

Shopify API version 2019-07 you do indeed need to use cursor-based pagination.

First make a normal API call, include the header response.

Then in the header response API, you will see the "link" parameter with rel next or previous.

Extract the page_info and then make another call with page_info.
The first API call is something like this:

https://.....@abc.myshopify.com/admin/api/2019-10/products.json?limit=2&published_status=published
To get header response from API response :
function getheaderarray($apiresponse){
       
        $data = explode("\n",$apiresponse);
        $headers['status'] = $data[0];
        array_shift($data);
        foreach($data as $part){
            $middle = explode(":",$part,2);
            if ( !isset($middle[1]) ) { $middle[1] = null; }
            $headers[trim($middle[0])] = trim($middle[1]);
        }
       
        return $headers;
  }  
Then the second API call is something like this:
https://.....@abc.myshopify.com/admin/api/2019-10/products.json?limit=2&page_info=abcdsf21asdf3afdfdfd1safd51s3f1x32ref4asdj
When you make the second call, do not add any filers as the filters will be applied from the first call.
FYI: if your testing in a browser due to the way the link is in angle brackets, it will be hidden, so just view source code in your developer environment.

Friday 20 September 2019

How to change root password of mysql

sudo service mysql stop
sudo mkdir -p /var/run/mysqld

sudo chown mysql:mysql /var/run/mysqldsudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u rootmysql> FLUSH PRIVILEGES;
mysql> USE mysql;mysql> UPDATE user SET authentication_string=PASSWORD("<Your Password>") WHERE User='root';mysql> UPDATE user SET plugin="mysql_native_password" WHERE User='root';
mysql> exit
sudo pkill mysqldsudo service mysql start

Saturday 14 September 2019

Simple zoom effect with mouse hover with HTML, CSS and JS

Preview



HTML
<div class="gallery-placeholder">
    <div class="fotorama__stage__frame fotorama__active">
        <img class="fotorama__img" src="<?php echo 'https://kansagra/jaydip/jaydip.jpg'; ?>" >
    </div>
</div>
<div class="gallery-popup fixed-full-popup-model">
    <div class="gallery-zoom-img">
        <div class="gallery-main-img" style=""></div>
    </div>
</div>
CSS
<style>
.gallery-popup {
    cursor: url(../images/zoom-out.svg),pointer;
}
body .gallery-placeholder .fotorama__stage__frame.fotorama__active .fotorama__img {
    cursor: url(../images/zoom-in.svg),pointer;
}
.gallery-popup .gallery-zoom-img .gallery-main-img {
    width: 100%;
    height: 100vh;
    background-position: 0 0;
    background-repeat: no-repeat;
    background-size: cover;
}
.fixed-full-popup-model {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 21;
    background: #FFF;
    width: 100%;
    height: 100%;
    display: none;
}
</style>
JS
<script type="text/javascript">
$(document).ready(function(){
$('body .gallery-placeholder').on('click', '.fotorama__stage__frame.fotorama__active .fotorama__img',function(){
var $this = $(this);
var img = $this.attr('src');
$('.gallery-popup .gallery-zoom-img .gallery-main-img').css("background-image", "url(" + img + ")")
$(".gallery-popup").fadeIn();
$("body").css("overflow", "hidden");
});
$(".gallery-popup").on("mousemove",".gallery-main-img",function(e){
var pixelToMove=100;
var height=$(this).innerHeight();
var newValueY=(e.clientY / height)*pixelToMove;
$(this).css('background-position',0+' '+newValueY+'%');
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
    $(".gallery-popup").fadeOut();
    $("body").css("overflow-y", "inherit");
}
});
$(".gallery-popup .gallery-main-img").click(function(){
$(".gallery-popup").fadeOut();
$("body").css("overflow-y", "inherit");
$('.gallery-popup .gallery-zoom-img .gallery-main-img').css("background-image", "");
});
});
</script> 

After installed Magento 2, got Internal server error due to IfVersion < 2.4

Following .htaccess code is not working in Magento 2

<Files composer.json>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>

Ans.  Just enabled "mod_version" from your server