Saturday 30 December 2017

How to download and Extract Uncompress zip / gz file from URL in PHP


File zip / gz download from URL

ini_set('display_errors', 1);
$dbname = 'db_'.date('Ymdhis').".gz";
$url = 'http://www.domainname.com/backups/bkp30122017.gz';
file_put_contents($dbname, fopen($url, 'r'));

Extract / Uncompress GZ / ZIP file

try{
    //This input should be from somewhere else, hard-coded in this example
    $file_name = $dbname;
    // Raising this value may increase performance
    $buffer_size = 4096; // read 4kb at a time
    $out_file_name = str_replace('.gz', '.sql', $file_name);
    // Open our files (in binary mode)
    $file = gzopen($file_name, 'rb');
    $out_file = fopen($out_file_name, 'wb');
    // Keep repeating until the end of the input file
    while (!gzeof($file)) {
        // Read buffer-size bytes
        // Both fwrite and gzread and binary-safe
        fwrite($out_file, gzread($file, $buffer_size));
    }
    // Files are done, close files
    fclose($out_file);
    gzclose($file);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

Wednesday 27 December 2017

How to upload image / file in magento


<input type="file" name="image">

Select path of media directory

$path = Mage::getBaseDir() . DS . 'media' . DS . 'customerimages' . DS;
$imagename = $this->uploadImageFile($_FILES, $path);

Create functions

function uploadImageFile($filedata, $path){
   
    if(isset($filedata['image']) && $filedata['image']['error'] == 0){
        try{
           
            $uploader = new Varien_File_Uploader('image');
            $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
            $uploader->setAllowRenameFiles(true);
           
            if(!is_dir($path)){
                mkdir($path, 0755, true);
            }
            $ext = pathinfo($filedata['image']['name'], PATHINFO_EXTENSION);
            $uploader->save($path, date('Ymd') . "_" . date('his') . '.' . $ext);
            $uploadFile = $uploader->getUploadedFileName();
            if($uploadFile){
                return $uploadFile;
            } else {
                return 'File not uploaded!';
            }
        } catch (Exception $e) {
            return $e->getMessage();
        }
    } else {
        return 'Please select image file!';
    }
}

Tuesday 26 December 2017

How to get product Tire / Final / Group price custom in Magento

How to get product Tire / Final / Group price custom order in Magento


$productid = 4108;
$qty = 3;
$customergroup = 1;
$_productB = Mage::getModel('catalog/product')->load($productid);
$_productB->setCustomerGroupId($customergroup);
echo $_productB->getPriceModel()->getFinalPrice($qty, $_productB);exit;

Monday 25 December 2017

Export Big sql/mysql database using php file

Export Big sql/mysql database using php file

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '512M');
$dbinfo = array(
    "host" => 'localhost',
    "user" => 'root',
    "pass" => 'root',
    "dbname" => 'dbname'
);

// Database Config
$sqlhost = $dbinfo["host"];
$dbuser = $dbinfo["user"];
$dbpassword = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];
// filename
$file = date('Ymdhis');
echo shell_exec("mysqldump --add-drop-table -u $dbuser -p$dbpassword`cat /etc/psa/.psa.shadow` $dbname > $file.sql");
//shell_exec("mysql -u $dbuser --password='$dbpassword' --host='$sqlhost' $dbname < $file");
echo 'Finished!<br/>';

File Directly Open in NetBeans in Ubuntu / Linux using terminal


 File Directly Open in NetBeans in Ubuntu / Linux using terminal

1. Open terminal and login with sudo su
2. Edit file using nano in terminal (Use following command)
sudo nano /usr/share/applications/netbeans-8.1.desktop 
3. Change

Exec=/bin/sh "/usr/local/netbeans-8.1/bin/netbeans"
to
Exec=/bin/sh "/usr/local/netbeans-8.1/bin/netbeans" %U

Terminal=0
to
Terminal=false
4. Press CTRL+X , than Y and Enter
5. That't IT, Now you can see NetBeans in open with application

Ref by. Nirav Patel

Thursday 21 December 2017

How to extract/ unzip ZIP / GZIP file using PHP

How to extract ZIP / GZIP file using PHP


<?php
$zip = new ZipArchive;
$res = $zip->open('myproject.zip');
if ($res === TRUE) {
  $zip->extractTo('/var/www/html/directoryname/');
  $zip->close();
  echo 'woot!';
} else {
  echo 'doh!';
}
?>

Tuesday 12 December 2017

