Tuesday, 17 December 2019

how to connect ssh by pem file aws server

1. Requirement : .ppk or .pem key file
2. If you have .ppk file. It is required to change it to .pem file as it is the key format supported by Linux.
You need putty tools for generating .pem file from .ppk.
Install putty tools : sudo apt-get install putty-tools
Go to the directory of the .ppk file and run the following command : puttygen [filename].ppk -O private-openssh -o [filename].pem
3. Now you have the .pem file. It is needed to be added to the linux known hosts.
Run the following command : ssh-add [filename].pem
4. Now connect to AWS using linux in built 'Connect to Server' -> Type(SSH). You don't need to add password.

Friday, 6 December 2019

How to show address field in registration form in magento 2?

Hi first find magento root folder then vendor\magento\module-customer\view\frontend\layout customer_account_create.xml.
Then copy the file and related theme folder. For example path /app/design/frontend/vendor name /Theme Name/Magento_Customer/layout/customer_account_create.xml
then go to line no 13 check this code and put billow section on line no


 <referenceContainer name="content">
            <block class="Magento\Customer\Block\Form\Register" name="customer_form_register" template="form/register.phtml">
                <container name="form.additional.info" as="form_additional_info"/>
                <container name="customer.form.register.fields.before" as="form_fields_before" label="Form Fields Before" htmlTag="div" htmlClass="customer-form-before"/>
                <action method="setShowAddressFields">
                    <argument name="show.address.fields" xsi:type="boolean">true</argument>
                </action>
            </block>
            <block class="Magento\Cookie\Block\RequireCookie" name="require-cookie" template="Magento_Cookie::require_cookie.phtml">
                <arguments>
                    <argument name="triggers" xsi:type="array">
                        <item name="registerSubmitButton" xsi:type="string">.action.submit</item>
                    </argument>
                </arguments>
            </block>
        </referenceContainer>

Monday, 2 December 2019

Function mcrypt_module_open() is deprecated in Magento 2

Function mcrypt_module_open() is deprecated from PHP version 7.1. If you are using PHP 7.1 or higher for your Magento 2 website then you might face this error.
NOTE: This error is already solved by Magento in 2.2 and higher version.

Solution: Add @ sign before all below functions.

Below is one example.
$this->_handle = mcrypt_module_open($cipher, '', $mode, '');
Becomes
$this->_handle = @mcrypt_module_open($cipher, '', $mode, '');

Sunday, 24 November 2019

How to Call CMS Static Block in Phtml File in magento 2

Display CMS Static Block In Phtml File:
<?php
    echo $block->getLayout()
               ->createBlock('Magento\Cms\Block\Block')
               ->setBlockId('block_identifier')
               ->toHtml();
?>

Tuesday, 19 November 2019

Magento2 cannot load some transaction emails

error : main.CRITICAL: Zend_Json_Exception: Decoding failed: Syntax error in /home/forge/domain.com/vendor/magento/zendframework1/library/Zend/Json.php:97

This is a bug in Magento 2 and here is the solution:
This will fixed the invalid json objects in the order email templates.

See this on vendor/magento/module-sales/view/frontend/email/order_new.html file.

<!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order.getEmailCustomerNote()":"Email Order Note", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order area=\"frontend\"":"Order Items Grid", "var payment_html|raw":"Payment Details", "var formattedShippingAddress|raw":"Shipping Address", "var order.getShippingDescription()":"Shipping Description" "var shipping_msg":"Shipping message" } @-->

Take a look at this line:

"var order.getShippingDescription()":"Shipping Description"

It needs comma (,) at the end of this line to make it work. So it goes with the other files or template files.

So it should be like this:

<!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order.getEmailCustomerNote()":"Email Order Note", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order area=\"frontend\"":"Order Items Grid", "var payment_html|raw":"Payment Details", "var formattedShippingAddress|raw":"Shipping Address", "var order.getShippingDescription()":"Shipping Description", "var shipping_msg":"Shipping message" } @-->

Monday, 18 November 2019

Discount not applied to Grand Total in magento 1.9

We fixed this by adding the following into /app/code/core/Mage/Sales/etc/config.xml sales/quote section.

<discount>
   <class>sales/order_invoice_total_discount</class>
    <after>subtotal</after>
