:::: MENU ::::

Magento 2 get customer address

Today we discuss how in Magento 2 get customer address. Which include the default shipping address and default billing address also the all customer address list too. There are two types of addresses related to customer shipping and billing. you can add the unlimited address as a customer. let start with our example.

Customer Default Billing Address

Get the customer defaut billing address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        $billingAddressId = $customerObject->getDefaultBilling();
        return $billingAddress = $this->addressFactory->create()->load($billingAddressId);
       
    }
}

Customer Default Shipping Address

Get the customer defaut billing address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        $shippingAddressId = $customerObject->getDefaultShipping();
        return $shippingAddress = $this->addressFactory->create()->load($shippingAddressId);
       
    }
}

Customer All Address

Get the customer all address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        return $customerObject->getAddresses();
       
    }
}
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 17, 2020


Magento 2 current order

In this tutorial, we talk about how to get Magento 2 current order. Which includes order information current order id, Increment Id and other order-related data too like shipping information, billing information, and customer information. Now we start with our example.

You have to inject the checkout model session to get the latest order information.

protected $_checkoutSession;


public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,

) {

        $this->_checkoutSession = $checkoutSession;


    }

Now with $_checkoutSession obejct you can get order following information.

 $order = $this->_checkoutSession->getLastRealOrder();
 $orderId=$order->getEntityId();  // order id
 $order->getIncrementId();  // order increment id
 $order->getShippingMethod(); // shippingm ehtod
 $order->getPayment();   // payment method
 $order->getCustomerEmail(); // customer email
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 4, 2020


Magento 2 order PayPal information

Today we talk about how in Magento 2 order PayPal information. In this tutorial, we focus on how to get order PayPal information which includes the PayPal express token and PayPal correlation id. So let start with our example.

First, we get payment additional information.

[cc lang="php" tab_size="2" lines="40"]
$paymentAdditionalInfo = $order->getPayment()->getAdditionalInformation();

With the heplp of addiotnal information obejct we get paypal expreess token.

// get PayPal express checkout token
$token = $paymentAdditionalInfo['paypal_express_checkout_token'];

With the heplp of addiotnal information obejct we get paypal correlation id.

// get PayPal correlation ID
$correlationId = $paymentAdditionalInfo['paypal_correlation_id'];
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 4, 2020


Magento 2 delete file or image

Today we discuss how to delete a file or image in Magento 2. In this tutorial, we focus on Magento 2 ways to delete the file or image. As a PHP developer, you already about the function unlink(filepathhere) will delete the file for you. So let start with our example.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;

class Delete extends Action
{

    protected $fileSystem;
    protected $file;

    public function __construct(
        Filesystem $fileSystem,
        File $file
    )
    {
        $this->fileSystem = $fileSystem;
        $this->file = $file;
    }

    public function delete()
    {
        $fileName= "helloworld.jpg";
        $mediaRootDir = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
        if ($this->file->isExists($mediaRootDir . $fileName)) {
            $this->file->deleteFile($mediaRootDir . $fileName);
        }
       
    }
}

Delete FIle with ObjectManager.

$fileName= "helloworld.jpg";
$file = $this->_objectManager->get('Magento\Framework\Filesystem\Driver\File');
$mediaDirectory = $this->_objectManager->get('Magento\Framework\Filesystem')->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$mediaRootDir = $mediaDirectory->getAbsolutePath();

if ($file->isExists($mediaRootDir . $fileName))  {

    $file->deleteFile($mediaRootDir . $fileName);
}
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 17, 2020


PrestaShop get current user information

Today we talk about PrestaShop get current user information. In this tutorial, we focus on how to get customer information. User email, User name, User id, and other users related information.
You can get the context variable by following.

in the Controller file.

 $contextObject = $this->context;

Other files

 $contextObject = Context::getContext();

You can get the following user information using the $contextObject.

$contextObject->customer->id;
$contextObject->customer->firstname
$contextObject->customer->lastname
$contextObject->customer->email
Author: Qaisar Satti
Category: Prestashop
Last Modified: November 28, 2019


PrestaShop database configuration

Today we talk about how in PrestaShop database configuration work. Sometimes you need to edit database connection manually for moving one server to another or local server to live server. I recently find difficulty to find the database configuration. SO we focus on where the PrestaShop database connection file exists or edit from the back office. There are two ways to way to change the database configuration.

Admin Panel

Login to the back office.You can go to Preferences > Database to change the database settings

Database Configuration file in 1.6

Location of file in following directory.

config/settings.inc.php

Database Configuration in file 1.7

Location of file in following directory.

app/config/parameters.php
Author: Qaisar Satti
Category: Prestashop
Last Modified: November 28, 2019


Magento 2 call a phtml file in static block

Today we talk about how to in Magento 2 call a phtml file in static block. Calling a phtml file is no different as compared to Magento 1 calling. But if you are calling it in cms block you have to use a class instead of type.

Calling a phtml file on the static block. Just add class and template path.

My current file location for the module is.

app/code/QaisarSatti/HelloWorld/Block/HelloWorld/view/frontend/templates/helloworld.phtml

{{block class="QaisarSatti\HelloWorld\Block\HelloWorld" template="QaisarSatti_HelloWorld::helloworld.phtml"}}

My current phtml location for the theme is.

app/design/frontend/QaisarSatti/helloworld/Magneto_Theme/templates/helloworld.phtml

{{block class="QaisarSatti\HelloWorld\Block\HelloWorld" template="helloworld.phtml"}}

If you want to add phtml with general magento class. Use following code.

{{block class="Magento\Framework\View\Element\Template" template="helloworld.phtml"}}
Author: Qaisar Satti
Category: Magento 2
Last Modified: November 28, 2019


Pages:1234567...25