How to Enable SSL certificate in cloud.google.com

How to Enable SSL certificate in cloud.google.com


Open cloud.google.com
1. Goto your VM instance
2. Click on name of your instance
3. Edit instance
4. Checked "Firewalls Allow HTTPS traffic" and save


5. Goto Network services -> Load balancing -> Edit / add your Load balancer
6. Add / Edit "https protocol" on Frontend configuration and select / create new certificate




7. Again goto your VM instance list
8. Click on SSH



9. After open google cloud ssh window, write "sudo su" on ssh window
10. ssh-keygen
11. gcloud compute ssl-certificates list
12. gcloud compute ssl-certificates describe ssl2111(name of your ssl certificate)
13. nano /etc/apache2/sites-available/default-ssl.conf
Upload certificate files and update path here where you place your SSLCertificateFiles
<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        <Directory /var/www/html/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
    DocumentRoot /var/www/html

    ..........
    ..........
    ..........
    ..........
    #SSLCertificateFile     /etc/ssl/certs/ssl-cert-snakeoil.pem
    #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    SSLCertificateFile "/var/www/html/cert/cert.pem"
    SSLCertificateKeyFile "/var/www/html/cert/privkey.key"
    SSLCertificateChainFile "/var/www/html/cert/chain.crt"
    ..........
    ..........
    ..........
    ..........
</VirtualHost>
</IfModule>

14. sudo service apache2 restart
15. gcloud auth login
16. gcloud config set project projectname-010412(Your project id)
17. sudo a2ensite default-ssl
18. service apache2 reload
19. sudo a2enmod ssl
20. sudo service apache2 restart
21. gcloud compute firewall-rules create www-firewall     --target-tags https-tag --allow tcp:443
22. service apache2 reload 

That's It, Please check your SSL 

How to check commit log of the particular file on Git or Bitbucket using terminal

How to check commit log of the particular file on Git or Bitbucket 


sudo git log -- app/code/local/jaydip/kansagra/controllers/CountryController.php

Wednesday 8 November 2017

Create custom order in magento programatically