</discount>

This is a terrible solution, obviously, and I have no idea why it is needed. We will have to research it further to come up with a better solution than editing a core file!

Tuesday, 12 November 2019

Creating profile image module in magento 2



  1. Create folders under magento root
<magento root>/code/<vendor>/<module>/

  1. Create a file ‘registration.php’ and put the below contents in it
\Magento\Framework\Component\ComponentRegistrar::register(\Magento\Framework\Component\ComponentRegistrar::MODULE,'<vendor>_<module>',__DIR__);

  1. Create folder ‘etc’ and create file ‘module.xml’ in it,, and put the below content in it.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="<vendor>_<module>" setup_version="1.0.0">
</module>
</config>

  1. Create a route for the controllers which are needed to be made. Create e folder ‘frontend’ in etc folder and create file ‘routes.xml’ in it, and enter the following details in it.
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="<route_path>" id="<route_path>">
<module name="<vendor>_<module>"/>
</route>
</router>
</config>

  1. Create folder ‘Controller’ and create two folder in it.
‘Delete’ and ‘Index’. Create Index.php in both of it.

  1. In Delete -> Index.php , paste the following code

namespace <vendor>\<module>\Controller\Delete;

use Magento\Framework\App\Filesystem\DirectoryList;

class Index extends \Magento\Framework\App\Action\Action
{
protected $_filesystem;
protected $image;
protected $_file;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\<vendor>\<module>\Block\Imageprofile $image,
\Magento\Framework\Filesystem\Driver\File $file,
\Magento\Framework\Filesystem $fileSystem
) {
parent::__construct($context);
$this->image = $image;
$this->_file = $file;
$this->_filesystem = $fileSystem;

}

public function execute(){

$fileName = 'IMG_'.$this->image->currentUser()->getId();
$mediaRootDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('images/'.$this->image->currentUser()->getId().'/');
if ($this->_file->isExists($mediaRootDir.$fileName)) {
$this->_file->deleteFile($mediaRootDir.$fileName);
}
$this->_redirect('customer/account/');
}
}

  1. In Index -> Index.php , paste the following code

namespace <vendor>\<module>\Controller\Index;

use Magento\Framework\App\Filesystem\DirectoryList;


class Index extends \Magento\Framework\App\Action\Action
{
protected $_filesystem;
protected $image;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Filesystem $fileSystem,
\<vendor>\<module>\Block\Imageprofile $image
) {
parent::__construct($context);
$this->_filesystem = $fileSystem;
$this->image = $image;
}
public function execute()
{
$result = array();
if ($_FILES['profile_image']['name']) {
try {
// init uploader model.
$uploader = $this->_objectManager->create(
'Magento\MediaStorage\Model\File\Uploader',
['fileId' => 'profile_image']
);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'png']);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
// get media directory
$mediaDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
// save the image to media directory
$result = $uploader->save($mediaDirectory->getAbsolutePath('images/'.$this->image->currentUser()->getId().'/'),'IMG_'.$this->image->currentUser()->getId());
} catch (Exception $e) {
\Zend_Debug::dump($e->getMessage());
}
}
$this->_redirect('customer/account/');
//echo "Hello";
}
}


  1. Finally create a folder named ‘Block’ and create a file ‘Imageprofile.php’ in it. Paste the following code in it.

namespace <vendor>\<module>\Block;

use Magento\Framework\App\Filesystem\DirectoryList;

class Imageprofile extends \Magento\Framework\View\Element\Template
{
protected $customerSession;
protected $_file;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\Filesystem\Driver\File $file,
array $data = []
)
{
parent::__construct($context,$data);
$this->customerSession = $customerSession;
$this->_file = $file;
}
public function currentUser()
{
return $this->customerSession->getCustomer();//->getId();
}

public function getMediaUrl()
{
$mediaUrl = $this->_storeManager
->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
return $mediaUrl;
}

public function checkExist()
{
$filename = 'IMG_'.$this->currentUser()->getId();
$filepath = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('images/'.$this->currentUser()->getId().'/');
if ($this->_file->isExists($filepath.$filename)) {
return 1;
}else{
return 0;
}
//return $filepath.$filename;
}

}