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();