function createorderAction(){
       
        $order = Mage::getModel('sales/order')->load(124);
       
        $ba = $order->getBillingAddress();
        $sa = $order->getShippingAddress();
       
        $customer_id = $order->getCustomerId();
       
        $store_id = 1;
        /*------------------------------------------------------------------------
        Payment and Shipping Method
        ------------------------------------------------------------------------*/
        $payment_method = 'checkmo';
        //$payment_method = 'stripe_cc';
        $shipping_method = 'flatrate_flatrate';
        $customer = Mage::getModel('customer/customer')->load($customer_id);
       
        /*------------------------------------------------------------------------
        Create a Quote
        ------------------------------------------------------------------------*/
        $quote = Mage::getModel('sales/quote');
        $quote->setStoreId($store_id);
        $quote->assignCustomer($customer);
        $quote->setSendCconfirmation(1);
        /*------------------------------------------------------------------------
        Add products to Quote
        ------------------------------------------------------------------------*/
        $items = $order->getAllItems();
       
        $block = Mage::app()->getLayout()->createBlock('sales/order_item_renderer_default');
       
        $quote->setCouponCode('20OFF');
       
        foreach ($items as $item):
           
            $block->setItem($item);
           
            $_options = $block->getItemOptions();
           
            $addproduct = array('product'=>$item->getProductId(), 'qty'=>1);
            foreach ($_options as $_option):
                $addproduct['options'][$_option['option_id']] = $_option['option_value'];
            endforeach;
           
            $product = Mage::getModel('catalog/product')->load($addproduct['product']);
            $quote->addProduct($product,
                new Varien_Object(
                    $addproduct
                )
            );
            //$item->setDiscountAmount($price);
            //$item->setBaseDiscountAmount($price);
        endforeach;
       
        /*------------------------------------------------------------------------
        Assign Address, Shipping and Payment methods
        ------------------------------------------------------------------------*/
       
        $address_data = array(
            'customer_address_id' => $ba->getId(),
            'firstname' => $ba->getFirstname(),
            'lastname' => $ba->getLastname(),
            'street' => array(
                '0' => $ba->getStreet()
            ),
            'city' => $ba->getCity(),
            'postcode' => $ba->getPostcode(),
            'telephone' => $ba->getTelephone(),
            'country_id' => $ba->getCountryId(),
            'region_id' => $ba->getRegionId(),
        );
       
        $s_address_data = array(
            'customer_address_id' => $sa->getId(),
            'firstname' => $sa->getFirstname(),
            'lastname' => $sa->getLastname(),
            'street' => array(
                '0' => $sa->getStreet()
            ),
            'city' => $sa->getCity(),
            'postcode' => $sa->getPostcode(),
            'telephone' => $sa->getTelephone(),
            'country_id' => $sa->getCountryId(),
            'region_id' => $sa->getRegionId(),
        );
       
        $billingAddress = $quote->getBillingAddress()->addData($address_data);
        $shippingAddress = $quote->getShippingAddress()->addData($s_address_data);
        $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
            ->setShippingMethod($shipping_method)
            ->setPaymentMethod($payment_method);
       
        $quote->getPayment()->importData(array('method' => $payment_method));
       
        //$quote->setDiscountAmount($discountAmount);
       
        $quote->collectTotals()->save();
       
        $discountAmount = 85.33;
        $paymentplantotal = 512.00;
        $downpayment = 42.67;
        $pymtfrequency = 1;
        $leftpayments = 11;
        $nextpayments = 42.67;
       
        $quote->setDiscountdue($discountAmount);
        $quote->setPaymentplantotal($paymentplantotal);
        $quote->setDownpayment($downpayment);
        $quote->setPymtfrequency($pymtfrequency);
        $quote->setLeftpayments($leftpayments);
        $quote->setNextpayments($nextpayments);
       
        $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)
            ->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)
            ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
            ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount);
       
        $quote->collectTotals()->save();
        //$quote->setCouponCode("20OFF")->save();
               
        $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
        foreach ($quote->getAllAddresses() as $address) {
           
            if ($address->getAddressType() == $canAddItems) {
                $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount() - $discountAmount);
                $address->setGrandTotal((float) $address->getGrandTotal() - $discountAmount);
                $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount() - $discountAmount);
                $address->setBaseGrandTotal((float) $address->getBaseGrandTotal() - $discountAmount);
                /*************************/
                $address->setDiscountdue($discountAmount);
                $address->setPaymentplantotal($paymentplantotal);
                $address->setDownpayment($downpayment);
                $address->setPymtfrequency($pymtfrequency);
                $address->setLeftpayments($leftpayments);
                $address->setNextpayments($nextpayments);
                $address->save();
            }
        }
       
        foreach ($quote->getAllItems() as $item) {
            //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
            $rat = $item->getPriceInclTax() / $quote->getBaseSubtotal();
            $ratdisc = $discountAmount * $rat;
            $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty());
            $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save();
        }
       
        /*----------------------------------------------------------------------*/
        /*------------------------------------------------------------------------
        SECTION : CHECKOUT
        ------------------------------------------------------------------------*/
        $convertQuote = Mage::getModel('sales/convert_quote');
        if ($quote->getIsVirtual()) {
            $order = $convertQuote->addressToOrder($quote->getBillingAddress());
        } else {
            $order = $convertQuote->addressToOrder($quote->getShippingAddress());
        }
        // assign payment method
        $quotePayment = $quote->getPayment();
        $quotePayment->setMethod($quote->getPayment()->getMethod());
        $quote->setPayment($quotePayment);
        $orderPayment = $convertQuote->paymentToOrderPayment($quotePayment);
        $order->setBillingAddress($convertQuote->addressToOrderAddress($quote->getBillingAddress()));
        $order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
        if (!$quote->getIsVirtual()) {
            $order->setShippingAddress($convertQuote->addressToOrderAddress($quote->getShippingAddress()));
        }
        // set payment options
        $order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
        // order products
        $items = $quote->getAllItems();
        foreach ($items as $item) {
            //@var $item Mage_Sales_Model_Quote_Item
            $orderItem = $convertQuote->itemToOrderItem($item);
            if ($item->getParentItem()) {
                $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
            }
            $order->addItem($orderItem);
        }
       
       
        $order->setCanShipPartiallyItem(false);
        $order->sendNewOrderEmail();
        $order->place();
        $order->save();
        $quote->setIsActive(0);
        $quote->save();
        //pre($order->getData());exit;
        //pre($quote->getData());
    }

Saturday 28 October 2017

Get Address of customer from database Query in Magento PHP Mysql

SELECT
`entity_id` as `entity_id`,
`firstname`.`value` as `First_Name`,
`surname`.`value` as `Surname`,
`telephone`.`value` as `Telephone`,
`country`.`value` as `country`,
`region`.`value` as `region`,
`statecounty`.`value` as `statecounty`,
`city`.`value` as `city`,
`company`.`value` as `company`,
`street`.`value` as `street1`,
`customer_entity`.`created_at`,
`customer_entity`.`updated_at`
FROM
`customer_address_entity_varchar` as `country`
INNER JOIN
`customer_address_entity_varchar` as  `firstname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `surname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `telephone` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `region` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `statecounty` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `city` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as  `company` USING (`entity_id`)
INNER JOIN
`customer_address_entity_text` as  `street` USING (`entity_id`)
INNER JOIN
`customer_entity` USING (`entity_id`)
WHERE
`firstname`.`attribute_id` = 20  &&
`surname`.`attribute_id` = 22  &&
`country`.`attribute_id` = 27 &&
`region`.`attribute_id` = 28 &&
`statecounty`.`attribute_id` = 144 &&
`city`.`attribute_id` = 26 &&
`company`.`attribute_id` = 24 &&
`street`.`attribute_id` = 25 &&
`telephone`.`attribute_id` = 31

Tuesday 26 September 2017

Transfer Attribute value from one attribute to another attribute in magento

You can transfer Attribute value from one attribute to another attribute in magento


public function changeattrAction()
    {
        //echo 'tes';exit;
        $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
     
        $j = 0;
        //echo count($products->getData());exit;
        foreach ($products as $k=>$product):
            if($j >= 5000 && $j < 5500){
                //echo $j;
             
                if($product->getH1() != ''){
                    echo $j.'. '.$product->getId().' '.$product->getH1().'<br>';
                    $product->setH1copy($product->getH1());
                    $product->save();
                }
            }
            $j = $j+1;
         
        endforeach;
    }

Thursday 14 September 2017

Create Zip file of all php files from your server using PHP file

Create Zip file of all php files from your server using PHP file. If you have not cpanel of the server so you can use this php file and compress files as zip file.

Just you need put this file into root directory of the server (ex.public_html/createzip.php)

And run this file from browser eg. http://domain.com/createzip.php

Create one file name : createzip.php and put following code into the file. and run file from browser.

<?php
// Get real path for our folder
$realpath = getcwd();
$rootPath = realpath($realpath);
// Initialize archive object
$zip = new ZipArchive();
$filename = 'bk_'.date('YmdHis').'.zip';
$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
    // Skip directories (they would be added automatically)
    if (!$file->isDir())
    {
        // Get real and relative path for current file
        $filePath = $file->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);
        // Add current file to archive
        $zip->addFile($filePath, $relativePath);
    }
}
// Zip archive will be created only after closing object
$zip->close();

Saturday 9 September 2017

W: GPG error: https://repo.skype.com stable InRelease

Did you got error something like this, whenever you get update ubuntu "sudo apt-get update" in terminal?

W: GPG error: https://repo.skype.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 1F3045A5DF7587C3

ANS.

According to https://repo.skype.com/, run:

curl https://repo.skype.com/data/SKYPE-GPG-KEY | sudo apt-key add -

in a terminal

Friday 25 August 2017

Zip File Extract using PHP file

If you have not cpanel of the server so you can use this php file and extract uploaded zip file.

<?php
ini_set('display_errors', 1);
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->extractTo('./rr/');
    $zip->close();
    echo "It's extract";
} else {
    echo 'failed';
}
?>

Saturday 12 August 2017

SoftException in Application.cpp:668: is writable by group

500 Error: File is writable by group

On occasion you may get a 500 page error (a blue/green error) when trying to run a PHP file in your account. When checking the error log which you can do via the cPanel account log in you may see the following line:

[Sat Aug 12 00:57:37 2017] [error] [client 103.240.34.54] SoftException in Application.cpp:668: Directory "/home/username/public_html/index.php" is writeable by group

This is due to the server running SuPHP and the files having higher permissions than allowed, 
 
How to solve this issue
 
Fix this problem you need to make sure your files are chmod 644 for all PHP based files and 755 for directories in order for them to work with SuPHP. You can easily do this by connecting via FTP with Filezilla Not from Cpanel and right clicking on the problem folders and files and selecting file permissions. Also set  0755 permission on public_html directory.

Saturday 22 July 2017

How to get the latest record in each group using GROUP BY


In PHP MySQL

SELECT `main_table`.`rebate_amount`, `main_table`.`companyname`, (SELECT target FROM batecash WHERE id = MAX(main_table.id)) AS `maxtarget`, SUM(rebate_amount) AS `rebate_amount`, SUM(invoiceamount) AS `purchase_amount`, MAX(id) AS `max_id`, `main_table`.`rebatetarget`, YEAR(created_at) yr, QUARTER(created_at) qt FROM `batecash` AS `main_table` WHERE (customerid = '5') GROUP BY YEAR(created_at), QUARTER(created_at) ORDER BY `created_at` DESC

 In Magento

$rebatecount = Mage::getModel('rebatereward/batecash')->getCollection()
                    ->addFieldToSelect('rebate_amount')
                    ->addFieldToSelect('companyname')
                    ->addFieldToFilter('orderstatus', array('eq' => 'completed'))
                    ->addFieldToFilter('addressid', array('eq' => $address->getId()))
                    ->addFieldToFilter('customerid', array('eq' => $this->getCustomer()->getId()));

            $rebatecount->getSelect()->columns("(SELECT rebatetarget FROM batecash WHERE id = MAX(main_table.id)) as maxtarget");
            $rebatecount->getSelect()
                    ->columns('SUM(rebate_amount) as rebate_amount')
                    ->columns('SUM(invoiceamount) as purchase_amount')
                    ->columns('MAX(id) as max_id')
                    ->columns('rebatetarget')
                    ->columns('YEAR(created_at) yr, QUARTER(created_at) qt')
                    ->group('YEAR(created_at), QUARTER(created_at)')
                    ->order(array('created_at DESC'));

Wednesday 19 July 2017

Which table truncate for magento speed optimised

SET foreign_key_checks = 0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
SET foreign_key_checks = 1;

Friday 9 June 2017

Test email in order email notification in magento

Add following function into any frontend controller and check via URL

public function sendtestAction()
    {
        $order = Mage::getModel('sales/order');
        $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
        $order->loadByIncrementId($incrementId);
        echo $incrementId;
        try {
            echo $order->sendNewOrderEmail();
        } catch (Exception $ex) {
            echo "Email Not Sent...";
        }
        $customer = Mage::getSingleton('customer/session')->getCustomer();
        $email = $customer->getEmail(); //End Email Sending
        echo '<pre>Done';
        echo $email;exit;
    }

Friday 28 April 2017

Pagination on shopify collection page with linklist

<h1 class="desktop-6 desktop-push-3 tablet-3 mobile-3">
  {% if collection.handle == 'all' %}{{ 'collections.general.all_products' | t }}
  {% elsif collection.handle == 'e-juice' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'a-d' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'e-i' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'j-m' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'n-z' %}
      E JUICE BRANDS
  {% else %}
  {{ collection.title }}
  {% endif %}
</h1>



<div class="clear"></div>
{% if linklists[collection.handle].links.size > 0 %}

<div class="collsn_img_link">
    {% if collection.image %}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
{% endif %}
{% if linklists[collection.handle].links.size > 0 %}

<div class="desktop-12 tablet-6 mobile-3 collecsn-linklist ">
  {% comment %}
   <p class="chose-categry">Choose a sub category:-</p>
  {% endcomment %}
      {% assign collections = linklists[collection.handle].links %}
    {% paginate collections by 40 %}
     {% assign currentpage = paginate.current_page %}
      {% assign current_offset = paginate.current_offset %}
    {% assign offset_limit = paginate.current_offset | plus:40 %}
  <ul id="myList" >
  {% for collection_link in collections %}
    {% assign forindex = forloop.index %}
    {% if current_offset < forindex and offset_limit >= forindex %}
    <li class="desktop-3 tablet-3 mobile-3 {% cycle ' first', '', '', ' last' %}">
      {% assign collection = collection_link.object %}
      {% if collection_link.type == 'collection_link' %}
      <div class="collection-image">
        <a href="{{ collection.url }}" title="{{ collection_title }}">
          {% if collection.image %}
          {{ collection.image.src | collection_img_url: 'large' | img_tag: collection_title }}
          {% else %}
          {{ collection.products.first.featured_image | product_img_url: 'large' | img_tag: collection_title }}
          {% endif %}
          <h3>{{ collection_link.title }}</h3>
        </a>    
      </div>
      {% else %}
        <div class="collection-info-inner">     
          <h3>{{ collection_link.title | link_to: collection_link.url }}</h3>
        </div>
      {% endif %}
<!--           <div class="collection-info-inner"> -->
<!--             <a href="{{ collection.url }}" title="{{ collection_title }} collection"> -->
<!--               <h3>{{ link.title | link_to: link.url }}</h3> -->
<!--             </a> -->
<!--        </div> -->
    </li>
    {% endif %}
    {% endfor %}
  </ul>
{% include 'pagination' %}
{% endpaginate %}
  <div class="clear"></div>
<!--   <div id="loadMore">See more</div> -->
  </div>
{% else %}
{% paginate collection.products by 40 %}
<!-- Start Sidebar -->
{% if settings.collection_sidebar %}
{% include 'collection-sidebar' %}
{% endif %}
<!-- End Sidebar -->


<div class="{% if settings.collection_sidebar %}desktop-9 tablet-6{% else %}desktop-12 tablet-6{% endif %} mobile-3">

  <div id="collection-description" class="desktop-12 tablet-6 mobile-3">

<div class="collsn_img">
    {% if collection.image and collection.handle != "candy"%}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte" contenteditable="true" spellcheck="false">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
</div>
  {% if settings.collection_sidebar == false %}
  {% if settings.filters %}
  <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
    {% include 'filter' %}
  </div>
  {% endif %} 
  {% endif %}

 {% comment %} <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
  {% include 'dropdown-filter' %}
  </div>  {% endcomment %}
  <div id="product-loop">
    <div id="product_collection">
    {% for product in collection.products %}
    {% assign products-per-row = settings.products-per-row %}
   
    <div id="product-listing-{{ product.id }}" class="product_price product-index {% if products-per-row == "6" %}desktop-2{% elsif products-per-row == "4" %}desktop-3{% elsif products-per-row == "3" %}desktop-4{% elsif products-per-row == "5" %}desktop-fifth{% elsif products-per-row == "2" %}desktop-6{% endif %} tablet-half mobile-half" data-alpha="{{ product.title }}" data-price="{{ product.price | money_without_currency }}">          
      {% include 'product-listing' %}
    </div>
    {% endfor %}
    </div>
  </div>
</div>
{% include 'pagination' %}
{% endpaginate %}

{% endif %}


<script>

 $( document ).ready(function() {
 
    (function($){
      function fixButtonHeights() {
        var heights = new Array();

        // Loop to get all element heights
        $('.product-index').each(function() {
         
          // Need to let sizes be whatever they want so no overflow on resize
          $(this).css('min-height', '0');
          $(this).css('max-height', 'none');
          $(this).css('height', 'auto');
         
          // Then add size (no units) to array
          heights.push($(this).height());
        
//         alert(heights);
        });

        // Find max height of all elements
        var max = Math.max.apply( Math, heights );
//         alert(max);

        // Set all heights to max height
        $('.product-index').each(function() {
        
          $(this).css('height', max + 'px');
          // Note: IF box-sizing is border-box, would need to manually add border
               

        });
      }

      $(window).load(function() {
        // Fix heights on page load
        setTimeout(function() {
        fixButtonHeights();
        }, 3000);
        // Fix heights on window resize
        $(window).resize(function() {
          // Needs to be a timeout function so it doesn't fire every ms of resize
          setTimeout(function() {
            fixButtonHeights();
          }, 100);
        });
      });
    })(jQuery);
     
  });
 
</script>
<style>
 
</style>
<script>

</script>
<!-- <script>
  $(document).ready(function () {
    size_li = $("#myList li").size();
    x=40;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+40 <= size_li) ? x+40 : size_li;
      if(x == size_li || x >= size_li){
        $('#loadMore').hide();
      }
        $('#myList li:lt('+x+')').show();
    });
});
</script> -->

Wednesday 29 March 2017

How to install PHP, apache and mysql in ununtu 14.04

https://www.howtoforge.com/ubuntu-lamp-server-with-apache2-php5-mysql-on-14.04-lts

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-12-04

Enable .htaccess

sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/sites-available/000-default.conf
<Directory "/var/www/html">
AllowOverride All
</Directory>

sudo service apache2 restart

Monday 23 January 2017

How to import Big SQL file usign PHP with shell command into hosting server

<?php

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '512M');

$dbinfo = array(
    "host" => 'localhost',
    "user" => 'magentom_jaydip',
    "pass" => 'rmO22RQ%UbW0',
    "dbname" => 'magentom_jaydip'
);


// Database Config
$sqlhost = $dbinfo["host"];
$dbuser = $dbinfo["user"];
$dbpassword = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];

// filename
$file = "mg_jaydip.sql";

shell_exec("mysql -u $dbuser --password='$dbpassword' --host='$sqlhost' $dbname < $file");

echo 'Finished!<br/>';
?>